Matlab 如何放大图像中的特定位置?
我有这样的形象:Matlab 如何放大图像中的特定位置?,matlab,image-processing,zooming,Matlab,Image Processing,Zooming,我有这样的形象: img = [1 1 1 3 3 3 3 3 3; 1 1 1 3 3 3 3 3 3; 1 1 1 3 3 3 3 3 3; 1 1 2 3 3 3 3 3 3; 1 1 2 2 2 2 2 1 1; 1 2 2 2 2 2 1 1 1; 1 2 2 2 2 1 1 1 1]; 假设我有兴趣在特定位置周围看到更精细的细节: Indx = [18; 47]; 坐标系: rows = [4;
img = [1 1 1 3 3 3 3 3 3;
1 1 1 3 3 3 3 3 3;
1 1 1 3 3 3 3 3 3;
1 1 2 3 3 3 3 3 3;
1 1 2 2 2 2 2 1 1;
1 2 2 2 2 2 1 1 1;
1 2 2 2 2 1 1 1 1];
假设我有兴趣在特定位置周围看到更精细的细节:
Indx = [18; 47];
坐标系:
rows = [4; 5] and cols = [3; 7]
据我所知,“缩放开/关”
允许用户通过按下鼠标按钮以交互方式缩放。然而,除了这种手动方法,是否有一种方法可以通过编程要求matlab放大这些位置(或更多位置)的3x3邻域
?无论何时调用“imshow”
请告诉我在这方面需要帮助/建议/建议。非常感谢您的期待。其中有一块可以为您提供单击点的像素位置。您可以有效地使用此代码:
function [loc] = get_image_point (I)
figure('name','Doubleclick to set location');imshow(I);
[c r] = getpts(1);
loc = int32([c r]);
if size(loc)>1
loc = [loc(1,1) loc(1,2)];
end
close all;
end
有了该像素位置,您可以创建具有指定尺寸的图形,比如您双击图像中的像素位置(x,y)
。然后,您可以简单地说figure('Position',[0屏幕宽度屏幕高度]),imshow(图像(x-x1:x+x1,y-y1:y+y1))
。确保x+-x1
和y+-y1
在范围内。这可能是一种“过度杀伤力”,但您可以使用以下功能:
imwarp
允许使用置换(以及更多)进行缩放
假设:
是您的兴趣点(中心x,中心y)
- 输出图像(缩放后)与输入图像大小相同
- 缩放后,关注点应位于图像的中心
我使用了
'peppers.png'
图像进行演示
以下是我的代码示例:
I = imread('peppers.png');
w = size(I, 2); %Image width
h = size(I, 1); %Image height
zoom = 4; %Zoom factor x4
%Point of interest.
center_x = w/2 - 80;
center_y = h/2 - 50;
%Draw center cross for testing (thickness is 2 pixels):
I(center_y-1:center_y, center_x-5:center_x+4, :) = 255;
I(center_y-5:center_y+4, center_x-1:center_x, :) = 255;
figure;imshow(I);
%Compute displacement:
x0 = w/2 - zoom*center_x;
y0 = h/2 - zoom*center_y;
%Build transformation matrix T.
T = [zoom 0 0; ...
0 zoom 0; ...
x0 y0 1];
tform = affine2d(T); %Needed by imwarp
%J = imwarp(I, tform, 'OutputView', imref2d(size(I)), 'Interp', 'nearest'); %Select nearest interpolation.
%Apply transformation (dimensions of J will be the same as I).
J = imwarp(I, tform, 'OutputView', imref2d(size(I)), 'Interp', 'cubic'); %Select cubic interpolation.
figure;imshow(J);
输入图像(注意小十字):输出图像:
它非常有效,我将尝试根据我的情况调整它。非常非常感谢。