Selecting the border of an image



I am using Fiji for my image analysis. This is the Image that I want to Analyze.


I want to select the circular border in the image which I can select using Wand Tool and then invert the image for further operations.


I want to write a script, so that I can automate this process for other images.

Thanks in advance.


You can use the ImageJ macro recorder to record the commands, e.g., of the Wand tool, see:

Here the command I recorded:

doWand(24, 125);


Hi Bio7,

I tried this as well but the problem is the doWand() command does not select the boundary for other images. I have 500 images with different shapes. That is why I need a more generic solution.



Try the following:

run("Duplicate...", " ");
setMinAndMax(0, 0);
run("Apply LUT");
run("Fill Holes");
run("Create Selection");

This could be a start for automating your process.

See here my screenshot:


You could also set a threshold before using the wand tool which works for specific areas across several images:

 setThreshold(0, 9) //use a threshold which works for all images!
 doWand(13, 18); //some random pick of the background!

If some of the images haven’t a closed shape you have to work with binary operations to close them.



Even after thresholding the image, its not able to detect the boundary correctly.

@Danielle_Z :
"Fill Holes " is not implemented since the image is not 8-bit. Whwn I convert the image the 8 bit and then run macro, the macro is throwing an error : No window with the title "Original " found. I changed the name to current window name and I can see the area value in results but the selection is not displayed (complete black window).

Sorry for the late reply.


Apologies, l was unclear: I had named your image ‘original’ for myself to play with. The steps I provided there are really just a start and not a full automation just yet.

In the macro you could add the following to get round having to rename your image:
title = getTitle;
then replace

If I understand correctly, at the point where you would run("Create Selection");, it comes up with a black window?


yes, the black window comes up when I run(“Create Selection”)