How to create selection which at least partially overlaps with another selection

Hello! I have image with two channels. In both channels I thresholded and selected (edit/selection/create selection) pixels with specific range values. Now I need to create another selection which will contain only structures selected in channel one with the condition that these structures will overlap (partially or entirely) with structures selected in second channel. I was trying to look into options in ROI manager, but didn’t find such option. For example, option AND create overlapping mask of these structures, but I need to select mask of entire structures in channel 1 which at least partially overlap with the selection in the channel 2. Please let me know if you know how to do it in ImageJ. Thank you!

Hi Timur,
I think the BinaryReconstruct function in Gabriel Landini’s Morphology Plugin collection (G. Landini – Software – Novel context-based segmentation algorithms for intelligent microscopy) should be able to do what you want. In FIJI you can install these plugins simply by activating the ‘Morphology’ update site (List of update sites - ImageJ).
Here is a sample image with two channels:

Using the BinaryReconstruct function as shown below results in a new image that only contains the two upper red ellipses that overlap with the green ellipse.

run("Stack to Images");
run("BinaryReconstruct ", "mask=Untitled-0001 seed=Untitled-0002 create white");


Hope this helps,


Thank you Volko! It looks like to do this I need to create binary image with two colors. How can I do it? So far I know only how to create binary image of one color only.

Hi Timur,
No, you just need two binary images (binary images are always just black (0) and white (255)). For illustration, I just put the two binary images into a stack and showed the stack as a composite image with different colours for each slice. Sorry if this confused matters (I also should have uploaded the images as tif images rather than png, which didn’t show the individual channels and altered the pixel values - I did this in a bit of a rush). If you have separate binary images there is no need to combine them first into a stack. Simply use the second line of the code with the appropriate names of the two images that function as the mask and seed.
The macro code below creates two separate binary images and then uses binaryReconstruct (last line) to create a new image that only shows the particles in the mask image that overlap with the seed image.
I hope this is clearer now.
Good luck,

//Create binary sample mask image with four particles
run("Colors...", "foreground=white background=black selection=cyan");
newImage("Test-Mask", "8-bit black", 254, 254, 1);
makeOval(47, 55, 51, 50);
run("Fill", "slice");
makeOval(157, 125, 45, 47);
run("Fill", "slice");
makeOval(134, 51, 87, 41);
run("Fill", "slice");
//Create binary sample seed image with one particle
newImage("Test-Seed", "8-bit black", 254, 254, 1);
makeOval(51, 45, 163, 66);
run("Fill", "slice");
//Use BinaryReconstruct to create a new image that 
//only shows the particles in the mask image that overlap
//with the particle in the seed image 
run("BinaryReconstruct ", "mask=Test-Mask seed=Test-Seed create white");

Yes it worked! Thank you very much. Have a wonderful afternoon!