dividing image into blocks and access them seperately

1 Ansicht (letzte 30 Tage)
Urmila
Urmila am 23 Feb. 2014
Bearbeitet: Tushar Das am 3 Mai 2021
I am diving image into 8x8 blocks
1) using loop
kk=0;
for i=1:(r/bs)
for j=1:(c/bs)
Block(:,:,kk+j)=Si((bs*(i-1)+1:bs*(i-1)+bs),(bs*(j-1)+1:bs*(j-1)+bs));
end
kk=kk+(r/bs)
end
2)using mat2cell
blocks = mat2cell(Si, 8 * ones(1,r/8), 8 * ones(1,c/8));
I want to read and access each block individually.how to do it.i am doing like this
blocks = mat2cell(Si, 8 * ones(1,r/8), 8 * ones(1,c/8));
a1=blocks{1,1};
a2=blocks{1,1};
:
:
aend=blocks{end,end};
But I want it in loop so that to reduce no of lines of code but how to do it then.kindly help me.

Akzeptierte Antwort

Jan
Jan am 23 Feb. 2014
Bearbeitet: Jan am 23 Feb. 2014
You have blocks{1,1}, blocks{1,2}, ... already. There is no better, nicer, more convenient or faster method. Hiding an index in the name of the variables is a bad idea and belongs to teh programming anti-patterns.
If you have a large number of blocks, keeping them in one numerical array might be more efficient:
blocks = respahe(Si, 8, r/8, 8, c/8);
blocks = permute(blocks, [1,3,2,4]);

Weitere Antworten (1)

Tushar Das
Tushar Das am 3 Mai 2021
Bearbeitet: Tushar Das am 3 Mai 2021
In the above metioned about block dividing in 8x8 . Can anyone suggest how to perform for 2x2 ? .

Community Treasure Hunt

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

Start Hunting!

Translated by