2017-06-01 62 views
-1

目前我正在努力創建一個解決方案,以在MATLAB中使用interp1()調整圖像大小(顏色和灰度)。我到處尋找,但我發現的唯一解決方案是使用interp2(),這是我不能。我一直在嘗試和研究近3天,但沒有任何幫助。先謝謝你。MATLAB中的圖像插值涉及interp1

+1

爲什麼你不能_interp2_? –

+0

我知道使用interp2比較容易,但在這個問題中,我只能使用interp1。 –

+0

我一直在看這[帖子](https://stackoverflow.com/questions/6183155/resizing-an-image-in-matlab)並試圖引用它,但仍有錯誤或丟失。 –

回答

0

由於您嚴格使用interp1 ..您可以按照以下步驟操作。根據全局指標進行插值。

I = imread('peppers.png') ; 
[nx,ny,t] = size(I) ; 
%% 
dx = 4 ; dy = 4 ; % see to it that dx and dy are multiples of nx and ny 
%% Global indices 
idx = 1:nx*ny ; 
% for interpolation 
idxi = 1:dx:nx ; idyi = 1:dy:ny ; 
[I1,J1] = meshgrid(idxi,idyi) ; 
idxi = sub2ind([nx,ny],I1,J1)' ; 
%% 
nxi = nx/dx ; nyi = ny/dy ; 
I1 = zeros(nxi,nyi,t) ; 
%% 
for i = 1:t 
    C = I(:,:,i) ; 
    temp = interp1(idx,double(C(:)),idxi(:)) ; 
    I1(:,:,i) = reshape(temp,nxi,nyi) ; 
end 
I1 = uint8(I1) ; 
imshow(I1) 
size(I) 
size(I1) 
+0

非常感謝你@siva道具給你的男人:)我會研究這一點。 –

+0

如果我想增加圖像的大小,該怎麼辦? –

0

如果您反對插值,您可能跳過幾行和幾列。

I = imread('peppers.png') ; 
size(I) 
I1 = I(1:2:end,1:2:end,:) ; 
size(I1) 

而且也,你可以看看到imresize

I2 = imresize(I,[200 200]) ; 
+0

我必須在這個問題中使用interp1(),並且在這種情況下不能使用imresize()。提前致謝。 –