Want to combine RGB plane to form a specific color in an image
1 view (last 30 days)
Show older comments
I want to generate specific color by manually assigning values to RGB. e.g. R=0, G=128,B=64 to generate dark green color. I combined these planes with 'cat' command to generate image with dark green color. But it generate sky blue color. similarly when i want to generate shade of purple color by assigning r=142, g=111,b=238 and combine these planes with 'cat' command but it generate white color. Why it is so? and how i can resolve this problem?
here i am giving code :
t1_r(1:5,1:5)=142
t1_g(1:5,1:5)=111
t1_b(1:5,1:5)=238
i1=cat(3,t1_r,t1_g,t1_b);
figure; imshow(i1);
0 Comments
Answers (2)
Adam
on 3 Mar 2017
Edited: Adam
on 3 Mar 2017
t1_r(1:5,1:5)=uint8(142)
t1_g(1:5,1:5)=uint8(111)
t1_b(1:5,1:5)=uint8(238)
i1=cat(3,t1_r,t1_g,t1_b);
figure; imshow(i1);
There are other ways to do it, but basically matrices are doubles by default and as an RGB value Matlab interprets a double between 0 and 1 so any value above 1 will clip to 1 and you will get (1,1,1) which is white.
Your first case would give you [0 1 1] which is a cyan colour.
If you convert to uint8 then it expects values in the range you are giving it. You could instead define e.g.
t1_r(1:5,1:5) = 142/255;
etc, and then use a 'double' type. It is up to you.
0 Comments
See Also
Categories
Find more on Modify Image Colors in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!