how can i calculate brightness,contrast,hue and saturation of a image?
90 views (last 30 days)
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.
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(:));