Split RGB Image into blocks (24-bit)

3 ビュー (過去 30 日間)
Saud Alfalasi
Saud Alfalasi 2020 年 11 月 21 日
編集済み: Image Analyst 2020 年 11 月 22 日
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
Image Analyst 2020 年 11 月 21 日
Try blockproc(). I'm attaching some demos that you can adapt as needed.
  8 件のコメント
Saud Alfalasi
Saud Alfalasi 2020 年 11 月 21 日
%% open the image
I = imread('Original.jpg') ;
[n,m] = size(I) ;
%% split into 3 planes
redChannel = I(:, :, 1);
greenChannel = I(:, :, 2);
blueChannel = I(:, :, 3);
%% output functions (S should be a copy of the image, but in blocks)
funr = S(:,:,1);
fung = S(:,:,2);
funb = S(:,:,3);
blockSize = [64 64];
@(block_struct) (block_struct.data) * ones(size(block_struct.data));
%% blocks
blockyImageR = blockproc(redChannel, blockSize, funr)
blockyImageR = blockproc(redChannel, blockSize, fung)
blockyImageR = blockproc(redChannel, blockSize, funb)
Image Analyst
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
Rik 2020 年 11 月 21 日
The better solution would be to use blockproc, but you can also use mat2cell and use a loop.
  2 件のコメント
Saud Alfalasi
Saud Alfalasi 2020 年 11 月 21 日
Hi Rik, I actually want to use blockproc however I need to keep a track on the block position/ block number that I’m working on. On each block I will do some kind of operation. This will determine which block should be accessed next. I’m not necessarily going from block 1 to block2 to block3.... it might be block 1, block 17, block 28 ... following the principle of a knights tour (reference to a flag matrix with the number of blocks)
Rik
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.

サインインしてコメントする。

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by