% Separate input image’s color channel
imgr = r(:,:,1);

% Compute input’s histogram
Hnimgr = imhist(imgr)./numel(imgr);

% Histogram specification, using image reference
outr = histeq(imgr);

histsp(:,:,1) = outr;
                          
%% Plot histogram & Display Image
%Show Image


subplot(335);imshow(r);title('Input Image');

subplot(337);imshow(histsp);title('Result Image');