在Matlab中在图像上绘制矩形

在Matlab中在图像上绘制矩形,matlab,Matlab,我正试图弄清楚如何在Matlab中在图像上绘制矩形 一旦矩形绘制在图像上,我想保存更改 提前谢谢 使用 有关绘制矩形的更多选项,请参见。矩形的'Position'参数的格式为[从x到y的宽度高度],以像素为单位。我使用的是倍频程,函数getframe不可用,所以我编写了这个简单的函数 %% Draw red rectangle IN the image using the BoundingBox from regionprops function rgbI = drawRectangleOnIm

我正试图弄清楚如何在Matlab中在图像上绘制矩形

一旦矩形绘制在图像上,我想保存更改

提前谢谢

使用


有关绘制矩形的更多选项,请参见。矩形的
'Position'
参数的格式为
[从x到y的宽度高度]
,以像素为单位。

我使用的是
倍频程
,函数
getframe
不可用,所以我编写了这个简单的函数

%% Draw red rectangle IN the image using the BoundingBox from regionprops
function rgbI = drawRectangleOnImg (box,rgbI)
    x = box(2); y = box(1); w = box(4); h = box(3);
    rgbI(x:x+w,y,1)   = 255;
    rgbI(x:x+w,y+h,1) = 255;
    rgbI(x,y:y+h,1)   = 255;
    rgbI(x+w,y:y+h,1) = 255;
    rgbI(x:x+w,y,2)   = 0;
    rgbI(x:x+w,y+h,2) = 0;
    rgbI(x,y:y+h,2)   = 0;
    rgbI(x+w,y:y+h,2) = 0;
    rgbI(x:x+w,y,3)   = 0;
    rgbI(x:x+w,y+h,3) = 0;
    rgbI(x,y:y+h,3)   = 0;
    rgbI(x+w,y:y+h,3) = 0;
end

不使用getframe:

im=imread('face.jpg'); %Image read
rectangle('Position', [10 10 30 30] ,...
    'EdgeColor', 'r',...
    'LineWidth', 3,...
    'LineStyle','-');%rectangle properties
imshow( im, rectangle); %draw rectangle on image.

有关更多详细信息,请访问:)

最简单的使用方法是更新的Matlab版本

img = imread('abcd.jpg');
box = [X1, Y1, width, height];    
outImage= insertObjectAnnotation(img,'rectangle',bbox,'Rectangle');
figure, imshow(outImage), title('Image with rectangle');

如果图像太大,不适合屏幕怎么办?有没有办法保持原始图像的分辨率?@ShmilTheCat我想你可以设置图形的属性
fh
设置(fh,'Position',[0 0大小(img,2),大小(img,1)]
im=imread('face.jpg'); %Image read
rectangle('Position', [10 10 30 30] ,...
    'EdgeColor', 'r',...
    'LineWidth', 3,...
    'LineStyle','-');%rectangle properties
imshow( im, rectangle); %draw rectangle on image.
img = imread('abcd.jpg');
box = [X1, Y1, width, height];    
outImage= insertObjectAnnotation(img,'rectangle',bbox,'Rectangle');
figure, imshow(outImage), title('Image with rectangle');