easily sub dividing image into blocks
古いコメントを表示
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
2013 年 9 月 10 日
This does not look like a valid Matlab program. Please format the code properly and post valid Matlab syntax.
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
2013 年 9 月 13 日
採用された回答
その他の回答 (2 件)
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
2013 年 9 月 12 日
編集済み: Andrei Bobrov
2013 年 9 月 12 日
Hi Jan! Or:
C = reshape(num2cell(Blocks,[1 2]),m4,n4);
mahesh chathuranga
2013 年 9 月 13 日
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
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!