Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Why are saturation results different than Matlab's imhist() function?

We have a machine vision application where we had set some threshold levels in Matlab, and had planned on applying them to NI's IMAQ libraries. However, when trying to reproduce a set of Matlab results to verify our VB code was working, we found that we could reproduce Matlab's results on the R, G, B, and H planes, but not the S plane.

For example, if you take the 50% red image at http://www.cae.tntech.edu/~mwr/red-50.png and load it into both Vision Builder and Matlab, you get the following results:

Matlab:

rgb=imread('red-50.png');
hsv=rgb2hsv(rgb);
[hist_s,bins]=imhist(hsv(:,:,2),101);
bins(find(hist_s==max(hist_s)))
ans =
0.5000

Vision Builder 6.0.5:

Load red-50.png
Extract Col
or Planes: HSL - Saturation Plane
Histogram -> results in a peak in bin 64 on a 0-255 scale.

How many different ways are there to calculate saturation? So far, Matlab and Corel Photo-Paint agree on their calculations, and Vision Builder is the odd one.
0 Kudos
Message 1 of 3
(3,533 Views)
Not really an answer, just an edit to the original question. We can reproduce the R, G, B, and V planes, but neither H nor S planes. S shows the most obvious error even on test images, but H showed errors on the images that we need to analyze.
0 Kudos
Message 2 of 3
(3,533 Views)
Mike,

Thank you for posting on the forum. We spoke regarding this question, but I wanted to reply to this post with some information for other readers. You can see how we are calculating the HSL plane by examining the equations in the Vision Concepts Manual. Using the formulas, I was able to confirm that we are calculating the value for the HSL plane from the equation listed there:

S = 255(1-3min(R,G,B)/(R+G+B))

where R, G, and B in this equation are normalized. So given an RGB image (255,127,127) then we get the following values:

S = 255(1-(3*.5)/(2))
S = 63.75

I also created an image in just MS Paint with the RGB values of (255,127,127) and that gave me HSL values of (0,240,180) -- or in MS Word HSL values of (0,255,191). These latter values match
ed the HSI values returned from LabVIEW (using the IMAQ ColorHistogram VI).

Regards,
Michael
Applications Engineer
National Instruments
0 Kudos
Message 3 of 3
(3,533 Views)