How do I specify settings when running Color Threshold in ImageJ Macro

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I specify settings when running Color Threshold in ImageJ Macro

jerryk
How can I run Image > Adjust > Color threshold... using specific settings
such as:
Threshold color = white
Color space = HSB

For the Hue, Saturation, Brightness sliders, how do I specify their values ?

I have folders containing five .tif images that I want to apply color
threshold with the same specific values for hue, saturation, brightness,
threshold color, color space etc... for all of them.

My code currently (I am a beginner to ImageJ macros by the way):

dir = getDirectory("");
images = getFileList(dir);
setBatchMode(true);
for (i = 0; i < images.length; i++) {
        open(dir+images[i]);
        imgName = getTitle();
        run("Color Threshold...");
        selectImage(imgName);
        run("Measure");
}
run("Summarize");

Also, is there a way that I can calculate the standard deviation and mean of
the Hue, Saturation, Brightness distributions for all pixels in the original
image?

For example, in Python I used the opencv2 module to convert an image to a
numpy array. I iterated through each pixel and found the standard deviation
of the values for Hue, Saturation, Brightness. I would like to use this
standard deviation as a range for my color threshold. I would like to do
this in ImageJ Macro, since I don't know how to transmit data from python
scripts to ImageJ macros.

This is an example of what I want to do:

run("Color Threshold...",
"Hue = [meanHue - stdHue, meanHue + stdHue]",
"Saturation = [meanSaturation - stdSaturation, meanSaturation +
stdSaturation]",
"Brightness = [meanBrightness - stdBrightness, meanBrightness +
stdBrightness]"
)

Maybe it's not implemented this way but I would like to know how.

Any help would be greatly appreciated. Thanks.




--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How do I specify settings when running Color Threshold in ImageJ Macro

Gabriel Landini
On Tuesday, 1 October 2019 22:04:52 BST jerryk wrote:
> How can I run Image > Adjust > Color threshold... using specific settings
> such as:
> Threshold color = white
> Color space = HSB
> For the Hue, Saturation, Brightness sliders, how do I specify their values ?

I do not think you can. That is an interactive tool. If you need to record a
macro so it replicates the result obtained with the current settings of the
colour thresholder,  use the "Macro" button.

Cheers

Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How do I specify settings when running Color Threshold in ImageJ Macro

Herbie
In reply to this post by jerryk
Good day!

Instead of using the color threshold feature, did you consider to
transform the images to the HSB color space and to set individual, i.e.
achromatic thresholds for the three resulting slices?

HTH

Herbie

::::::::::::::::::::::::::::::::::::
Am 01.10.19 um 23:04 schrieb jerryk:

> How can I run Image > Adjust > Color threshold... using specific settings
> such as:
> Threshold color = white
> Color space = HSB
>
> For the Hue, Saturation, Brightness sliders, how do I specify their values ?
>
> I have folders containing five .tif images that I want to apply color
> threshold with the same specific values for hue, saturation, brightness,
> threshold color, color space etc... for all of them.
>
> My code currently (I am a beginner to ImageJ macros by the way):
>
> dir = getDirectory("");
> images = getFileList(dir);
> setBatchMode(true);
> for (i = 0; i < images.length; i++) {
> open(dir+images[i]);
> imgName = getTitle();
> run("Color Threshold...");
> selectImage(imgName);
> run("Measure");
> }
> run("Summarize");
>
> Also, is there a way that I can calculate the standard deviation and mean of
> the Hue, Saturation, Brightness distributions for all pixels in the original
> image?
>
> For example, in Python I used the opencv2 module to convert an image to a
> numpy array. I iterated through each pixel and found the standard deviation
> of the values for Hue, Saturation, Brightness. I would like to use this
> standard deviation as a range for my color threshold. I would like to do
> this in ImageJ Macro, since I don't know how to transmit data from python
> scripts to ImageJ macros.
>
> This is an example of what I want to do:
>
> run("Color Threshold...",
> "Hue = [meanHue - stdHue, meanHue + stdHue]",
> "Saturation = [meanSaturation - stdSaturation, meanSaturation +
> stdSaturation]",
> "Brightness = [meanBrightness - stdBrightness, meanBrightness +
> stdBrightness]"
> )
>
> Maybe it's not implemented this way but I would like to know how.
>
> Any help would be greatly appreciated. Thanks.
>
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html