How to display R, G, B colours of an individual pixel in an image?

8 views (last 30 days)
Himawari Tanaka
Himawari Tanaka on 3 Mar 2022
Commented: Image Analyst on 3 Mar 2022
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.

Answers (4)

KSSV
KSSV on 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.
  1 Comment
Himawari Tanaka
Himawari Tanaka on 3 Mar 2022
Can you show me some code examples of how patch() and text() could be used in my case? I have been reading about those functions, but I don't understand much how they related to my topic. It would be very helpful for me, thank you a lot.

Sign in to comment.


Simon Chan
Simon Chan on 3 Mar 2022
Use function imsplit
[R,G,B] = imsplit(I)
  1 Comment
Himawari Tanaka
Himawari Tanaka on 3 Mar 2022
I have used the imsplit() function in my code, but in the end, all pixels only represent 1 colour of either R, G or B. For example, here is my final result of the B channel of a pixel after using imsplit. I expect the R and G to be black or white, since they are 0, but they still represent as B colour with value 80.
Do you know how can I code this differently? Thank you a lot in advance.

Sign in to comment.


Image Analyst
Image Analyst on 3 Mar 2022
  3 Comments
Himawari Tanaka
Himawari Tanaka on 3 Mar 2022
Thanks alot for your insight. I was wondering if you know some modifications that I could apply?

Sign in to comment.


Image Analyst
Image Analyst on 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))
pixelColors = 1×3
63 34 68
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 Comments
Image Analyst
Image Analyst on 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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!