how can i calculate brightness,contrast,hue and saturation of a image?

90 views (last 30 days)
i want to calculate brightness,hue,saturation and contrast of an image.

Answers (3)

Jurgen
Jurgen on 26 Feb 2013
Assuming its an rgb image, you can do rgb2hsv to find the hue and saturation of pixels. Value is similar to brightness, but you may mean brightness from the hsb space. There is no function rgb2hsb.
Also note that saturation is/could be defined differently in other colorspaces. E.g. saturation of a pixel in hsl space is not the same as its saturation in hsv space.
Contrast could be defined as a ratio. E.g. highest brightness / lowest brightness in image.
  2 Comments
DGM
DGM on 5 Jul 2022
For sake of clarity, "HSB" typically refers directly to HSV -- asymmetric saturation space and all. So there really isn't any need for rgb2hsb() to exist.

Sign in to comment.


Image Analyst
Image Analyst on 5 Jul 2022
Useful conversions on the Math section here:
and here:

DGM
DGM on 5 Jul 2022
@Jurgen's answer recommending HSV is probably as appropriate as the vague question warrants. Still, since it seems people are still reading this question looking for similar answers, I might as well throw this out there.
If you want to calculate "brightness", you'll have to define what "brightness" means. If I had a bag of flour that had a "heaviness" of 3.2, what would that mean? These words have poor specificity. As Jurgen suspects, "brightness" may refer to B in HSB, which is synonymous with Value in HSV -- i.e. the maximum RGB value. As measures of "brightness" go, V is probably the worst available. You could use any other brightness metric if you wanted:
Similarly, hue is not the same in all color models. The angular (hue) displacement between two colors is also not consistent between different models. You'll have to choose what color model you want to consider.
Similarly, "contrast" is a nonspecific term. It could mean anything from a simple difference or ratio of extrema to a relatively complex expression. You'll have to pick a method that's suited to your task. A good starting point might be
simplecontrast = range(myimage(:))/mean(myimage(:));

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by