MATLAB 标注 图像上截取Rect区域图像
2015-12-21 14:16
686 查看
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
代码非常简单,里面没有做越界判断。
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
相关文章推荐
- 解析在main函数之前调用函数以及对设计的作用详解
- java和matlab画多边形闭合折线图示例讲解
- C#调用Matlab生成的dll方法的详细说明
- 从java中调用matlab详细介绍
- 稀疏自动编码器 (Sparse Autoencoder)
- VC++与Matlab混合编程的快速实现
- Matlab 矩阵运算
- matlab与opencv部分函数的对照
- matlab神经网络工具箱创建神经网络
- Matlab
- MATLAB 入门教程
- matlab函数_连通区域
- MATLAB中函数模式和命令模式的区别
- MATLAB 添加自定义的模块到simulink库浏览器
- MATLAB for Mac使编辑器支持中文
- [转]matlab中plot用法
- 初学数模-MATLAB Quick Start! Part I
- 初学数模-MATLAB Quick Start! Part II
- matlab程序优化以及eclipse与github的结合
- matlab中的rand函数(用于产生随机数)