Frage

I would need to resize a matrix (without interpolation) in Matlab into different resolution. The image below will highlight what I want:

enter image description here

Is there any built-in function for this in Matlab? If there isn't, what would be a good way to achieve this result?

Please let me know if my question isn't clear enough. Thank you for any help =)

War es hilfreich?

Lösung

A = [1 2; 3 4]; %// data
m = 3; %// row repetition factor
n = 3; %// column repetition factor
B = A(ceil(1/m:1/m:size(A,1)), ceil(1/n:1/n:size(A,1)))

Andere Tipps

there is a easy and fast way in form of the function kron()

>> kron( [1 2; 3 4], ones(1))
ans =
     1     2
     3     4
>> kron( [1 2; 3 4], ones(2))
ans =
     1     1     2     2
     1     1     2     2
     3     3     4     4
     3     3     4     4
>> kron( [1 2; 3 4], ones(3))
ans =
     1     1     1     2     2     2
     1     1     1     2     2     2
     1     1     1     2     2     2
     3     3     3     4     4     4
     3     3     3     4     4     4
     3     3     3     4     4     4

it is even possible to stretch/shrink dimensions

>> kron( [1 2; 3 4], ones(1,2))
ans =
     1     1     2     2
     3     3     4     4

If you have the image processing toolbox

the imresize function can be used to do this

Old=[1,2;3,4]; 
factor=2; % scale factor

New=imresize(Old,factor,'nearest')

New =

     1     1     2     2
     1     1     2     2
     3     3     4     4
     3     3     4     4
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top