Labelling slices in sub-stack

This might be VERY basic, but I cannot find a way to label a sub-stack with the original z (slice number or µm).

I am selecting the slices to sub-stack from a dialog as, for example, 1,4-6,8. But I cannot retrieve this information to then label the slices with z=1, z=4, etc…

Something that could help me is if there was a way of labelling a hyper stack (which the slice labeller cannot do), so I could label before generating the sub-stack.

Once again, I apologise if this is too basic and thanks for your help!

Hi @fpelisch,

I am not sure which plugin you use to create the substack. Below is an image macro that set a label to every slice, create a substack of that image and then print the label of that substack. If that fits your need you can basically copy that in imageJ script editor and remove the 2 first lines so it can apply to the image that is open.

// load sample data
run("T1 Head (2.4M, 16-bits)");

// add a label to every slice of the image
for( slice=1; slice<=nSlices; slice++)
{
	setSlice(slice);
	setMetadata("Label", ""+slice);
}

// create a substack of the image
run("Make Substack...", "  slices=50-100");


// read the label of the new image
for( slice=1; slice<=nSlices; slice++)
{
	setSlice(slice);
	label = getMetadata("Label");
	IJ.log(label);
}

Hi Benoit,

thanks a lot for your reply!

I am generating a sub-stack as follows (part of a dialog):

az = Dialog.getString();
run(“Make Substack…”, “channels=1-4 slices=[” + az + “]”);

I start with a hyper stack, 4 channels and several slices and the macro ends up generating a montage of the selected channels and slices. While I managed to label the channels no problem, I cannot properly label the slice number in each slice. What I want to do later on is write with text the slice number corresponding to its original location in the stack (i.e. az). I tried

for(i=1; i<=nSlices; i++){
setSlice(i);
setColor(255,255,255);
setFont(“Arial”, 11, " antialiased");
setJustification(“right”);
drawString(az, 3, 3);
}

I hope this is clear, but let me know if I should present the problem in a different way, as I am not used to doing it.

Cheers

Fede

Hi Federico,

Thanks for the feedback. I modified your sample code a bit.
mainly I inverted labelling order and substack and changed setSlice(i) for Stack.setPosition(ch,z,t). Also I added the value z in the drawString function

az = getString("slice range","3-4");

getDimensions(width, height, channels, zMax, frames)
ch=1;
t=1; 
for(z=1; z<=zMax; z++){
	Stack.setPosition(ch,z,t);
	setColor(255,255,255);
	setFont("Arial", 18, " antialiased");
	setJustification("left");
	drawString("z0="+z, 10, 20);
}

run("Make Substack...", "channels=1-4 slices=[" + az + "]");

Hi Benoit,

Thanks a lot again for taking the time to review this.

I could see how your changes actually work. The thing is that because of the way I am setting my macro (which includes: rotate, crop, make sub-stack), I would need to retrieve the slice information (relating to the original stack) at a later point and drawing the Z label in the sub-stack. Is there a way to call that string (az) and label slides consecutively with the string components that might not be, for example, 2-5, but rather 2,4-8?

This is the bit I am struggling with.

getDimensions(width, height, channels, zMax, frames)
ch=1;
t=1;
for(z=1; z<=zMax; z++){
Stack.setPosition(ch,z,t);
setColor(255,255,255);
setFont(“Arial”, 18, " antialiased");
setJustification(“left”);
drawString(“z0=”+z, 10, 20);
}

run(“Make Substack…”, “channels=1-4 slices=[” + az + “]”);
[/quote]