Stack Z project minimum keeping slices

Hello !

So i’m trying to write a macro to transform images, i got a stack of 360 or less images and as they are images aligned some of them contain black pixel.
What i would like to do is that everytime a black pixel is spotted on a frame and on x/y position it becomes black on all others frames, so at the end i will have a “Z project minimum” but with all the slices i started with, not only one.
I’ve written a macro and for now it’s working but only with the last frame i put (all the black pixel of this last frames are put on the others stacks).

The macro start with the first frame and spot the value of each pixel for different value of x and y, when a value equal to 0 is spotten, it’s supposed to be put at the same position (x,y) on each other frames.

In this link you will find some data : https://fex.insa-lyon.fr/get?k=hSZ0buXQoGlh0mggm5r

Stack.getDimensions(width, height, channels, slices, frames);
print("slices : ", slices);
print("frames : ", frames);
setBatchMode(true);
for (i=1; i<slices+1; i++){
	setSlice(i);
	print("Slice number ", i);
	for (x=0; x<width; x++){
		for (y=0; y<height; y++){
			v=getPixel(x,y);
			if (v==0) {
				for (j=1; j<slices+1; j++){
					z=j-1;
					setZCoordinate(z);
					setPixel(x,y,0); // Set a 0 value on each frame for this black pixel on x;y
					}
				}
			}
		}
	}

Maybe an easier way to achieve this would be to:

  • Create a minimum projection of your stack
  • Convert this projection to a binary image using a threshold of 1, thereby making all non-zero pixels white and all zero pixels black
  • Combine the original stack and the binary image using the Image Calculator or the Image Expression Parser, e.g. by multiplying them.
1 Like