How to exclude certain objects in image from ROI measurements?

Hi! I’m new to ImageJ and Fiji, and am having trouble figuring out how to effectively create masks and measure ROIs.

For example, I would like to be able to draw selections on the following image and calculate measurements for each ROI without include information from the white and dark circular objects.

Screen Shot 2021-05-07 at 11.08.33 AM

I’ve used the Trainable Weka Segmentation plugin to classify the objects already-- the region in the original image corresponding to green is what I would like to calculate measurements for.

Screen Shot 2021-05-07 at 11.09.49 AM

From here, what is the best way to create a mask that excludes what we see in purple and red; and take intensity measurements that exclude information from those objects? And is this the best way to complete this task in Image J? I’ve already binarized the classification output using the color threshold function, but am a bit lost as to where to go from here.

Also as an aside, is there a way to properly run the Weka Segmentation on very large images?

Thank you!

Since you already have white and black objects, you can directly apply Color Threshold to the original file just by selecting the central brightness pick. You should play a little bit with the range selection until you are satisfied with it

The selection shoulds look like:

Then, click on the “Select” button in the “Threshold Color” menu. You will get a ROI selecting only the outside of the black and white particles.

Whatever measurement you make with “Analyze” will only take into account the selected part of the image (excluding the particles). For example, “Plot Histogram” and “Measure” give

Hope this helps

Unfortunately, thresholding this way won’t work because the gray values found in the particles are also found in the remaining portion of the image. Excluding the particles this way excludes information we need in the photo.

Would you happen to know of any other method? Or perhaps a way to incorporate the Weka segmentation we’ve shown above?

Maybe transform your color mask output from Weka in grayscale then use threshold to select the specific gray level that you want (from your image it looks like it will be the gray level corresponding to the green area).
Click apply then go to Edit> Selection> Create selection, and hit “t” on your keyboard to add the selection to the ROI manager.
Then go back to your original image and click on your selection in the ROI manager then measure.
Everything can be automated in a macro once you know which grey level to select in threshold.


Also for applying your trained weka segmentation model to large images you can use the Beanshell script posted by @iarganda

It works well, I just tried it recently.


@ha2021 I haven’t used Weka segmentation before, but if it converts your pixels to green and purple, maybe you can use the “Hue” filter in “Threshold Color” to select only the green range, and then follow the steps I explained before.

Thanks for your help!

Thanks for your reply! If we use a script, does not mean everything would hav to be done using macros, meaning we can’t use the user interface?

Yes you will not have the user interface with the script, because the script is just to apply a classifier that you trained before.
You don’t need to train a new classifier each time on each image, you just do it on a subset of your data, then you save the model/classifier and apply it to the rest of your data (or to large images).

You first need to create a model in Trainable weka segmentation by using several pictures from your dataset. For that you first need to create a multistack image in Fiji. You need to open in Fiji several images that could be representative of all your images (I think they need to be the same size). If you only have big images to use for training, crop them first to small size (512x512 pixels or 1024 x 1024).

Then you go to Image>Stacks>Images to stack
This will allow you to generate an image that contains several stacks. Then you can use this multistack image to train a new model in Trainable weka segmentation. You can go from stack to stack using the mouse wheel.
Once you are satisfied with the segmentation, you click on “Save classifier” within Trainable weka window.

Then you can apply this classifier on large images with the Beanshell script that I mentioned in my earlier post (once you run the script it will ask you to choose the folder where are located your images to be segmented/classified, where is located your classifier (the one that you just trained before).
Then you let it run and it will create the masks (don’t use probability map if you just want the segmented images).

Hope it can help.



1 Like