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 ));