实现放大/标记感兴趣区域(MATLAB)

这篇博客分享了一种在Matlab中通过自编程序实现图像处理的方法,具体为:找到图像中特定位置的子区域,用红色边框进行标记,并将该区域放大后置于图像左下角。代码中定义了`ShowEnlargedPatch`函数,该函数接受图像、坐标、窗口大小和放大倍数等参数,通过`imresize`函数进行放大,并利用`rectangle`函数绘制边框。最终,使用`getframe`和`frame2im`将结果显示并保存。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在图像处理中,常常会遇到这样一个问题:如何将图像中某一小块使用红色边框标记,然后再将其放大放置于左下角?之前在网上查找了很多关于此类方法的解决方法,但是都失败了。最后自己编写了一个小的程序来实现改功能。其代码如下:

Img = imread('Lena.png');
Local_Zoom = ShowEnlargedPatch(Img, 241, 426, 70, 70, 2, 2);
imwrite(Local_Zoom, '.../Results/Local_Zoom.tif');

子函数ShowEnlargedPatch():
function O_img = ShowEnlargedPatch(Img, Row, Col, WindowRow, WindowCol, LineWidth, Scale)
% 函数输入说明:
%  Row, Col:  感兴趣区域的左上角横纵坐标(在图像表现为行、列)
% WindowRow, WindowCol: 感兴趣区域大小
% LineWidth:  线的宽度
% Scale:  感兴趣区域放大的倍数
% 函数输出:
% O_img: 合成后的输出图像

[height width] = size(Img);
Patch(:,:) = Img(Row-LineWidth:Row+LineWidth+WindowRow, Col-LineWidth:Col+LineWidth+WindowCol);
Interpolation_Method = 'bicubic';   
Enlarged = imresize(Patch, Scale, Interpolation_Method);

[m n] = size(Enlarged);

EnlargedShowStartRow = height - LineWidth;
EnlargedShowStartCol = 1 + LineWidth;

Img(EnlargedShowStartRow - m + 1:EnlargedShowStartRow,EnlargedShowStartCol:EnlargedShowStartCol + n - 1) = Enlarged(:,:);

Point = [EnlargedShowStartCol EnlargedShowStartRow-m m n];
figure, imshow(Img, 'border', 'tight')
hold on;
rectangle('Position', [Col Row WindowCol WindowRow], 'LineWidth', 2, 'EdgeColor', 'r')
rectangle('Position', Point, 'LineWidth', 2, 'EdgeColor', 'r')

frame = getframe(gcf, [0 0 512 512]);
O_img = frame2im(frame);

result reference to link

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大江东去浪淘尽千古风流人物

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值