Split RGB Image into blocks (24-bit)
古いコメントを表示
Eg a 630x538 24-bit image
Would be 630x538x3.
How would I:
Chnage dimensions of image so that exactly divisible
Split into blocks of e.g 3x3x3 or 8x8x3 or 16x16x3
And then access each block in turn?
回答 (2 件)
Image Analyst
2020 年 11 月 21 日
0 投票
Try blockproc(). I'm attaching some demos that you can adapt as needed.
8 件のコメント
Saud Alfalasi
2020 年 11 月 21 日
Image Analyst
2020 年 11 月 21 日
I don't know why you need some arbitrary, random order to process the blocks in, but if you do, you'll just have to store the block coordinates in an coordinates array [row1, row2, col1, col2] and then get each block by extracting the region from that array:
% Go down every row of coords getting the coordinates of the rectangle to process.
for row = 1 : size(coords, 1)
row1 = coords(row, 1);
row2 = coords(row, 2);
col1 = coords(row, 3);
col2 = coords(row, 4);
subImage = originalImage(row1:row2, col1:col2, :);
% Now do something with this subImage
end
Saud Alfalasi
2020 年 11 月 21 日
Saud Alfalasi
2020 年 11 月 21 日
Image Analyst
2020 年 11 月 21 日
Yep, my code should work for that. Is there any reason why you cannot put the starting and ending rows and columns of your blocks into an N-by-4 array like that?
Saud Alfalasi
2020 年 11 月 21 日
Saud Alfalasi
2020 年 11 月 21 日
Image Analyst
2020 年 11 月 22 日
編集済み: Image Analyst
2020 年 11 月 22 日
If you don't want to scan and process your image in the normal raster-scan style of blockproc(), then exactly what order to you want to do it in? Again, why can't you make up that list of coordinates in advance? Even if the upper left of the block was some kind of knights tour, you could do it. Surely you must know the route or a recipe for building it. If you don't, then what's wrong with a raster scan?
I don't do private consulting via email. I don't have the time and no one could afford me.
Rik
2020 年 11 月 21 日
0 投票
The better solution would be to use blockproc, but you can also use mat2cell and use a loop.
2 件のコメント
Saud Alfalasi
2020 年 11 月 21 日
Rik
2020 年 11 月 21 日
If you want a specific order (i.e. the blocks don't have an independent outcome) you can't use blockproc. Otherwise I don't see why splitting into cells will not suit your needs.
カテゴリ
ヘルプ センター および File Exchange で Neighborhood and Block Processing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!