How to implement sub-pixel linear interpolation in matlab?
7 ビュー (過去 30 日間)
The problem is quite clear, but I really don't know where to start.
Assuming this is a gray scale image, the black dot(not the rectangle) is the pixel. For example, x0 is a pixel, it has a x-y location (say (70, 82) ) and a gray value. And I have a direction value(say 135 degree) for pixel x0.
I want to do the linear interpolation along the direction from x0, the method is using the two nearest pixels' gray value. For example, I want to get x's value, the two nearest pixels around x is a and b.
I only want to interpolate pixels on the direction line, and either it's x-coordinate value or y-coordinate value is integer, like the red dots on this picture.
I think my function's input should be a gray scale image, start point x0's coordinate location, a direction value, and a range value to limit how many red dot's I want to get, and output should be the interpolated gray scale values for these red dots.
Thanks for your advices.
Christiaan 2015 年 6 月 17 日
What you could do is defining a starting point in a grid, then draw a line and find all intersections points. Once you have found your point you can use any 1D interpolater to find the corresponding grey points.
A small code that helps you on your way, modified from this question :
The code you can find below:
clc;clear all;close all;
x = 0:5; % X-range
y = 0:25; % Y-range
lxmb = @(x,mb) mb(1).*x + mb(2); % Line equation: y = m*x+b
m = 2.7; % Slope (or slope array)
b = 1; % Intercept (or intercept array)
mb = [m b]; % Matrix of [slope intercept] values
L1 = lxmb(x,mb); % Calculate Line #1 = y(x,m,b)
hix = @(y,mb) [(y-mb(2))./mb(1); y]; % Calculate horizontal intercepts
vix = @(x,mb) [x; lxmb(x,mb)]; % Calculate vertical intercepts
hrz = hix(x(2:end),mb)' % [X Y] Matrix of horizontal intercepts
vrt = vix(y(1:6),mb)' % [X Y] Matrix of vertical intercepts
figure(1) % Draw grids & plot lines
plot(repmat(x,2,length(x)), [0 length(y)-1]) % Vertical gridlines
plot([0 length(x)-1], repmat(y,2,length(y))) % Horizontal gridlines
plot(x, L1) % Plot more lines here (additional ‘plot’ statements)
hvix = [hrz; vrt]; % Concatanated ‘hrz’ and ‘vrt’ arrays
srtd = unique(hvix,'rows'); % Remove repeats and sort ascending by ‘x’
Good luck! Christiaan