这可能是一种“矫枉过正”,但您可以使用imwarp
功能:
imwarp
允许与位移(及以上)缩放。
假设:
(center_x, center_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);
输入图像(注意小十字):
输出图像:
它的工作原理很正确的,我我会尽力适应这种情况。非常感谢。 – gary105