当前位置:文档之家› Clab_2_report_u5715685

Clab_2_report_u5715685

Clab_2_report_u5715685
Clab_2_report_u5715685

A S S I G N M E N T C O V E R S H E E T

ANU College of Engineering and

Computer Science

Australian National University Canberra ACT 0200 Australia

https://www.doczj.com/doc/3316622563.html,.au

Submission and assessment is anonymous where appropriate and possible. Please do not write your name on this coversheet.

This coversheet must be attached to the front of your assessment when

submitted in hard copy. If you have elected to submit in hard copy rather than Turnitin, you must provide copies of all references included in the assessment item.

All assessment items submitted in hard copy are due at 5pm unless otherwise specified in the course outline. Student ID

For group assignments, list each student’s ID U5715685 Jinpeng CAI

Course Code ENGN6528 Course Name Computer Vision Assignment number Computer lab 2 report Assignment Topic

Lecturer Hongdong Li Tutor

Tutorial (day and time) Word count Due Date 3/04/16 Date Submitted

Extension Granted

I declare that this work:

?upholds the principles of academic integrity, as defined in the ANU Policy : Code of Practice for Student Academic Integrity ;

?is original, except where collaboration (for example group work) has been authorised in writing by the course convener in the course outline and/or Wattle site;

?is produced for the purposes of this assessment task and has not been submitted for assessment in any other context, except where authorised in writing by the course convener;

?gives appropriate acknowledgement of the ideas, scholarship and intellectual property of others insofar as these have been used;

?in no part involves copying, cheating, collusion, fabrication, plagiarism or recycling. Initials

For group

assignments, each student must initial.

Computer lab report 2

Task-1:

We test our harris function and compare the build in corner function for four test images.

As following:

Figure 1. My harris corner function compare to build in corner function for Lenna image

Figure 2. My harris corner function compare to build in corner function for mandm image

Figure 3. My harris corner function compare to build in corner function for pepper image

Figure 4. My harris corner function compare to build in corner function for Right image Task-2:

we get some codes from wattle and after analysis them, we fulfill several lines of codes in my_kmeans function. As following:

% - Set each cluster center to the average of the points assigned to it. % - Assign each point to the nearest cluster center

for m = 1: ndata

for n = 1: nc

distances(m,n) = norm(data(m,:) - cluster_stats(n,2:end));

end

% - Assign each point to the nearest cluster center

[~,b] = min(distances(m,:));

%update the membership assignment, i.e., update the data_clusters with current values.

data_clusters(m) = b;

end

Finally, we get the images filtered by k-means function:

Figure 5. Seven cluster image mandm and mandm original image

Figure 6. Edge image of cluster image

Figure 7. Seven cluster image mandm and mandm original image

Figure 8. Edge image of seven cluster image

Task-3:

Firstly, we resize the image and rotate them. We rotate image by -45, 45, 45. For detecting the feature points weather are same for the same rotation, we choose two same angles rotation. After that, we connect matches points by lines between two features.

Figure 9. Rotate image by -45 degree and draw the feature points

Figure 10. Rotate image by 45 degrees and draw the feature points

Figure 11. Rotate image by 45 degrees and draw the feature points

Figure 12. Draw lines between matching feature points Appendix:

Task-1:

close all;

clear all;

clc;

%% read image

im1=imread('Lenna.png');

%im1=imread('mandm.png');

%im1=imread('peppers.png');

%im1=imread('Right.jpg');

%% convert the rgb to gray

im1=rgb2gray(im1);

%% use our harris corner function to detect corner

[cim1, r1, c1] = harris(im1, 2, 1, 11, 0);

%% plot the image and draw the corner

subplot(1,2,1);

imshow(im1);

hold on;

p1=[c1, r1];

plot(p1(:,1), p1(:,2),'or');

title('\bf Harris Corners')

%% use the build in harris corner detector and plot the corner subplot(1,2,2);

build_corner1=corner(im1,'Harris');

imshow(im1);

hold on

plot(build_corner1(:,1), build_corner1(:,2), 'r*');

title('\bf Build Harris Corners')

Task-2:

close all;

clear all;

clc;

%% read image (we

img = im2uint8(imread('peppers.png'));

%img = im2uint8(imread('mandm.png'));

%% convert image to the La*b* colour space

cform = makecform('srgb2lab');

lab = applycform(img,cform);

%% Form 5 dimensional feature vector

image = im2double(lab);

source = im2feature(image);

%% Use my k-means to segment the image

[data_cluster,cluster_stats] = my_kmeans(source,7);

% Display cluster image

displayclusters(img,data_cluster);

function [data_clusters, cluster_stats] = my_kmeans( data, nc )

% This function performs k-means clustering on data , given (nc) = the number of clusters.

% Random Initialization

ndata = size(data,1);

ndims = size(data,2);

random_labels = floor(rand(ndata,1) * nc) + 1;

data_clusters = random_labels;

cluster_stats = zeros(nc,ndims+1);

distances = zeros(ndata,nc);

while(1)

% Make a copy of cluster statistics for

% comparison purposes. If the difference is very small, the while loop will exit.

last_clusters = cluster_stats;

% For each cluster

for c=1:nc

% Find all data points assigned to this cluster

[ind] = find(data_clusters == c);

num_assigned = size(ind,1);

% some heuristic codes for exception handling.

if( num_assigned < 1 )

disp('No points were assigned to this cluster, some special processing is given below');

% Calculate the maximum distances from each cluster

max_distances = max(distances);

[maxx,cluster_num] = max(max_distances);

[maxx,data_point] = max(distances(:,cluster_num));

data_clusters(data_point) = cluster_num;

ind = data_point;

num_assigned = 1;

end%% end of exception handling.

% Save number of points per cluster, plus the mean vectors.

cluster_stats(c,1) = num_assigned;

if( num_assigned > 1 )

summ = sum(data(ind,:));

cluster_stats(c,2:ndims+1) = summ / num_assigned;

else

cluster_stats(c,2:ndims+1) = data(ind,:);

end

end

% Exit criteria

diff = sum(abs(cluster_stats(:) - last_clusters(:)));

if( diff < 0.00001 )

break;

end

% - Set each cluster center to the average of the points assigned to it.

% - Assign each point to the nearest cluster center

for m = 1: ndata

for n = 1: nc

distances(m,n) = norm(data(m,:) - cluster_stats(n,2:end));

end

% - Assign each point to the nearest cluster center

[~,b] = min(distances(m,:));

%%update the membership assignment, i.e., update the

data_clusters with current values.

data_clusters(m) = b;

end

% Display clusters for the purpose of debugging.

% cluster_stats

%pause;

end

Task-3:

clear all;

close all;

clc;

%image read and convert the size

im = imread('face.JPG');

im = im2uint8(imresize(im,[512,512]));

%rotate the image

im1 = imrotate(im,-45);

im2 = imrotate(im,45);

im3 = imrotate(im,45);

imwrite(im1,'face1.jpg');

imwrite(im2,'face2.jpg');

imwrite(im3,'face3.jpg');

%use the sift function to computer their feature points

[image1,descriptors1,locs1] =sift('face1.jpg');

showkeys(image1,locs1);

[image2,descriptors2,locs2] = sift('face2.jpg');

showkeys(image2,locs2);

[image3,descriptors3,locs3] = sift('face3.jpg');

showkeys(image3,locs3);

size_b3 = size(descriptors3);

size_b1 = size(descriptors1);

%compute the closest distance between two sift descriptors and second %closest point

for i= 1:size_b1(1)

for j = 1:size_b3(1)

dis1(j,:) = descriptors3(j,:) - descriptors1(i,:);

end

dis2 = dis1.^2;

dis3 = sum(dis2,2);

dis = sqrt(dis3);

[min1,j1] = min(dis);

[min2,j2] = min([dis(1:j1-1,1); dis(j1+1:end,1)]);

%the cloeset point

if (min1/min2 < 0.6)

%choose less than 30 points

if i<30

%store information in vectim garage

garage(i,1)=j1;

garage(i,2)=min1;

garage(i,3)=min2;

garage(i,5)=locs1(i,1);

garage(i,6)=locs1(i,2);

garage(i,7)=locs3(j1,1);

garage(i,8)=locs3(j1,2);

else

%set the other points to zero

garage(i,:)=0;

end

else

%set the other points to zero

garage(i,:)=0;

end

end

%use appendimages to show face1 and face3 in the same image

im4 = appendimages(im1,im3);

figure();

imshow(im4);

title('SIFT point compare');

size_im1 = size(im1);

hold on

%draw the lines between two SIFT feature points

for i3 = 1:size_b1(1);

if(garage(i3,1) > 0)

line([garage(i3,5), garage(i3,7)+size_im1(2)],[garage(i3,6), garage(i3,8)], 'Color', 'c');

end

end

相关主题
相关文档 最新文档