如何在MATLAB中通过ROI放大图像

时间:2016-03-07 02:52:17

标签: matlab matlab-figure

我有两张照片。我想在特殊区域(ROI)看到更多细节。因此,我将绘制一个红色矩形并将其放大为原始大小(256 x 256),并在第二行显示为我的预期结果。你能帮我解决一下MATLAB吗?这是我目前的代码

 Img1 = imread('peppers.png');
 Img2 = imread('coins.png');
 Img1=imresize(Img1,[256 256]);
 Img2=imresize(Img2,[256 256]);
 %%Draw rectangle
 subplot(221);imshow(Img1); rectangle('Position',[100 50 20 20], 'LineWidth',2, 'EdgeColor','r');
 subplot(222);imshow(Img2);rectangle('Position',[100 50 20 20], 'LineWidth',2, 'EdgeColor','r');
 %% zoom in image

enter image description here

1 个答案:

答案 0 :(得分:1)

尝试此操作(当图像出现时,使用您的mouse选择感兴趣的区域):

 Img1 = imread('peppers.png');
 Img1=imresize(Img1,[256 256]);

 f=figure;
 imshow(Img1);
 rect = getrect(f); %//select roi with mouse
 Img1_roi = Img1( rect(2) : (rect(2)+rect(4)) , rect(1) : (rect(1)+rect(3)) , : ); %//store roi in matrix

 Img2 = imread('coins.png');
 Img2= imresize(Img2,[256 256]); 

 f=figure;
 imshow(Img2);
 rect = getrect(f); %//select roi with mouse
 Img2_roi = Img2( rect(2) : (rect(2)+rect(4)) , rect(1) : (rect(1)+rect(3)) , : );  %//store roi in matrix

 %//Plot
 subplot(2,2,1)
 imshow(Img1)
 subplot(2,2,2)
 imshow(Img2)
 subplot(2,2,3)
 imshow(Img1_roi)
 subplot(2,2,4)
 imshow(Img2_roi)