2017-03-02 36 views
0

我有圖像:如何放大圖像中的特定位置?

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] 

我明白「zoom on/off」允許一個通過按下鼠標按鍵交互縮放。然而,不是這種手動方法,有沒有一種方法可以通過編程的方式讓matlab縮放 - 比如這些位置的3x3 neighbourhood(或更多)?每當調用‘imshow’

我需要幫助/建議/建議。非常感謝預期。

回答

0

這可能是一種「矯枉過正」,但您可以使用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); 

輸入圖像(注意小十字):
enter image description here

輸出圖像:
enter image description here

+0

它的工作原理很正確的,我我會盡力適應這種情況。非常感謝。 – gary105

0

有一塊code它給你點你點的像素位置。可以有效地使用此代碼:

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 

有了這樣的像素位置,你可以創建一個指定尺寸的身材,讓說你雙擊像素位置image(x,y)。然後,你可以簡單地說figure('Position', [0 0 screenWidth screenHeight]), imshow(image(x-x1:x+x1, y-y1:y+y1))。確保x+-x1y+-y1在該範圍內。