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)))
Resizing a matrix into different resolution in Matlab
-
12-07-2023 - |
Pergunta
I would need to resize a matrix (without interpolation) in Matlab into different resolution. The image below will highlight what I want:
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 =)
Solução
Outras dicas
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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow