Change image axis type

imagej

#1

Hey all,

what is the simplest way to change the axis information of a dataset opened in ImageJ ? I want the Z-Axis to be TIME.

Thanks,
Deborah


#2

You can use Dataset.axis(dim).setType(axisType) as illustrated in this Groovy script:

#@ Dataset input

import net.imagej.axis.Axes

input.numDimensions().times { dim ->
	axisType = input.axis(dim).type()
	println axisType
	if (axisType == Axes.Z) {
		input.axis(dim).setType(Axes.TIME)
	}
}

input.numDimensions().times { dim ->
	axisType = input.axis(dim).type()
	println axisType
}

(If you just want to change the way the dataset is displayed in the Legacy UI, there might be synchronization issues however, so you might have to create a copy of the dataset before displaying it again. Or stick to Re-order Hyperstack… :slight_smile: )


#3

Thanks! The script did the trick :slight_smile:


#4

I think we need a nice intuitive GUI to change labels of an axis which works for both ImagePlus and Dataset.

I Image > Hyperstack > Reorder Hyperstack... but this converts an Dataset into an ImagePlus before changing the axis.

@imagejan are you aware of any other GUI way to change the axis?


#5

I don’t know of any built-in way of doing this on ImageJ2 objects (i.e. Dataset or ImgPlus). We can possibly create a DynamicCommand along the following lines:

#@script (name="Swap axis labels")
#@ Dataset input
#@ String (choices={"X", "Y", "Channel", "Z", "Time"}, label="Swap") axis1
#@ String (choices={"X", "Y", "Channel", "Z", "Time"}, label="with") axis2
#@ UIService ui

import net.imagej.axis.Axes

foundDim = -1

input.numDimensions().times { dim ->
	axisType = input.axis(dim).type()
	if (axisType == Axes.get(axis1)) {
		foundDim = dim
		input.axis(dim).setType(Axes.get(axis2))
		println "Swapping $axis1 to $axis2"
	}
}

input.numDimensions().times { dim ->
	axisType = input.axis(dim).type()
	if (axisType == Axes.get(axis2) && dim != foundDim) {
		input.axis(dim).setType(Axes.get(axis1))
		println "Swapping $axis2 to $axis1"
	}
}

ui.show(input)

where we’d have to use an initialize/callback method to restrict the number of choices for the two inputs.