Bilinear interpolation error - index exceeds matrix dimensions

I am supposed to do the bilinear interpolation without using imresize or interp. I am getting the error 'Index exceeds matrix dimensions' The padding was to avoid that.
{ f300=imread('Chrono');
fbilin(1:3:2769,1:3:2109)=f300(1:923,1:703);
f300=padarray(f300,[4 4],'replicate','both');
for j=1:3:2109
for i=1:3:2769
f11=f300(i,j+2);
f12=f300(i,j+2);
f21=f300(i+2,j);
f22=f300(i+2,j+2);
fbilin(i+1,j+1)=(f11*((i+2)-(i+1))*((j+2)-(j+1))+...
f21*((i+1)-(i))*((j+2)-(j+1))+...
f12*((i+2)-(i+1))*((j+1)-(j))+...
f22*((i+1)-(i))*((j+1)-(j)))./((i+2)-(i))*((j+2)-(j));
end
end
subplot(2,3,5), imagesc(fbilin), title('Chronometer Bilinear'); }

1 件のコメント

Image Analyst
Image Analyst 2013 年 1 月 25 日
Click edit (to the upper left). Put a blank line before your code. Then highlight all your code and click {}Code icon above to format your code properly.

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2013 年 1 月 25 日
編集済み: Matt J 2013 年 1 月 25 日

0 投票

Use DBSTOP to halt execution at the point where the error occurs. Check the values of the indices at that point. Also check the size of the (supposedly padded) arrays.

8 件のコメント

P
P 2013 年 1 月 25 日
error in line f21=f300(i+2,j); my padded matrix is of size 932x711.
Matt J
Matt J 2013 年 1 月 25 日
編集済み: Matt J 2013 年 1 月 25 日
If you have used "dbstop if error" you should have reached a K>> prompt. Enter the following at the K>> prompt and paste for us the exact output
K>> i,j, size(f300)
P
P 2013 年 1 月 25 日
K>> i,j,size(f300)
i =
931
j =
1
ans =
931 711
P
P 2013 年 1 月 25 日
if i swap my i and j in the sequence of the loop my dbstop result is K>> i,j,size(f300)
i =
1
j =
712
ans =
931 711
Matt J
Matt J 2013 年 1 月 25 日
編集済み: Matt J 2013 年 1 月 25 日
Well, it's now clear that your indices have run over too large a range, right? If size(f300,1)=931, then there's no way that i+2=933 can be used to index it. Similarly in your second case, j=712 is not a valid index into an array whose dimension is only 711.
P
P 2013 年 1 月 25 日
i agree. I just cannot figure out how to run this loop to get the image.
Matt J
Matt J 2013 年 1 月 25 日
編集済み: Matt J 2013 年 1 月 25 日
Well, one thing should be clear. If the size of the array is 931, you should probably not be running i up to 2769, and similarly for j. Where did these numbers come from anyway?
P
P 2013 年 1 月 26 日
編集済み: P 2013 年 1 月 26 日
you are right. instead of f300 it should be fbilin. Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

質問済み:

P
P
2013 年 1 月 25 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by