Nearest Neighbor interpolat​ionでの画像のアッ​プ・ダウンサンプリン​グ

5 ビュー (過去 30 日間)
Naoki Ishibashi
Naoki Ishibashi 2017 年 9 月 11 日
編集済み: michio 2017 年 9 月 11 日
Nearest Neighbor interpolationで画像のアップ・ダウンサンプリングを自分でやろうとしています。 いろいろなサイトを参考に書いているのですが、 エラーが出てしまい、何が原因かわからず困っております。 教えて頂けると幸いです。
function [out] = nearestneighbor(im, out_dims)
%// Get some necessary variables first
in_rows = size(im,1);
in_cols = size(im,2);
out_rows = out_dims(1);
out_cols = out_dims(2);
%// Now interpolate
%// Go through each channel for the case of colour
%// Create output image that is the same class as input
out = zeros(out_rows, out_cols, size(im, 3));
for idx=1:size(im,3)
for i=1:in_cols
for j=1:in_rows
xloc = round ((j * (out_rows+1)) / (in_rows+1));
yloc = round ((i * (out_cols+1)) / (in_cols+1));
out(i,j,idx) = im(xloc,yloc,idx);
end
end
end
end
以下エラー
添字インデックスは、実数の正の整数か、論理値のいずれかでなければなりません。
エラー: nearestneighbor (line 18)
out(i,j,idx) = im(xloc,yloc,idx);

回答 (1 件)

michio
michio 2017 年 9 月 11 日
編集済み: michio 2017 年 9 月 11 日
out(i,j,idx) = im(xloc,yloc,idx);
で xloc, yloc が 0 になったりしているのかなぁ、とプログラムをみてまず疑いました。デバッグ機能を使えば、実際にエラーが発生した時に、xloc, yloc, idx, i, j などの変数がどんな値になっているかを確認することができます。下記参考にしてみてください。
詳細は3つ目のページ内にある dbstop 関数へのリンク先で確認できますが、例えば、、
dbstop if error
など便利ですよ。

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!