Want to combine RGB plane to form a specific color in an image

1 visualización (últimos 30 días)
chaitali laulkar
chaitali laulkar el 3 de Mzo. de 2017
Respondida: chaitali laulkar el 6 de Mzo. de 2017
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);

Respuestas (2)

Adam
Adam el 3 de Mzo. de 2017
Editada: Adam el 3 de Mzo. de 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.

chaitali laulkar
chaitali laulkar el 6 de Mzo. de 2017
Its working. Thank you very much.

Categorías

Más información sobre Modify Image Colors en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by