IMAGE SEPARATION INTO BLOCKS

조회 수: 2 (최근 30일)
krithika P
krithika P 2011년 12월 16일
HI , i have an 256*256 image .. i want to separate it into blocks of 4*4 of that original image .. for that i tried with this code .
[img_x,img_y]=size(img); block_size=4; slide_len=1; n=1; for ix=block_size/2:slide_len:img_x-block_size/2 for jy=block_size/2:slide_len:img_y-block_size/2 current_block=img((ix-block_size/2+1):(ix+block_size/2),(jy-block_size/2+1):(jy+block_size/2));
end
end
but i could not get the full blocks also when i cheked with original image pixel values differs .. can i use this codes or any in built command can be used .. thanks to all in advance for reading this patiently
  댓글 수: 2
Muthuraj V
Muthuraj V 2011년 12월 16일
Hi you can use this command
c=mat2cell(a,[x y...],[x y...])
where in that x y .. should match with the no. of rows and columns,,,
chek for help in matlab, u wil get more detail
Regards,
Muthu.
krithika P
krithika P 2011년 12월 16일
i get like this when i use this command
Columns 1 through 9
[4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8]
[4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8]
[4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8]
[4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8]
[4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8]
[4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8]
[4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8]
[4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8] [4x4 uint8]

댓글을 달려면 로그인하십시오.

채택된 답변

Junaid
Junaid 2011년 12월 16일
Dear as in obove code division is n't correct .. follow this code
let say your image is I of 256 x 256. Make your your grid which is 4 x 4 this time should divide image dimensions.
if size(I,3)>1, I = rgb2gray(I); end % to make sure image is grayscale
I = imresize(I, [256 256]); % you can keep it the size you want but should be divisible by 4 x 4.
img_blocks = mat2cell(I,size(I,1)/4*ones(1,4), size(I,2)/4*ones(1,4));
Then you get img_blocks of size 4x4. For first block you can get
part1 = img_blocks{1,1};
  댓글 수: 6
krithika P
krithika P 2011년 12월 16일
thank you ..
Andrei Bobrov
Andrei Bobrov 2011년 12월 16일
s = [64 64];
S = size(I);
out = permute(reshape(I,s(1),S(1)/s(1),s(2),[]),[1 3 2 4]);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Supported Hardware에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by