Click here to Skip to main content
15,883,872 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
currently i am working with project on colour detection of resistor using image processing.But i am unable to get the results for all images.Pleae help me.

What I have tried:

I have treid the following code....



clc;
close all;
clear all;
[fname path]=uigetfile('*.*','enter an image');
fname=strcat(path,fname);
RGB=imread(fname);
imshow(RGB);
matrixSize=size(RGB);
Y=matrixSize(1,1);
X=matrixSize(1,2);
x1 = Y;
Y=Y/2;
Y=round(Y);

for i=1:x1
for t=1:X
if RGB(i,t)<255
binary(i,t)=0;
else
binary(i,t)=255;
end
end
end
figure, imshow(binary)
for i=1:X
if RGB(Y,i)==0 && RGB(Y,i,2)==0 && RGB(Y,i,3)==0 %stores 65 for black
Temp(i,1)='A';
else
Temp(i,1)=0;
end
end

for i=1:X
if RGB(Y,i)>=185 && RGB(Y,i,2)>=122 && RGB(Y,i,3)<=87
Temp(i,1)='B'; %stores 66 for brown
end
end

for i=1:X
if RGB(Y,i)>=200 && RGB(Y,i,2)<=50 && RGB(Y,i,3)<=50
Temp(i,1)='R'; %stores 82 for red
end
end

for i=1:X
if RGB(Y,i)>=240 && RGB(Y,i,2)>=230 && RGB(Y,i,3)<=10
Temp(i,1)='Y'; %stores 89 for yellow
end
end

for i=1:X
if RGB(Y,i)<=140 && RGB(Y,i,2)<=140 && RGB(Y,i,3)>=200
Temp(i,1)='D'; %stores 68 for blue
end
end

for i=1:X
if RGB(Y,i)==163 && RGB(Y,i,2)==73 &&RGB(Y,i,3)==164
Temp(i,1)='V'; %stores 86 for violet
end
end

for i=1:X
if RGB(Y,i)==0 && RGB(Y,i,2)==255 &&RGB(Y,i,3)==0
Temp(i,1)='G'; %stores 72 for green
end
end

j=1;

for i=1:X
if Temp(i,1)~=0
colorArray(1,j)=Temp(i,1);
j=j+1;

end
end



colorArray(1,1)= colorArray(1,floor(j/6)); %for 1st band
colorArray(1,2)= colorArray(1,floor(j/3)+1); %for 2nd band
colorArray(1,3)= colorArray(1,floor(j-2)); %for 3rd band
i=1;
for i=1:3
if colorArray(1,i)==65 %black
colorArray(1,i)=0;
disp('black colour')
end

if colorArray(1,i)==66 %brown
colorArray(1,i)=1;
disp('brown colour')
end

if colorArray(1,i)==82 %red
colorArray(1,i)=2;
disp('red colour')
end

if colorArray(1,i)==79 %orange
colorArray(1,i)=3;
disp('orange colour')
end

if colorArray(1,i)==89 %yellow
colorArray(1,i)=4;
disp('yellow colour')
end

if colorArray(1,i)==71 %green
colorArray(1,i)=5;
disp('green colour')
end

if colorArray(1,i)==68 %blue
colorArray(1,i)=6;
disp('blue colour')
end

if colorArray(1,i)==86 %violet
colorArray(1,i)=7;
disp('violet colour')
end

if colorArray(1,i)==72 %grey
colorArray(1,i)=8;
disp('grey colour')
end

if colorArray(1,i)==87 %white
colorArray(1,i)=9;
disp('white colour')
end
end

hundreds=power(10,colorArray(1,3));
tens=colorArray(1,1)*10;
ones=colorArray(1,2)*1;

resistorValue=(tens+ones)*hundreds


figure, imshow(fname);
Posted
Comments
RedDk 22-Jul-18 14:06pm    
Someone posted a link somewhere to here:
https://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900