How can I convert the 8*8 matrix a to 4*4 matrix b using downsample

15 Ansichten (letzte 30 Tage)
downsample for raw and column and save the result in one matrix like b
for example:
a=
[1 2 8 5 4 7 5 9;
4 8 3 6 7 1 2 11;
7 8 2 1 7 7 7 9;
11 5 7 0 9 7 6 5;
7 8 9 6 0 0 8 7;
9 6 7 2 6 3 2 1;
1 1 2 4 5 8 9 6;
0 7 8 9 6 3 5 4]
b=
1 8 4 5
7 2 7 7
7 9 0 8
1 2 5 9

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 4 Mär. 2016
A(1:2:end,1:2:end)
  3 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 4 Mär. 2016
Bearbeitet: Azzi Abdelmalek am 4 Mär. 2016
a=[1 2 8 5 4 7 5 9;
4 8 3 6 7 1 2 11;
7 8 2 1 7 7 7 9;
11 5 7 0 9 7 6 5;
7 8 9 6 0 0 8 7;
9 6 7 2 6 3 2 1;
1 1 2 4 5 8 9 6;
0 7 8 9 6 3 5 4]
[n,m]=size(a);
a1=reshape(downsample(a,2),[],m)
out=reshape(downsample(a1',2),[],size(a1,1))'

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Guillaume
Guillaume am 4 Mär. 2016
Bearbeitet: Guillaume am 4 Mär. 2016
The two answers you've got are downsampling, using nearest neighbour interpolation.
More advanced ways of downsampling your matrix would be to use imresize, e.g.
imresize(a, 0.5, 'nearest') %nearest neighbour interpolation
imresize(a, 0.5, 'bilinear') %bilinear interpolation
imresize(a, 0.5, 'bicubic') %etc.
  1 Kommentar
Batool Engineer
Batool Engineer am 4 Mär. 2016
I want to write ' downsample ' instruction, e.g. b=downsample(a,2)
but in command window appear b =
1 2 8 5 4 7 5 9
7 8 2 1 7 7 7 9
7 8 9 6 0 0 8 7
1 1 2 4 5 8 9 6
but I want for columns also.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by