<< Chapter < Page Chapter >> Page >

Driver.m

clear all close allI1 = getnewvector('metal/metal3.JPG',800, 700, 1400, 800); I2 = getnewvector('metal/metal1.JPG',800, 700, 1400, 800);I3 = getnewvector('metal/metal2.JPG',800, 700, 1400, 800); I4=getnewvector('down1.JPG',800, 700, 1400, 800);I5=getnewvector('down2.JPG',800, 700, 1400, 800); I6=getnewvector('down3.JPG',800, 700, 1400, 800);% need to rescale all images here [x, y,I1]=getcenter(I1); [x1, y1,I2]=getcenter(I2); [x2, y2,I3]=getcenter(I3); [x3, y3,I4]=getcenter(I4); [x4,y4,I5]=getcenter(I5); [x5,y5,I6]=getcenter(I6); [theta1, r1]= polarize(I1, [x,y]);[theta2, r2] = polarize(I2, [x1,y1]); [theta3, r3]= polarize(I3, [x2,y2]);[theta4, r4] = polarize(I4, [x3,y3]); [theta5, r5]= polarize(I5, [x4,y4]);[theta6, r6] = polarize(I6, [x5,y5]); interval=pi/18;[ counter1, dividedData1 ] = divideIntoBins(theta1, r1, interval);[ counter2, dividedData2 ] = divideIntoBins(theta2, r2, interval);[ counter3, dividedData3 ] = divideIntoBins(theta3, r3, interval);[ counter4, dividedData4 ] = divideIntoBins(theta4, r4, interval);[ counter5, dividedData5 ] = divideIntoBins(theta5, r5, interval);[ counter6, dividedData6 ] = divideIntoBins(theta6, r6, interval);counter2 = counter2/(length(theta2)); counter3 = counter3/(length(theta3));counter1 = counter1/(length(theta1)); counter4 = counter4/(length(theta4));counter5 = counter5/(length(theta5)); % figure;% subplot(3,1,1); % plot(counter1);% subplot(3,1,2); % plot(counter2);% subplot(3,1,3); % plot(counter3);disp(norm(counter1-counter2,2)); disp(norm(counter1-counter3,2));disp(norm(counter1-counter4,2)); disp(norm(counter1-counter5,2));%n1=(norm(counter2,1)+norm(counter3,1))/2 %n2=(norm(counter4,1)+norm(counter5,1)+norm(counter6,1))/3% % % comparing within the same category% v1 = getnewvector('vulcan1.JPG'); % v2 = getnewvector('vulcan2.JPG');% v3 = getnewvector('vulcan3.JPG'); % d = zeros(3,1);% inner = zeros(3,1); % [d(1),inner(1)]= getdistance(v1,v2); % [d(2),inner(2)]= getdistance(v2,v3); % [d(3),inner(3)]= getdistance(v1,v3); % %

Getnewvector.m

function I=getnewvector(filename, XMIN, YMIN, WIDTH, HEIGHT) I=imread(filename);I=imcrop(I,[XMIN, YMIN, WIDTH, HEIGHT]); %cropI=rgb2gray(I); filter12=fspecial('gaussian',[20,20],20); %lowpass filter I=imfilter(I,filter12);% figure; % imshow(I);%I=imcontour(I,1); % magical contour algorithm %get rid of unconnected dots and get the largest connect part which is our handI=mean(double(I)/255,3)>0.5; [L,N]= bwlabel(I,4); s=zeros(1,N);for i=1:N, s(i)=sum(L(:)==i);end; [t,ind]=max(s); I=double(L==ind);% figure; % imshow(I);% filter12=fspecial('gaussian',[17,17],17);% I=imfilter(I,filter12); figure;imshow(I); % I = imresize(I,[1601 1601]); % I = im2bw(I,.6);end

Getcenter.m

% get the center of the contour image % output the center coordinate, and the edged imagefunction [x,y,Iout]=getcenter(I)[m, n]=size(I);a=sum(sum(I)); rowindex=zeros(a,1);colomnindex=zeros(a,1); number1=0;for i=1:m, for j=1:n,if I(i,j)==1 number1=number1+1;rowindex(number1,1)=i; colomnindex(number1,1)=j;end endend x=mean(rowindex);size(x); x=round(x);y=mean(colomnindex); y=round(y);Iout = edge(I,'canny'); end

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Elec 301 projects fall 2013. OpenStax CNX. Sep 14, 2014 Download for free at http://legacy.cnx.org/content/col11709/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Elec 301 projects fall 2013' conversation and receive update notifications?

Ask