MATLAB achieves Histogram Matching of color image (R, G, B) color components and calculates their correlation

Source: Internet
Author: User

Function implementation converts a color image to a histogram component Vector

Calcrgb2hist. M file

Function hist = calcrgb2hist (picname) pic1 = imread (picname); pic1r = pic1 (:,:, 1); pic1g = pic1 (:,:, 2 ); pic1b = pic1 (:,:, 3); figure, imshow (pic1r) Title ('R component image ') % 2. Draw a histogram [m, n] = size (pic1r); % rhist = zeros (1,256); % pre-created vector for storing the gray probability of occurrence (k + 1) = length (find (pic1r = k)/(m * n); % calculate the probability of gray-scale appearance of each level, store it in the corresponding position of rhist endfigure, bar, rhist, 'R') % plot the title ('R like histogram ') xlabel ('grayscale value') ylabel ('probability of occurrence') % ghist = zeros (1,256); For k = 0: 255 ghist (k + 1) = length (find (pic1g = k)/(m * n); endfigure, bar (0: 255, ghist, 'G') Title ('R like histograms ') xlabel ('grayscale value') ylabel ('probability of occurrence') % bhist = zeros (1,256 ); for k = 0: 255 bhist (k + 1) = length (find (pic1b = k)/(m * n); endfigure, bar (0: 255, bhist, 'B ') title ('R like histogram ') xlabel ('grayscale value') ylabel ('probability of occurrence') hist = [reshape (rhist ', 1,256), reshape (ghist ', 1,256), reshape (bhist ', 1,256)]; % Concatenates the histogram into a vector of 256*3. End


Below are the main functions executed

P1 = calcrgb2hist('frame22.bmp '); P2 = calcrgb2hist('frame22.bmp'); G = effeccoef (P1, P2); fprintf ('correlation coefficient = % d \ n', g ));



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.