Interpolating matrices of different sizes to the same size
29 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
wefoust
le 4 Déc 2012
Commenté : Swaminath VENKATESWARAN
le 7 Juil 2017
Hello, I apologize if this has been asked before, but my search has been futile so far. I am working with several models, and they all have different resolution. Therefore my data is in different size arrays. To continue with my analysis, I simply need the to be the same size. For example:
Model_1 is 60X128
Model_2 is 96X192
Model_3 is 145X192
etc.
Ideally, I would like each array to be 60X128. Although this seems simple, I am unable to come up with some "elegant" way of coding this. I apologize if this post is confusing, because I am still learning jargon of these methods. Any help will be greatly appreciated and thanks in advance.
~Eliott
1 commentaire
Swaminath VENKATESWARAN
le 7 Juil 2017
Hello,
Can you share the code for interp2? I have the following data and I am unable to fit them.
Model 1- Each Size of 1020x1
Model 2- Each Size of 1220x1
Model 3- Each Size of 1750x1
Thanks in advance.
Réponse acceptée
Sven
le 4 Déc 2012
Modifié(e) : Sven
le 5 Déc 2012
Hi Eliott,
Do you have the image processing toolbox? If so, this will be quite easy:
targetSize = [60 128];
Model_2_resized = imresize(Model_2, targetSize);
Model_3_resized = imresize(Model_3, targetSize);
If not, you can instead use interp2. It will let you resample the images at a given set of locations. Let me know if the above works or not, and I can help you out with the code for the interp2 command.
-----==== Answer edited below ====----
Hi Eliott, this code should resize a source image (ie, any X-by-Y matrix) to a target size. It's essentially what imresize() does:
targetSize = [60 128];
sourceIm = double(imread('rice.png')); % you can of course use your own source
sourceSize = size(sourceIm);
[X_samples,Y_samples] = meshgrid(linspace(1,sourceSize(2),targetSize(2)), linspace(1,sourceSize(1),targetSize(1)));
source_resized_to_target_size = interp2(sourceIm, X_samples, Y_samples);
figure, imagesc(sourceIm)
figure, imagesc(source_resized_to_target_size) % note the change in pixels
Did it work for you?
Thanks, Sven.
3 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Multirate Signal Processing dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!