How do I divide an image into blocks for processing?

I am new to MATLAB.
I am trying to write code which will divide the image in nonoverlaping blocks of size 3*3. I am supposed to do operations on specific blocks like getting the value of the center pixel of block and do some operations.
I don't know where to start. Using command like blockproc wont help. Can anyone suggest a start point?

5 件のコメント

Jiro Doke
Jiro Doke 2011 年 2 月 14 日
Why won't using "blockproc" help? That's exactly for doing what you proposed.
Brett Shoelson
Brett Shoelson 2011 年 2 月 14 日
What Jiro said.
David Young
David Young 2011 年 2 月 14 日
Agreed - blockproc should be the business.
Aparna RAJAWAT
Aparna RAJAWAT 2016 年 8 月 5 日
I want to divide an image into different block size.and image size is 16x16.block size are 4x4,5x5 and so on.please help me how to do coding in matlab
Image Analyst
Image Analyst 2016 年 8 月 5 日
Aparna, please see the FAQ

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

回答 (2 件)

Yaw
Yaw 2011 年 2 月 17 日

1 投票

The best way to do this is to use the "mat2cell" command. It's very simple.
  1. a=3; b=3; %window size
  2. x=size(f,1)/a; y=size(f,2)/b; %f is the original image
  3. m=a*ones(1,x); n=b*ones(1,y);
  4. I=mat2cell(f,m,n);

1 件のコメント

Walter Roberson
Walter Roberson 2011 年 2 月 17 日
blockproc() is able to handle situations where the original matrix does not happen to have dimensions that are multiples of 3. Your code will crash on those cases.

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

Vieniava
Vieniava 2011 年 2 月 14 日

0 投票

Suppose I is your image matrix. Trivial way is shown below:
s=size(I);
wing=1; % ;)
bs=2*wing+1; % block size
for i=wing: bs : (s(1)-wing)
for j=wing : bs : (s(2)-wing)
BLOCK=I( (i-wing):(i+wing) , (j-wing):(j+wing) );
%
% paste your function/code which processes the BLOCK
%
end
end

製品

質問済み:

2011 年 2 月 14 日

コメント済み:

2016 年 8 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by