用鼠标选取图像的感兴趣区域,matlab

%% 使用鼠标选定图片区域
clc
clear
I=imread('test.jpg');  
imshow(I);
k = waitforbuttonpress;              % 等待鼠标按下
point1 = get(gca,'CurrentPoint');    % 鼠标按下了
finalRect = rbbox;                   %
point2 = get(gca,'CurrentPoint');    % 鼠标松开了
point1 = point1(1,1:2);              % 提取出两个点
point2 = point2(1,1:2);
p1 = min(floor(point1),floor(point2));             % 计算位置
p2 = max(floor(point1),floor(point2));
offset = abs(floor(point1)-floor(point2));         % offset(1)表示宽,offset(2)表示高
x = [p1(1) p1(1)+offset(1) p1(1)+offset(1) p1(1) p1(1)];
y = [p1(2) p1(2) p1(2)+offset(2) p1(2)+offset(2) p1(2)];
hold on                              %防止plot时闪烁
plot(x,y,'r');

在这里插入图片描述

发布了56 篇原创文章 · 获赞 18 · 访问量 3481

猜你喜欢

转载自blog.csdn.net/kangjielearning/article/details/104865274
今日推荐