Interpolating matrices of different sizes to the same size
19 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Swaminath VENKATESWARAN
2017 年 7 月 7 日
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.
採用された回答
Sven
2012 年 12 月 4 日
編集済み: Sven
2012 年 12 月 5 日
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 件のコメント
Sven
2012 年 12 月 5 日
Hi Eliott, I've updated the answer with interp2 and no image processing toolbox.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Multirate Signal Processing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!