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

조회 수: 8 (최근 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 CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!