WHAT'S THE ALGORITH APPROACH FOR THE BELOW CODE?
显示 更早的评论
clc;
clear all;
Photo='Resistor (1M).png'; %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);
2 个评论
What exactly are you asking? You just pasted in a load of (very ugly) code with no comment or question to go with it apart from the vague one in the title. It's useful to know where code comes from if you are expecting people to try to make sense of it and explain it. Arbitrary 3rd party code may be total junk that has no sense to it so it is a waste of time trying to make sense of it without having some kind of background as to where it comes from and what its supposed purpose is.
Guillaume
2018-7-10
Arbitrary 3rd party code may be total junk
Exhibit A in the question!
The code scans through the image no less than 8 times. One of these, in order to create a mask that is never used. There's more nonsense later on where things are repeated for no reason and calculations are performed and never used. And in the end the code takes into account the value of only 3 pixels.
Then, we have the nonsense that is X is the number of columns, but x1 (which used to be Y) the number of rows (and Y is now half the number of row). How can anybody keep track of what each variable represent is beyond me.
Not one of the loop is needed. The code is indeed complete junk and should be thrown away.
采纳的回答
更多回答(2 个)
vv_art
2018-7-10
0 个投票
3 个评论
Image Analyst
2018-7-10
The code may work for that pure computer graphics image but won't work in general. I agree with the others that the code was written by a complete amateur and you should run fast and far from it. There are other resistor postings here which may have better code (not sure) so you might search for them.
vv_art
2018-7-10
Guillaume
2018-7-10
It's unclear what you need help with here
类别
在 帮助中心 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!