انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
اجرانشدن کد

اجرانشدن کد

#3
کد:
clear all
% Initializing variables
candidate=0;
J=500;
I=650;
T_short=10;
T_long=50;
H=210;
L=60;
window=8;
m1=J/window;
m2=I/window;





for count=1:10
pause
count
str = strcat('C:\Program Files\MATLAB\R2012a\bin\pelaks\car',int2str(count),'.bmp');
eval('C=imread(str);');



% Make a gray image
%C=rgb2gray(C);

% imshow(C);
% Make a standard
C=imresize(C,[J I]);
% C=C(.1*J_old+1:.9*J_old,:);
% J=.8*J_old;

m1=fix(J/window);
m2=fix(m2);
% H=C;
F=C;

% Enhancing the image
for n=0:window-1
for m=0:window-1
D=C(m1*n+1:(m1*(n+1)),m2*m+1:(m2*(m+1)));

I_bar=mean(mean(D));
sigma=var(var(double(D)));

for i=m2*m+1:m2*(m+1)
for j=m1*n+1:m1*(n+1)
I_prime(j,i)=f(sigma)*(double(C(j,i))-I_bar)+I_bar;
end
end

end
end
I_prime=imresize(I_prime,[J,I]);
% Edge detection
BW = edge(I_prime,'sobel','vertical');
% figure, imshow(BW);
% w=[1 0 -1;1 0 -1;1 0 -1]; %prewit khoooob
% DDD=uint8(I_prime);
% SSS=im2bw(DDD,graythresh(DDD));
% BW=imfilter(SSS,w);
% figure,imshow(BW)
E=BW;
M=zeros(J,I);
N=zeros(J,I);

% Regeneration 'E'
for j=3:J-2
for i=3:I-2
if E(j,i)==1
if (E(j-1,i-1)+E(j-1,i)+E(j-1,i+1)+E(j,i-1))>0
M(j,i)=max1(M(j-1,i-1),M(j-1,i),M(j-1,i+1),M(j,i-1))+1;
else
M(j,i)=max1(M(j-2,i-1),M(j-2,i),M(j-2,i+1),M(j-1,i-2),M(j-1,i+2),M(j,i-2))+1;
end
end
end
end

for j=J-2:-1:3
for i=I-2:-1:3
if E(j,i)==1
if (E(j+1,i-1)+E(j+1,i)+E(j+1,i+1)+E(j,i+1))>0
N(j,i)=max1(N(j+1,i-1),N(j+1,i),N(j+1,i+1),N(j,i+1)+1);
else
N(j,i)=max1(N(j+2,i-1),N(j+2,i),N(j+2,i+1),N(j+1,i-2),N(j+1,i+2),N(j,i+2))+1;
end
end
end
end

for j=1:J
for i=1:I
if E(j,i)==1
if ( (M(j,i)+N(j,i))> T_long || (M(j,i)+N(j,i))< T_short )
E(j,i)=0;
end
end
end
end

% figure,imshow(E)
B=E;
% Finding candidate row
if candidate>=1
B=X;
end

if candidate>5
break;
end

s=sum(B');

for i=1:floor(J/L)
S(i)=sum(s( (i-1)*L+1:i*L ));
end

[q1 q2]=max(S);

for tt=1:20
if (q2-2)*L<=0 | (q2+1)*L>J
S(q2)=0;
[q1 q2]=max(S);
else
break;
end

end

ROW=s((q2-2)*L:(q2+1)*L);
% imshow(B((q2-1)*L:(q2+2)*L,:));
[ad r]=max(ROW);
uper_pointer=r-1;
lower_pointer=r+1;

for i=1:L-1

if uper_pointer<=T_short
uper_pointer=1;
lower_pointer=L+3;
break;
end

if lower_pointer>=3*L+2-T_short
lower_pointer=3*L+1;
uper_pointer=2*L-1;
break;
end

t1=sum(ROW(uper_pointer-T_short:uper_pointer));
t2=sum(ROW(lower_pointer:lower_pointer+T_short));

if t1>=t2
uper_pointer=uper_pointer-1;
else
lower_pointer=lower_pointer+1;
end
end

% imshow(C((q2-2)*L+uper_pointer+1-10:(q2-2)*L+lower_pointer-1,:))

% Crop the image
AM=(C((q2-2)*L+uper_pointer+1:(q2-2)*L+lower_pointer-1,:));
D=B((q2-2)*L+uper_pointer+1:(q2-2)*L+lower_pointer-1,:);
% figure,imshow(D);

% Horizontal and vertical dilation
SE = strel('rectangle', [5 10]);
D1 = imdilate(D,SE);
% figure,imshow(D);
SE = strel('rectangle', [10 4]);
D2 = imdilate(D1,SE);
% figure,imshow(D);
SE = strel('rectangle', [3 10]);
D = imdilate(D2,SE);
% figure,imshow(D);

% filing the holes (not necessary)
BW2 = imfill(D,'holes');
% figure,imshow(BW2);

% Finding the best candidate
[ad1 ad2]=size(BW2);
fd=1;
for i=1:ad2-1
if (BW2(L/2,i+1)==1 & BW2(L/2,i)==0) | (BW2(L/2,i+1)==0 & BW2(L/2,i)==1)
dist(fd)=i;
fd=fd+1;
end
end

for i=1:fd-2
ss(i)=dist(i+1)-dist(i);
end


for i=1:2*T_long+1
[C1 I1]=max(ss);
if BW2(L/2,dist(I1))==0 & BW2(L/2,dist(I1+1))==1
break;
else
ss(I1)=0;
end
end

% Show the first candidate 121 230
if (dist(I1+1)-dist(I1))< 150 | (dist(I1+1)-dist(I1))> 300
candidate=candidate+1;
number_of_samples=3;
B((q2-2)*L+uper_pointer+1:(q2-2)*L+lower_pointer-1,:)=0;
X=B;
continue;
else
figure,imshow(AM(:,dist(I1):dist(I1+1)));
%figure,imshow(C)
break;
end
clear M N

end





این همون کده فقط برای اجراش چندتاکددیگه هست که بایدازاوناهم استفاده کرد.مشکل من اینه که عکسااز6به بعدارور میده بعداینکه خروجی رونشون نمیده کسی هست راهنماییم کنه؟؟؟؟؟

 
پاسخ


پیام‌های این موضوع
اجرانشدن کد - توسط سما - ۱۳۹۳/۰۴/۰۸, ۱۰:۵۸ ب.ظ
RE: اجرانشدن کد - توسط 4i469x - ۱۳۹۳/۰۴/۰۹, ۰۲:۳۹ ق.ظ
RE: اجرانشدن کد - توسط سما - ۱۳۹۳/۰۴/۰۹, ۱۲:۴۶ ب.ظ
RE: اجرانشدن کد - توسط 4i469x - ۱۳۹۳/۰۴/۰۹, ۰۳:۱۵ ب.ظ
RE: اجرانشدن کد - توسط سما - ۱۳۹۳/۰۴/۰۹, ۱۱:۰۶ ب.ظ
RE: اجرانشدن کد - توسط سما - ۱۳۹۳/۰۴/۱۱, ۱۰:۱۸ ب.ظ

پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان