jjepsuomi
jjepsuomi

Reputation: 4373

Resizing a matrix into different resolution in Matlab

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 =)

Upvotes: 1

Views: 1041

Answers (3)

Luis Mendo
Luis Mendo

Reputation: 112679

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)))

Upvotes: 5

ben
ben

Reputation: 1390

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

Upvotes: 5

RTL
RTL

Reputation: 3587

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

Upvotes: 3

Related Questions