?? ca6-submission.m
字號:
% detecting the ten circles from
% the given PNG image. You are also given a basketball image taken
% from NCAA - if you can detect the basketball from that image,
% you will earn one extra point
% Part 1: preprocessing the image
x=imread('coins.png');
imshow(x);
e=edge(x,'canny');
imshow(e);
c=bwareaopen(e,100);
figure;imshow(c);
% Part 2: apply circle detection to the binarized image
d=bwlabel(c);
z=zeros(size(c));
for k=1:max(max(d))
%{please explain what lines 31-33 do}
b=(d==k);
[i,j]=find(b==1); % This line gives the spatial co-ordinates of each object separated by the bwlabel command;
[R,mx,my,mse]=circle_detect(j,i); % This line uses the circle_detect function to determine the circle coordinates and the fitting error of each obbject passed to it;
% {please explain what lines 34-36 do}
if mse<0.1 % Some objects inside the circles have a big fitting error. Hence only the circles are taken by keeping this condition to remove the objects in the circles;
z=z+b; % Only when the fitting error < 0.1 , then the values are considered otherwise discarded;
end % Finally we get the circle images of the coins in the given image;
end
figure;
imshow(z);
% check your result
%y(:,:,1)=z*255;
%y(:,:,2)=(1-z).*double(x);
%y(:,:,3)=(1-z).*double(x);
%imshow(y/255);
% Part 3: Bonus part (1 extra credit point)
%Can you extract the basketball from the given image?
x=imread('ncaa.jpg');
figure;
imshow(x);
bg=rgb2gray(x);
e=edge(bg,'canny');
c=bwareaopen(e,100);
d=bwlabel(c);
b=(d==1);
[i,j]=find(b==1);
[R,mx,my,mse]=circle_detect(j,i);
figure;
imshow(b);
f(:,:,1)=b*255;
f(:,:,2)=(b).*double(x(:,:,2));
f(:,:,3)=(b).*double(x(:,:,3));
figure;
imshow(f/255);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -