<< Chapter < Page Chapter >> Page >

Processcropped.m

function [ x1,y1 ] = processCropped( category,fileName,saveName)% automate the process of feature extraction % Detailed explanation goes heredir = strcat(category,'/',fileName); I = getnewvector(dir,0, 0, 1601, 1601);[x1,y1,I] = getcenter(I);dir2 = strcat(category,'/',saveName); % save directoryimwrite(I,dir2,'bmp');end

Processcategory.m

function processCategory( category, numOfPics, saveAbrev ) % process the entire category% Detailed explanation goes here center = zeros(numOfPics,2);for n = 1:numOfPics, fileName = strcat(category,num2str(n),'.jpg');saveName = strcat(saveAbrev,num2str(n),'.bmp'); center(n,:) = processCropped( category,fileName,saveName);end csvwrite(strcat(category,'/','centers.dat'),center);end

Polarize.m

function [theta, r] = polarize(binaryMatrix, center)%POLARIZE Summary of this function goes here % Center: 1x2[m,n] = size(binaryMatrix);theta = zeros(500,1); r = zeros(500,1);numOfDots = 0; for i = 1:m, % for each rowfor j = 1:n, % for each column if (binaryMatrix(i,j) == 1),numOfDots = numOfDots + 1; dot = [i,j]- center; % find the relative coordinate with centroid [theta(numOfDots), r(numOfDots)]= cart2pol(dot(1),dot(2)); % convert into polarend endend end

Divideintobins.m

A dog sitting on a bed

Testdriver.m

clear all close alldir =char('down','up','okay','metal','point','stop','vulcan'); right=0;wrong=0; for n=1:7,traning1=csvread(strcat(dir(n,:),'/','features.dat'));[x y]=size(traning1); for k=1:x,training=traning1(k,:);type=classify(training,2,7,8);type1=mode(type);if type1==nright=right+1;else wrong=wrong+1;end endendsize(type) rightwrong % I1 = 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); % % %

Classify.m(part1)

A dog sitting on a bed

Classify.m(part2)

A dog sitting on a bed

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