Nearest Neighbor interpolationでの画像のアップ・ダウンサンプリング
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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);
0 Kommentare
Antworten (1)
michio
am 11 Sep. 2017
Bearbeitet: michio
am 11 Sep. 2017
out(i,j,idx) = im(xloc,yloc,idx);
で xloc, yloc が 0 になったりしているのかなぁ、とプログラムをみてまず疑いました。デバッグ機能を使えば、実際にエラーが発生した時に、xloc, yloc, idx, i, j などの変数がどんな値になっているかを確認することができます。下記参考にしてみてください。
詳細は3つ目のページ内にある dbstop 関数へのリンク先で確認できますが、例えば、、
dbstop if error
など便利ですよ。
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!