I have used the coding below but it cannot read my rgb values. can someone helps me.
% Read in the Base Image
imgblue = imread('Blue.jpg');
blue = imcrop(imgblue,[60 72 580 300]);
figure, imshow(blue), title('Blue Image'), impixelinfo;
Rb = blue(:,:,1);
Gb = blue(:,:,2);
Bb = blue(:,:,3);
imggreen = imread('Green.jpg');
green = imcrop(imggreen,[60 72 580 300]);
figure, imshow(green), title('Green Image'), impixelinfo;
Rg = green(:,:,1);
Gg = green(:,:,2);
Bg = green(:,:,3);
imgyellow = imread('Yellow.jpg');
yellow = imcrop(imgyellow,[60 72 580 300]);
figure, imshow(yellow), title('Yellow Image'), impixelinfo;
Ry = yellow(:,:,1);
Gy = yellow(:,:,2);
By = yellow(:,:,3);
%figure, imshow(Ryellow), impixelinfo;
% Read in the Input Image
imgtest = imread('Test.jpg');
test = imcrop(imgtest,[60 72 580 300]);
figure, imshow(test), title('Test Image'), impixelinfo;
Rt = test(:,:,1);
Gt = test(:,:,2);
Bt = test(:,:,3);
if (Rt==Rb)&&(Gt==Gb)&&(Bt==Bb)
h = msgbox('The colour image is BLUE','Blue');
else if (Rt==Rg)&&(Gt==Gg)&&(Bt==Bg)
h = msgbox('The colour image is GREEN','Green');
else if (Rt==Ry)&&(Gt==Gy)&&(Bt==By)
h = msgbox('The colour image is YELLOW','Yellow');
else
h = msgbox('Operation Completed','Unknown');
end
end
end

댓글 수: 4

Image Analyst
Image Analyst 2017년 12월 10일
편집: Image Analyst 2017년 12월 10일
You forgot to attach any of your images. So I'll wait until tomorrow until I run/test your code. Because
imgblue = imread('Blue.jpg');
should read your values. If it can't, then your image is corrupted, but I can't tell because you didn't attach it.
Also, read this link and fix your code formatting.
Plus, you should not do this
if (Rt==Rb)&&(Gt==Gb)&&(Bt==Bb)
since those are images and each == will produce a binary image, and it doesn't make sense to do && with a binary image!
syafini alias
syafini alias 2017년 12월 14일
what command should i use then?
Image Analyst
Image Analyst 2017년 12월 14일
Exactly what does "cannot read my rgb values" mean? Does imread() work or does it throw an error?
syafini alias
syafini alias 2017년 12월 14일
when i run this coding this error displays in command window
Undefined operator '==' for input arguments of type 'cell'.
Error in test1 (line 45) if (Rt==Rb)&&(Gt==Gb)&&(Bt==Bb)

댓글을 달려면 로그인하십시오.

답변 (2개)

YT
YT 2017년 12월 14일
편집: YT 2017년 12월 14일

0 개 추천

While running your code, I got
Operands to the || and && operators must be convertible to logical scalar values
Replace '&&' by '&' in all these (else)if-statements worked for me using your example
& = array
&& = scalar

댓글 수: 1

syafini alias
syafini alias 2017년 12월 15일
i try to convert from && to & as you mentioned before but this error displays in command window
Undefined operator '==' for input arguments of type 'cell'.
Error in test1 (line 45) if (Rt==Rb)&(Gt==Gb)&(Bt==Bb)

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2017년 12월 14일

0 개 추천

Use isequal():
if isequal(Rt, Rb) && isequal(Gt, Gb) && isequal(Bt, Bb)
h = msgbox('The colour image is BLUE', 'Blue');
elseif isequal(Rt, Rg) && isequal(Gt, Gg) && isequal(Bt, Bg)
h = msgbox('The colour image is GREEN', 'Green');
elseif isequal(Rt, Ry) && isequal(Gt, Gy) && isequal(Bt, By)
h = msgbox('The colour image is YELLOW', 'Yellow');
else
h = msgbox('The colour is unknown','Unknown');
end

댓글 수: 2

syafini alias
syafini alias 2017년 12월 15일
i try to use the coding as you give but the msgbox only shows unknown even i insert value for RGB same as the yellow color. it suppose to be show yellow.
Image Analyst
Image Analyst 2017년 12월 15일
편집: Image Analyst 2017년 12월 15일
They're not exactly equal. The test image was red and the reference colors were cyan, yellow, and green.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

질문:

2017년 12월 10일

편집:

2017년 12월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by