Skip to content, Skip to search


ImageJ2 Python Scripts

202 bytes removed, 13:42, 16 November 2016
Crop an image along one single axis
=== Crop an image along one single axis ===
<source lang='python'>
from net.imglib2.util import Intervals
from .ij_utils import get_axis
def get_axis(axis_type):
return {
'X': Axes.X,
'Y': Axes.Y,
'Z': Axes.Z,
'TIME': Axes.TIME,
}.get(axis_type, Axes.Z)
 def crop_along_one_axiscrop(ij, data, intervals, axis_type): """Crop along a single one or more axis using Views.
intervals : List with two values Dict specifying the start and the end of the interval. axis_type : Along which axis to cropand with what intervals. Can be Example : intervals = {'X' : ["X"0, 50], " 'Y", "Z", "TIME"' : [0, "CHANNEL"50]}
axis = get_axis(axis_type) interval_start intervals_start = [data.min(d) if d != data.dimensionIndex(axis) else intervals[0] for d in range(0, data.numDimensions())] interval_end intervals_end = [data.max(d) if d != data.dimensionIndex(axis) else intervals[1] for d in range(0, data.numDimensions())]
for axis_type, interval in intervals.items(): index = interval_start + interval_enddata.dimensionIndex(get_axis(axis_type)) intervals_start[index] = interval [0] intervals_end[index] = Intervals.createMinMax(*interval)[1]
output intervals = ijIntervals.opcreateMinMax().run("transform.crop", data, interval, True*intervals_start + intervals_end)
output = ij.op().run("transform.crop", data, intervals, True)
return output