RGB color error
6 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Image Analyst
2012 年 6 月 25 日
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
採用された回答
Image Analyst
2012 年 6 月 25 日
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 件)
Jan
2012 年 6 月 25 日
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!