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

45 views (last 30 days)
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
DGM
DGM on 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.
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
Himawari Tanaka
Himawari Tanaka on 3 Mar 2022
Unfortunately my task was to somehow make all the pixels of an image look like this. The intensity and brightness of each subpixel depends on their values of each pixel.
Thank a lot for your code. I think I will have to somehow modify the code as DGM said. I have been trying to separate RGB channel and display all pixels of the original image like above. So far, getting individual R, G, B channel of an image and their values are the best that I could get.
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!