1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > matlab截取rect MATLAB 标注 图像上截取Rect区域图像

matlab截取rect MATLAB 标注 图像上截取Rect区域图像

时间:2021-12-15 13:10:58

相关推荐

matlab截取rect MATLAB 标注 图像上截取Rect区域图像

Matlab里面根据鼠标的响应,截取rect区域图像,并且保存图像。

代码非常简单,里面没有做越界判断。

clc;

clear;

% label and rect

Forder = [pwd '\images\'];

files = dir([Forder,'*.png']);

L = length(files);

num = 0; % 响应鼠标事件,文件夹里标注多少个rect_num

for i = 1 : L

I = imread([Forder files(i).name]);

[m,n,k] = size(I);

pro_img = I(1 : floor(m / 2),:,:);

imshow( pro_img );

while(1)

k = waitforbuttonpress; % 等待鼠标按下

point1 = get(gca,'CurrentPoint'); % 鼠标按下了

finalRect = rbbox; %

point2 = get(gca,'CurrentPoint'); % 鼠标松开了

point1 = point1(1,1:2); % 提取出两个点(按着鼠标不动,Rect的左上角与右下角点)

point2 = point2(1,1:2);

if point1(1) == point2(1) | point1(2) == point2(2)

break;

end %结束终止条件

img_rect = I(point1(2) : point2(2),point1(1) : point2(1),: );

img_rect_path = [pwd '\images_label\' num2str(num) '.bmp'];

imwrite(img_rect,img_rect_path);

num = num + 1;

hold on;

end

end

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。