Iterate through items with wand tool

Hi all,

I’m trying to utilize the wand tool on an image of object outlines. My end goal is to essentially iterate through every outline selectable using the wand tool and save each element. Does anyone know how I would go about iterating through each object selectable by the wand tool?

Thanks!

This would be possible using a macro. However, before delving into the details of how to accomplish that, I would first ask whether you really need to use the wand tool in that way, or whether you can instead use a typical segmentation workflow? If you post an example image, we can comment more effectively on that.

I do not think the wand tool is necessary and the segmentation tool would likely work as well too. The only advantage I thought the wand tool might offer is the ability to select individual objects instead of the entire mask which is all I’ve been able to do with the segmentation tool.

Hi @reberya,

you can go through your segmented objects using the ROI manager, also when using macro. If you have a binary mask image already (where the objects have a value of 255 and background/outlines are 0), create a selection from it using

run("Create Selection"); 

You can then split a segmentation in several objects using the command

roiManager("split");

https://imagej.nih.gov/ij/developer/macro/functions.html#roiManager(“split”)

Afterwards, you may select single (or multiple) items in the ROI manager by using

roiManager("select", 1);

You can then measure properties of these ROIs using

roiManager("measure"); 

Good luck with your analysis!

Cheers,
Robert

1 Like

Another more flexible way of splitting segmentations into disjoint objects is the Analyze Particles command. Or BioVoxxel site’s Extended Particle Analyzer for even more options. The major advantage of these commands is that they allow you to filter the objects by certain criteria such as size or circularity.

There is no tool (that I know of) called the “segmentation tool”. Which tool do you mean?

I am referring to the general process of segmenting images in ImageJ. Check out http://imagej.net/Segmentation which describes the process. You actually do not need to use any tools at all to do it—only commands. And ideally record a macro so that you and others can repeat the process on additional images later.

1 Like

Hi @haesleinhuepf & @ctrueden,

This in conjunction with the analyze particles tool and general process of segmentation (that’s what I was trying to refer to in my previous post, not a particular tool - oops!) tackles the majority of the issues I was having with transversing through each individual object.

The only remaining issue is that when I use the split tool after applying my selection to the original image, it pretty consistently double counts objects. Thus for one object, it will provide an accurate outline, then immediately after in the ROI manager it shows another outline which is only slightly different over the same object. Any idea of why this could be?

Thanks for all the help!

The Split command does not remove the old composite selection from the ROI Manager, but does add the new split ROIs in addition.

If you use Analyze Particles with the “Clear results” option, you will not have this problem.

If you still have trouble, please post a sample image and macro which illustrates the problem, and we can suggest specific changes to solve the issue.

@ctrueden I had the clear results option selected and make sure my ROI and results tabs are clear before running and I still have the same problem of extra counting. For the attached macro, running analyzed particles (size=1500-Infinity pixel) yields only 34 objects, but applying the selection generated from this anlayze particles function ultimately leaves me with 91 objects at the end of my macro.

The overall goal of this project is mentioned in a similar thread: Plugin Development - Fluoresence intensity and area - Analyze Particles stack

The images I’m trying to analyze look like:

and my current macro is:

run(“Duplicate…”, “title=Mix-1.tif”);
selectWindow(“Mix.tif”);
run(“8-bit”);
run(“Auto Threshold”, “method=Li white”);
run(“Analyze Particles…”, “size=1500-Infinity pixel show=[Bare Outlines] display clear”);
run(“Clear Results”);
run(“Auto Threshold”, “method=Li white”);
run(“Create Selection”);
selectWindow(“Mix-1.tif”);
run(“Restore Selection”);
run(“ROI Manager…”);
roiManager(“Split”);
run(“Select All”);
roiManager(“Measure”);

Again, thanks so much for all your help!

Hi @reberya,

in fact, you do your analysis twice - that’s probably not intended. After doing

run("Analyse particles...

you already have a results table with all your measurements. When I run the code on the image it’s 29 objects. Just run the code from lines 1-5 without the rest.

Furthermore, I guess you want to measure signal intensity on the original image. For this you need a trick using the “redirect” option in the “Set measurements” menu. Here is your adapted macro: Try it :slight_smile:

// get the title of the current image to select the image later
title = getTitle()

// copy the image
run("Duplicate...", "title=DUP_" + title);
selectWindow("DUP_" + title);

// do the segmentation
run("8-bit");
run("Auto Threshold", "method=Li white");

// configure what properties to measure and in which image (the original image)
run("Set Measurements...", "area mean redirect=" + title + " decimal=2");

// do the measurements and send the ROIs to the ROI manager
run("Analyze Particles...", "size=1500-Infinity show=Nothing display clear add");

// close the image copy and select the original
close();
selectWindow(title);

// visualise the ROIs on the original image
roiManager("Show None");
roiManager("Show All");

Cheers,
Robert

2 Likes

@haesleinhuepf This works great! Thanks everyone for all your help with this. It’s much appreciated.

1 Like