Filter löschen
Filter löschen

Interpolating matrices of different sizes to the same size

29 Ansichten (letzte 30 Tage)
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 Kommentar
Swaminath VENKATESWARAN
Swaminath VENKATESWARAN am 7 Jul. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Sven
Sven am 4 Dez. 2012
Bearbeitet: Sven am 5 Dez. 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 Kommentare
Sven
Sven am 5 Dez. 2012
Hi Eliott, I've updated the answer with interp2 and no image processing toolbox.
wefoust
wefoust am 12 Dez. 2012
This works well! I originally started playing with the code, and gave up with interp2. I then used interp1, but the code was awfully slow (unusable for the large datasets I have). However, this is exactly what I need. Thanks for following up.
~Eliott

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by