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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值