필터 지우기
필터 지우기

Interpolating matrices of different sizes to the same size

조회 수: 29 (최근 30일)
wefoust
wefoust 2012년 12월 4일
댓글: Swaminath VENKATESWARAN 2017년 7월 7일
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
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
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
Sven 2012년 12월 5일
Hi Eliott, I've updated the answer with interp2 and no image processing toolbox.
wefoust
wefoust 2012년 12월 12일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by