Selecting the border of an image

fiji
imagej

#1

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

ct2%20-%20Copy

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.

ct2%20-%20Copy%20invert

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

Thanks in advance.


#2

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

https://imagej.nih.gov/ij/docs/guide/146-31.html#sub:Record
http://imagej.net/Introduction_into_Macro_Programming

Here the command I recorded:

doWand(24, 125);


#3

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.


#4

Hello,

Try the following:

run("Duplicate...", " ");
setMinAndMax(0, 0);
run("Apply LUT");
run("Fill Holes");
run("Create Selection");
roiManager("Add");
selectWindow("original");
roiManager("Measure");

This could be a start for automating your process.

See here my screenshot:


#5

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.


#6

@Bio7:

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.


#7

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
selectWindow("original");
with
selectWindow(title);

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


#8

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