Want to combine RGB plane to form a specific color in an image
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Adam
am 3 Mär. 2017
Bearbeitet: Adam
am 3 Mär. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Modify Image Colors finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!