Using interp1 to resample an image, results in NaN values.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Thijs Knoop
le 15 Jan 2022
Commenté : Star Strider
le 15 Jan 2022
Hello all,
I've run into an issue with a assignment I am doing. For this assignment it states: "Now, use an interpolation method (in Matlab®, ‘interp1’) to interpolate, i.e. resample, the spectrum from its original sampling to the linearized k-space sampling." During my tries I have come up with the following:
A = 807.6660554599425;
B = 0.06950484773532092;
C = -7.056743126149048e-6;
D = -3.62624279344136e-11;
N = linspace(1, 1024, 1024);
lambda = A*N.^3 + B*N.^2 + C*N + D;
k_n = (2*pi)./lambda;
max = max(k_n);
min = min(k_n);
maxmin = linspace(max,min,1024);
F_resampled = interp1(raw_plak, maxmin);
F_k = fft(F_resampled);
F4 = log(abs(F_k));
Where A through D are device specific settings and 'raw_plak' is the original image given by:
raw_plak = im2double(imread('plakband.tif'));
When using the interp1 fuction returns an array full of NaN values. What am I doing wrong?
Sorry if this has been answered already, I have looked but could not find an answer to my problem.
With regards.
2 commentaires
Star Strider
le 15 Jan 2022
The assignment says to resample a spectrum. (To me, that implies a vector.)
Where does the image (a 2D or 3D array) enter into this?
Réponse acceptée
Image Analyst
le 15 Jan 2022
@Star Strider spectra can be 2-D. For example a diffraction pattern is a 2-D spectrum. You can get a spatial frequency spectrum from an image using fft2().
Because they say use interp1, that implies the input is 1-D. But since you say raw_plak is a 2-D image gotten from imread(), you'll need to use interp2() not interp1(). If that doesn't get rid of the nan's, then attach 'plakband.tif' in a .zip file along with your m-file with the paperclip icon.
Don't destroy the max and min values by overwriting the functions with values like you did here:
max = max(k_n);
min = min(k_n);
3 commentaires
Star Strider
le 15 Jan 2022
@Image Analyst — I am well aware of that!
However the initial problem was to use interp1 (that interpolates vectors) on an image that was not provided.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Multirate Signal Processing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!