-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResistor_Colour_Code_Decoder.m
152 lines (127 loc) · 2.96 KB
/
Resistor_Colour_Code_Decoder.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
clc;
clear all;
Photo=''; %Resistor Image Path
RGB=imread(Photo);
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
Mask(i,t)=0;
else
Mask(i,t)=255;
end
end
end
figure, imshow(Mask)
for i=1:X
if RGB(Y,i)==0 && RGB(Y,i,2)==0 && RGB(Y,i,3)==0
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';
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';
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';
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';
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';
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';
end
end
j=1;
i1=0;
for i=1:X
if Temp(i,1)~=0
colorArray(1,j)=Temp(i,1);
j=j+1;
i1=i1+1;
end
end
i1=floor(i1/3);
i2=floor(i1*2);
i3=floor(i2+i1);
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));
colorArray(1,2)= colorArray(1,floor(j/3)+1);
colorArray(1,3)= colorArray(1,floor(j-2));
i=1;
for i=1:3
if colorArray(1,i)==65 %Black
colorArray(1,i)=0;
end
if colorArray(1,i)==66 %Brown
colorArray(1,i)=1;
end
if colorArray(1,i)==82 %Red
colorArray(1,i)=2;
end
if colorArray(1,i)==79 %Orange
colorArray(1,i)=3;
end
if colorArray(1,i)==89 %Yellow
colorArray(1,i)=4;
end
if colorArray(1,i)==71 %Green
colorArray(1,i)=5;
end
if colorArray(1,i)==68 %Blue
colorArray(1,i)=6;
end
if colorArray(1,i)==86 %Violet
colorArray(1,i)=7;
end
if colorArray(1,i)==72 %Grey
colorArray(1,i)=8;
end
if colorArray(1,i)==87 %White
colorArray(1,i)=9;
end
end
hundreds=power(10,colorArray(1,3));
tens=colorArray(1,1)*10;
ones=colorArray(1,2)*1;
resistorValue=(tens+ones)*hundreds;
if resistorValue>=1000 && resistorValue<1000000
resistorValue=resistorValue/1000;
fprintf('Resistor Value: %dk ohm',resistorValue);
elseif resistorValue>=1000000
resistorValue=resistorValue/1000000;
fprintf('Resistor Value: %dM ohm',resistorValue);
else
resistorValue=(tens+ones)*hundreds;
fprintf('Resistor Value: %d ohm',resistorValue);
end
figure, imshow(Photo);