How to quantify gradient image

I want to measure intensity of blue colour in this picture attached below. But when I am trying to measure mean gray value, it is shown higher in ‘light blue’ areas instead of ‘dark blue’ areas. Why so? can you suggest me a way to do it properly?

images

How about this:

  1. I downloaded your image, naming it blue_gradient.jpeg.

  2. I used Fiji Macro recorder to record the basics for this javascript script to select and plot a line plot. The script is below. I needed to add the importClass lines to import the classes we needed to run in Fiji’s script editor w/o changes. Change the path to suit your installation. I ran the script on the blue channel image.

importClass(Packages.ij.IJ);
importClass(Packages.ij.gui.Line);
importClass(Packages.ij.plugin.ChannelSplitter);

IJ.run("Close All");
imp = IJ.openImage("/Users/jrminter/Downloads/blue_gradient.jpeg");
IJ.run(imp, "Line Width...", "line=60");
channels = ChannelSplitter.split(imp);
imp_blue = channels[2]
imp_blue.setRoi(new Line(0,52,420,48));
IJ.run(imp_blue, "Plot Profile", "");
imp_blue.show();

  1. The results is
    blue_gradient_with_line_flattened

  2. The line profile creates provides a button to export the data data.csv (7.4 KB) from


    Hope this helps
    John

Thank you so much sir for solving my problem. I tried to run the macro but it is showing this error as mentioned below:
Undefined identifier in line 1:
(packages.ij.IJ)
Can you please guide me why?
Thank you again!

Please make also sure not to use *jpg for your analysis. This will introduce compression artifacts which will be included in your analysis. Especially when measuring gradients.

1 Like

You probably tried to run the script as an ImageJ macro? However, the script from @John_Minter is a javascript script. In the script editor switch to JavaScript in the Language menu and try again.

Yes you are right. I ran the script in imageJ macro. Thanks for the help!
By the way, @John_Minter sir can you tell why the mean gray value, when I directly measure, showing totally different result as I mentioned in the original question?

@Bio7 Can you please elaborate a bit on it? I couldn’t understand. Thanks for the help!

See:

https://imagej.nih.gov/ij/docs/guide/146-26.html#infobox:JpegAlert

Dear @Viraj_Mehta,

actually the mean grey value is not suitable for what you describe as the intended measurement.
If you want to get an impression about how strong a color is saturated, intensity does not help you.
One possibility is to use for example the saturation. That wouls make sense in the case you have only a single color in your image since it does not distinguish between colors. A distinction would need some additional restriction to specific color tones (hues).

The followinf macro is converting your input image into an HSB stack and analyses the saturation (second) channel using the plot tool in the complete image in horizontal direction.

run("HSB Stack");
setSlice(2);
run("Select All");
run("Plot Profile");
1 Like

@Viraj_Mehta, biovoxxel is correct. To answer your question, the mean gray level is different because you measured the mean gray level of all three channels and I measured the mean gray level of only the blue channel. In reality, one does not want an intensity value but instead wants to measure an optical density which is on a logarithmic scale.

To do proper color measurement one needs reproducible illumination and standard specimens with known color and optical density patches to verify that the measurements are consistent. My colleagues at Kodak had labs that specialized in this. In my quantitative microscopy group we had standard gray and color patches to image (certified by our color science colleagues) and protocols to reproducibly set our light source intensity and to make certain that the illumination was stable during the measurement cycle.

This site has a nice introduction to optical densitometry. I should note that one can measure either transmitted density (of a film strip) or reflected density (of a printed patch.)

Best regards,
John

1 Like

@biovoxxel @John_Minter @Bio7 Thanks a lot for spending your time to explain this to me!