Histogram Equalization, Stretching, origin histo compare and example source code

Example source code for histogram equalization
and compare with origin histogram and stretching histogram.

result is like that:

origin image & histogram




stretching image and histogram






Equalization image and histogram
 

<gist>

</gist>


tags:
equalizeHist, cvtColor, normalize, calcHist

opencv histogram stretching, example source code.

Histogram stretching
It's just adjusting the range with the same ratio.

For example, there is a range of numbers.
60, 61, 62, 63, 64, 65
Stretching is to extent other range, such as 0~255.
So, if we stitching 60~65 to 0~255, numbers will be like that.
60 -> 0
61 -> 51
62 -> 102
63 -> 153
64 -> 204
65 -> 255

so, in case of histogram, origin histogram will be stretched like that

image source : https://stackoverflow.com/questions/41118808/difference-between-contrast-stretching-and-histogram-equalization

then, let's look at code and result with real image.

origin input image


histogram


stretched image


histogram of stretched image


source code
<gist start>

<gist end>




Hue histogram example opencv source code

Hue histogram example source code.

input


Hue histogram output


source code
<gist start>

<gist end>

calcHist for RGB image, opencv histogram example

A Example source code for rgb histogram, the source code uses calcHist function in opencv.

Important things in the source code are the part of split rgb mat to vector[3] and drawing part.
Read the code carefully, so then you can understand easliy. ^^

input


the result of rgb histogram


<gist code start>

<gist code end>



reference : https://docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/histogram_calculation/histogram_calculation.html

calcHist for gray image, opencv Histogram example

This is example to use calcHist for grayimage.

input image


output


source code

end code


WebCam Histogram Test, OpenCV

Histogram Test on webcam stream
Refer to below source code..😀

test video


< gist >

< /gitst >



tags : normalize, calcHist, MatND