[OpenCV Getting Started Guide] Article 10 color histogram equalization

Source: Internet
Author: User

In the previous article "OpenCV Article 10 grayscale histogram equalization", we introduced the histogram equalization of grayscale images. in actual life, it is certainly the most commonly used color images. Therefore, this article introduces the histogram equalization of color images. In this way, histogram equalization can give you an intuitive impression on the image enhancement effect.

In OpenCV, color images are actually stored in a multi-channel array. The value ranges from 0 to 255 for each element in a single channel array. This is the same as the change range of pixels in grayscale images. ThereforeFor color image histogram equalization, you only need to first divide the color image into several channels, then these channels perform histogram equalization respectively, and finally merge all channels.The following describes the two main functions: cvSplit () and cvMerge ().

 

1. cvSplit

Function: splits multi-channel numbers to form several single-channel arrays or extracts a channel from the array.

Function prototype:

/* Splits a multi-channel array into the set of single-channel arrays or

Extracts participant [color] plane */

CVAPI (void) cvSplit (

Const CvArr * src,

CvArr * dst0,

CvArr * dst1,

CvArr * dst2,

CvArr * dst3

);

Parameter description:

The first parameter indicates the input multi-channel array, that is, the input image.

The second, third, fourth, and fifth parameters represent the output single-channel array.

 

Ii. cvMerge

Function: splits multi-channel numbers to form several single-channel arrays or extracts a channel from the array.

Function prototype:

/* Merges a set of single-channel arrays into the single multi-channel array

Or inserts one participant [color] plane to the array */

CVAPI (void) cvMerge (

Const CvArr * src0,

Const CvArr * src1,

Const CvArr * src2,

Const CvArr * src3,

CvArr * dst

);

Parameter description:

The first, second, and third parameters represent the input single-channel array.

The fifth parameter indicates the merged multi-channel array, that is, the output image.

 

The complete code is provided below:

// Image Enhancement-color histogram equalization // By MoreWindows (http://blog.csdn.net/MoreWindows) # include <opencv2/opencv. hpp> using namespace std; # pragma comment (linker, "/subsystem: \" windows \ "/entry: \" mainCRTStartup \"") // IplImage * EqualizeHistColorImage (IplImage * pImage) {IplImage * pEquaImage = cvCreateImage (cvGetSize (pImage), pImage-> depth, 3 ); // The original image is divided into different channels and then balanced. After the original image is merged, the histogram of the color image is balanced. const int MAX_CHANNEL = 4; IplImage * pImageChannel [MAX_CHANNEL] = {NULL}; int I; for (I = 0; I <pImage-> nChannels; I ++) pImageChannel [I] = cvCreateImage (cvGetSize (pImage), pImage-> depth, 1 ); cvSplit (pImage, pImageChannel [0], pImageChannel [1], pImageChannel [2], pImageChannel [3]); for (I = 0; I <pImage-> nChannels; I ++) cvEqualizeHist (pImageChannel [I], pImageChannel [I]); cvMerge (pImageChannel [0], pImageChannel [1], pImageChannel [2], pImageChannel [3], pEquaImage); for (I = 0; I <pImage-> nChannels; I ++) cvReleaseImage (& pImageChannel [I]); return pEquaImage;} int main (int argc, char ** argv) {const char * pstrWindowsSrcTitle = "source image (http://blog.csdn.net/MoreWindows)"; const char * pstrWindowsHisEquaTitle = "after histogram equalization (http://blog.csdn.net/MoreWindows )"; // load the source image IplImage * pSrcImage = cvLoadImage ("lena.jpg", photo); IplImage * pHisEquaImage = EqualizeHistColorImage (pSrcImage); cvNamedWindow (photo, photo); cvNamedWindow (photo, photo, CV_WINDOW_AUTOSIZE); cvShowImage (values, pSrcImage); cvShowImage (values, pHisEquaImage); cvWaitKey (0); cvDestroyWindow (values); cvReleaseImage (& pSrcImage ); cvReleaseImage (& pHisEquaImage); return 0 ;}

The running result is as follows:

By contrast, we can see that the histogram equalization has a good effect on image enhancement. After the image contrast is increased, the eyelashes, hair, and other small objects are much clearer.

 

This is the end of the histogram series in the [OpenCV Getting Started Guide]. The following lists the directories for your convenience:

1. Chapter 8 grayscale histogram in [OpenCV Getting Started Guide]

2. [OpenCV Getting Started Guide] Article 9 grayscale histogram equalization

3. [OpenCV Getting Started Guide] Article 10 color histogram equalization

 

The next article [OpenCV Getting Started Guide] 11th mouse drawing will introduce the development of a simple mouse drawing program with OpenCV. Welcome to continue browsing.

 

 

Articles in the OpenCV Getting Started Guide series:

Http://blog.csdn.net/morewindows/article/category/1291764

Reprinted please indicate the source, original address: http://blog.csdn.net/morewindows/article/details/8364722

Welcome to Weibo: http://weibo.com/MoreWindows

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.