matlab中怎样在一幅图片中截一个圆出来?

请好心人帮忙,非常感谢
2024-12-04 20:19:38
推荐回答(1个)
回答(1):

function [ I J ] = getPartofJPG( )
% 读一幅图 并将鼠标点击处附近的区域截图。
% http://zhidao.baidu.com/question/143304956.html
% 2010-03-23

I=imread('1.jpg');
%figure(1);
%imshow(I);
%I1=0.3*I(:,:,1)+0.59*I(:,:,2)+0.11*I(:,:,3);
figure(2);
imshow(I);
k=waitforbuttonpress;
point= get(gca,'CurrentPoint') %mouse pressed
rectregion = rbbox
point= point(1,1:2)% extract col/row min and maxs
point_x=point(1)
point_y=point(2)
[xmax ymax zmax]=size(I);
J = I;
for i=1:xmax
for j=1:ymax
if(sqrt((j-point_x)^2+(i-point_y)^2)<43)%&(sqrt((j-point_x)^2+(i-point_y)^2)>40))
J(i,j,:)=I(i,j,:);
else
J(i,j,:)=0;
end
end
end
figure;
imshow(J);