How to use nSlices inside of an argument to a build-in commands

I hope I used the correct section of “Development” for this post.

Short Question: How do I do 1-nSlices inside of run(“Make Substack…”,“slices=HELPHERE”)

Longer Question with my end goal.
I have a long stack the comes with a time stamp at the top. This is a shadow graph that shows very small changes in pressure, so I end up doing some stuff to the stack to help myself better see these waves. I end up having to raise the contrast and do my own back ground removal, BUT it messes up the time stamp at the top. (I also end up cropping my selection as I am normally working with around 5,000 slices)

I want to make a macro that uses a box selection at the top to cut out the time stamp for each slice, and after I edit the rest of the pixels in each slice, put it back together using the stacks->tools->combine…

I am very much so learning this software, and this is my first post. Any help is very much appreciated! Thanks:smiley:

Side Note: I try not to change the size of the sub-stacks when I combine, the timestamp re aligns with each respective frame

Hi @vnechev,

in the following ImageJ1 macro you will find various commands that will help you obtaining your goal. The debug statements will get you in the debugger after chosing Debug>Ddebug Macro, Debug>Run to do the single stepping through the relevant code to see what happens. In short, I create a stack with a stamp, select the stamp area, duplicate that to a separate file (nSlices is automatically chosen), then clear the original stack, then paste back from the stamp stack.

close("*");
newImage("test", "8-bit black", 200, 100, 10);
testID=getImageID();
for(i=0;i<nSlices;i++){
	setSlice(i+1);
	drawString("Image "+IJ.pad(i+1,2),10,20);
}
makeRectangle(6, 5, 63, 16);
run("Duplicate...", "title=text duplicate");
textID=getImageID();
setBackgroundColor(40, 40, 40);
debug;
selectImage(testID);
run("Select All");
run("Clear", "stack");
debug;
for(i=0;i<nSlices;i++){
	selectImage(textID);
	setSlice(i+1);
	run("Select All");
	run("Copy");
	selectImage(testID);
	makeRectangle(6, 5, 63, 16);
	run("Paste");
	
}

@eljonco

Wow this was extremely helpful. Not only did I learn how to accomplish my goal, but I know how to better test my macros. I really appreciate the code you provided. This is great!

Thanks so much!