[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Help with interpolation code
From: |
mantale1 |
Subject: |
Help with interpolation code |
Date: |
Tue, 26 Jun 2012 19:34:30 -0700 (PDT) |
Hi all,
I have some experience with MATLAB/Octave but I keep getting some
unexpected errors when I try to write a simple program that uses either
bilinear or nearest-neighbor interpolation. Here is the code:
function r = pv(im, x, y, method)
%get pixel value using interpolation
method = char(method);
[rows, cols] = size(im);
im = double(im);
H = rows;
W = cols;
if (x>=1) && (x<=W) && (y>=1) && (y<=H),
%point is in picture
if method == 'bilinear',
xd = floor(x);
xup = ceil(x);
yd = floor(y);
yup = ceil(y);
%pretend on unit square, construct mat with corner vals
Q = [im(yd,xd) im(yd,xup);...
im(yup,xd) im(yup,xup)];
r = [1 - mod(x,xd) mod(x,xd)] * Q * [1 - mod(y,yd); mod(y,yd)];
else %method == 'nearest',
r = im(round(y), round(x));
end
else %(x,y) not in image
r = 0;
end
When method is set to 'bilinear' the interpolation works fine, but when I
try to use 'nearest' I get an error saying:
mx_el_eq:nonconformant arguments (op1 is 1 x 7, op2 is 1 x8)
I honestly have no idea why I am getting this. Any ideas?
--
View this message in context:
http://octave.1599824.n4.nabble.com/Help-with-interpolation-code-tp4631009.html
Sent from the Octave - General mailing list archive at Nabble.com.
- Help with interpolation code,
mantale1 <=