this is my programme
[m n]=size(I);_(example image size is 256*256)_ c=mat2cell(I,[4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4],[4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4]); this is difficult and i want to sub divide the any image into (m/4)*(n/4) blocks.how can i do this easily?

댓글 수: 3

Jan
Jan 2013년 9월 10일
This does not look like a valid Matlab program. Please format the code properly and post valid Matlab syntax.
Image Analyst
Image Analyst 2013년 9월 12일
FYI: note the long arrays of 4's can be replaced by the shorter expression: 4*ones(1,m/4)
mahesh chathuranga
mahesh chathuranga 2013년 9월 13일
thank you

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

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 10일
편집: Azzi Abdelmalek 2013년 9월 10일

1 개 추천

im=rand(256);
[n,m]=size(im);
p=4
aa=1:p:n
bb=1:p:m
[ii,jj]=ndgrid(aa,bb)
out=arrayfun(@(x,y) im(x:x+p-1,y:y+p-1),ii,jj,'un',0)

댓글 수: 3

mahesh chathuranga
mahesh chathuranga 2013년 9월 10일
thank you very much
mahesh chathuranga
mahesh chathuranga 2013년 9월 12일
thank you very much. but sir i want to do this with mat2cellfunction
Jan
Jan 2013년 9월 12일
There is nothing magic in MAT2CELL. You can simply use a loop directly, see [EDITED] in my answer.

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

추가 답변 (2개)

Jan
Jan 2013년 9월 10일
편집: Jan 2013년 9월 12일

3 개 추천

Img = rand(768, 1024);
[m, n] = size(Img);
Blocks = permute(reshape(Img, [4, m/4, 4, n/4]), [1, 3, 2, 4]);
Now the block [x,y] can be accessed as
Block(:, :, x, y)
[EDITED] And to create a cell:
Img = rand(768, 1024);
[m, n] = size(Img);
m4 = m / 4;
n4 = n / 4;
Blocks = permute(reshape(Img, [4, m4, 4, n4]), [1, 3, 2, 4]);
C = cell(m4, n4)
for in = 1:n4
for im = 1:m4
C{im, in} = Blocks(:, :, im, in);
end
end

댓글 수: 3

Andrei Bobrov
Andrei Bobrov 2013년 9월 12일
편집: Andrei Bobrov 2013년 9월 12일
Hi Jan! Or:
C = reshape(num2cell(Blocks,[1 2]),m4,n4);
mahesh chathuranga
mahesh chathuranga 2013년 9월 13일
thanks
Alessandro Masullo
Alessandro Masullo 2018년 5월 30일

This is the smartest solution that I've ever seen.

It's just pure beauty. Fantastic, I love it!

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

Tejashree Ladhake
Tejashree Ladhake 2013년 11월 29일

0 개 추천

yes, it works! thank you

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by