How to implement sub-pixel linear interpolation in matlab?
16 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposta accettata
Christiaan
il 17 Giu 2015
Dear Sir,
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.
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
hold on
plot([0 length(x)-1], repmat(y,2,length(y))) % Horizontal gridlines
plot(x, L1) % Plot more lines here (additional ‘plot’ statements)
hold on
axis equal
hvix = [hrz; vrt]; % Concatanated ‘hrz’ and ‘vrt’ arrays
srtd = unique(hvix,'rows'); % Remove repeats and sort ascending by ‘x’
plot(srtd(:,1),srtd(:,2),'o');
Good luck! Christiaan
Più risposte (1)
Alex Taylor
il 18 Giu 2015
Out of curiosity, why not just use interp2 in MATLAB? Just pass in the image and the x,y query points and you are done.
0 Commenti
Vedere anche
Categorie
Scopri di più su Interpolation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!