I want to separate the RGB components(as R,G,B) of a color image also showing its histogram each. And then compare each histogram(of R,G,B) of a query image with each histogram of the database image respectively. i need a code for this plz.

3 views (last 30 days)
this was the code i took from here itself.
red = a(:,:,1); % Red channel
green = a(:,:,2); % Green channel
blue = a(:,:,3); % Blue channel
b = zeros(size(a, 1), size(a, 2));
just_red = cat(3, red, b , b); just_green = cat(3, b, green, b); just_blue = cat(3, b, b, blue);
[queryred, querymap1] = rgb2ind(just_red,256); [querygreen, querymap2] = rgb2ind(just_green,256); [queryblue, querymap3] = rgb2ind(just_blue,256);
figure, imshow(just_red), title('Red channel') figure, imshow(just_green), title('Green channel') figure, imshow(just_blue), title('Blue channel')
closepreview(vid)
% Plots a bar chart of the histogram of the color channel.
function pixelCount = PlotHistogramOfOneColorChannel(oneColorChannel, subplotNumber, caption, color) try % Let's get its histogram into 256 bins. [pixelCount grayLevels] = imhist(oneColorChannel, 256);
subplot(3, 3, subplotNumber); bar(grayLevels, pixelCount, 'FaceColor', color); title(caption, 'FontSize', 16); grid on; % Set the x axis range manually to be 0-255. xlim([0 255]); catch ME errorMessage = sprintf('Error in function PlotHistogramOfOneColorChannel.\n.\n\nError Message:\n%s', ME.message); uiwait(warndlg(errorMessage)); end return;

Answers (1)

Image Analyst
Image Analyst on 6 Nov 2023
See attached demo.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!