Matlab里面根据鼠标的响应,截取rect区域图像,并且保存图像。
代码非常简单,里面没有做越界判断。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34clc; 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
最后
以上就是欣喜小丸子最近收集整理的关于MATLAB 标注 图像上截取Rect区域图像的全部内容,更多相关MATLAB内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复