RGB color error

8 Ansichten (letzte 30 Tage)
huseyin kara
huseyin kara am 25 Jun. 2012
i have a image and i want to correct its color such as [232 25 40] to [255 0 0] exact red on MATLAB but when i try to do this if there is gray color, it became white. i mean, if the image does not have 255 color values, when i try to correct it with using least square method its all pixel values were shown 255 or 0 while some pixel values are not 255 or 0 such as 120 or 210. That is, my corrected image matrix has for example [213 100 120] (after corrected value) but it shown with imshow() commend like [255 0 0]. i will be glad if you help me. thank you.
imdir='C:\Users\infodif\Desktop\MatlabDeneme\';
imfile='im2.png';
im=imread([imdir, imfile]);
size(im)
R=im(:,:,1); G=im(:,:,2); B=im(:,:,3);
r=R(:); g=G(:); b=B(:);
D=[r,g,b];
K=[196 43 63; 115 177 78; 6 65 155];
O=[255 0 0; 0 255 0; 0 0 255];
k=inv(K);
A=k*O;
n=160; m=228;
C=double(D)*double(A);
R1=C(:,1); G1=C(:,2); B1=C(:,3);
for j=0:(m-1)
for i=1:n
rc(i,j+1)=R1(i+j*n ,:);
i=i+1;
end
j=j+1;
end
for j=0:(m-1)
for i=1:n
gc(i,j+1)=G1(i+j*n ,:);
i=i+1;
end
j=j+1;
end
for j=0:(m-1)
for i=1:n
bc(i,j+1)=B1(i+j*n ,:);
i=i+1;
end
j=j+1;
end
RGB(:,:,1)=rc; RGB(:,:,2)=gc; RGB(:,:,3)=bc; imshow(RGB)
this is my code.
  4 Kommentare
huseyin kara
huseyin kara am 25 Jun. 2012
i am trying to correct color of an image. to do this i took image and divided to red green and blue colors and r=R(:); with this command, i get a column matrix. D=[r,g,b] represents red green and blue values of each pixels. then K matrix is color values of pixels that i measure image on the screen. O matrix is real color values of pixels. A is least square matrix to get the correct color values. C is the operation of images each pixels multiply with the correction (least square matrix). that is, C is corrected matrix that image has real color values. for loops help to get (m*n,3) matrix to (m,n,3) matrix which is equal to the image's size. But i did not get the pixel color values which is between 0 and 255 such as gray color [120 120 120]. How i can get the gray color?
Image Analyst
Image Analyst am 25 Jun. 2012
I do color correction all the time. What is your model? You can use single channel linear, single channel quadratic, single channel cubic, cross channel linear, cross channel quadratic, or cross channel cubic. What model you choose depends on several things like the reason you expect your colors to be off from the expected values. For example, has there been a color shift in your lighting, or is it solely due to intensity changes? The higher the order the more accurate your fit will be for the training points but the more off it will be for other colors and may go haywire if you're extrapolating colors outside your training range. For just simple intensity changes with no change in the "color temperature" or "CRI" of the lighting, and no change to the gamma of the camera, cross channel linear should be fine. But you should have more points than 3, which is what I think you're using. Your color correction is so extreme it's more like thresholding than applying a polynomial model. Maybe you don't need color correction at all but need color segmentation. See my color segmentation tutorials in my File Exchange. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 25 Jun. 2012
If an image is double, it expects it to be in the range 0-1. Try casting your RGB to uint8 before you pass it to imshow:
imshow(uint8(RGB));
  1 Kommentar
huseyin kara
huseyin kara am 25 Jun. 2012
you are my hero. thank a lot.
i am a second year student and i am trying to learn image processing and i am beginner in MATLAB. thank you again.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jan
Jan am 25 Jun. 2012
As long as I do not understand the problem, I can at least guess: You are mixing UINT8 values and DOUBLE class. Then the pixels values are scaled from 0 to 1 and every value greater than 1 is displayed as white.
  1 Kommentar
huseyin kara
huseyin kara am 25 Jun. 2012
C=double(D)*double(A); can this cause the problem you said ? and how can i fix it? by divided the corrected matrix to 255 can help me or not?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with Image Processing Toolbox 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!

Translated by