How to display R, G, B colours of an individual pixel in an image?
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone
I want to display the exact R, G, B colors for all pixels instead of only getting their R, G, B values where three colors are still blended per pixel. To clarify my question, I have obtained R, G, B values for all single pixels of my image using impixelregionpanel function, but I wish to display each pixel as 3 individual RGB color channels based on their values in an image, instead of having blended final color as the result. I attached the picture below as an example to clarify my point.

I wonder if there is a way to do this in MATLAB?
Thank you very much for your help.
0 commentaires
Réponses (4)
Image Analyst
le 3 Mar 2022
If you want to make your own little image and display it you could do something like
rgbImage = imread('peppers.png');
[rows, columns, numberOfColorChannels] = size(rgbImage);
% Get the RGB colors at some location in the image.
pixelColors = uint8(impixel(rgbImage, 20, 50))
smallImage = pixelColors(1) * ones(300, 300, 'uint8');
smallImage(:, :, 2) = pixelColors(2); % Assign green.
smallImage(:, :, 3) = pixelColors(3); % Assign blue.
imshow(smallImage);
% Make lines across image.
smallRows = size(smallImage, 1);
yline(round(smallRows/3), 'Color', 'y', 'LineWidth', 2);
yline(round(2*smallRows/3), 'Color', 'y', 'LineWidth', 2);
% Place texts
xt = size(smallImage, 2) / 2;
% First the red value.
yt = smallRows/6;
str = sprintf('R = %d', pixelColors(1));
text(xt, yt, str, 'Color', 'y', 'FontSize', 20, 'FontWeight','bold','VerticalAlignment','middle', 'HorizontalAlignment','center');
% Next the green value.
yt = 3 * smallRows/6;
str = sprintf('G = %d', pixelColors(2));
text(xt, yt, str, 'Color', 'y', 'FontSize', 20, 'FontWeight','bold','VerticalAlignment','middle', 'HorizontalAlignment','center');
% Next the blue value.
yt = 5 * smallRows/6;
str = sprintf('B = %d', pixelColors(3));
text(xt, yt, str, 'Color', 'y', 'FontSize', 20, 'FontWeight','bold','VerticalAlignment','middle', 'HorizontalAlignment','center');
2 commentaires
Image Analyst
le 3 Mar 2022
I don't know what you want, like how many rows and how many columns, whether you want text labels over the unifrmly-colored blocks or not, and the direction of the R, G, and B blocks. Presumably you do, so good luck.
KSSV
le 3 Mar 2022
MAke/ create the required coordinates/ locations where you want to put text and the use patch, text.
Read about patch and text.
Image Analyst
le 3 Mar 2022
See Steve Eddins File Exchange submission

3 commentaires
DGM
le 3 Mar 2022
I'm pretty sure that if you want that, you're going to have to roll your own. You might be able to work off of im2html() or even impixelregionpanel(), but I don't know of any solution that would work without modification.
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



