- Home
- Search
- Contributors
- Recent Activity
- Flagged Content
- Log in to ask and answer questions.
- Ask a Question
- About MATLAB Answers

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
Asked by Algorithms Analyst on 29 Jan 2013

Hi all

I am working on some algorithm to implement it and in one stage I have been confused.Lets say that I have an image 512x512.

I want to make image partitioned in nxn squarre like regions that are overlapped with the same gap g for both image.So n=12 and g=3.

Thanks in Advance

*No products are associated with this question.*

Answer by Image Analyst on 29 Jan 2013

Accepted answer

Use blockproc() with the BorderSize option.

Show 29 older comments

Algorithms Analyst on 3 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_126808

Thanks for your response but how can I overlapped them with gap g as i used

I=blockproc(image,[8 8],'std2(image)*ones(size(image))')

Image Analyst on 3 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_126829

I don't see 12, g, or BorderSize specified in your equation. Make sure you send those in.

Algorithms Analyst on 4 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_126919

According to paper on local kernel color histogram by ( http://philippe.noriega.free.fr/fichiers/visapp06.pdf)

The first step is to partition an image like nxn square regions with same gap g where n=12 and g=3 so I did it like that but i am not sure is this correct

clc

close all

clear all source='lab.AVI';

vidinput=videoreader(source); frames=vidinput.NumberofFrames; for f=1:frames thisframe=read(vidinput,f); figure(1);imshow(thisframe); % Local kernel Color Histograms Implementation % First step is to partitioned image in to nxn square like regions which is % overlapped with same gap g =3 and n=12 thisframe=rgb2gray(thisframe); thisframe=double(thisframe); [M N Colors]=size(thisframe); fun=mean2(thisframe)*ones(size(thisframe)); thisframe=blkproc(thisframe,[12 12],[3 3],'std2(thisframe)*ones(size(thisframe))'); figure(2);imshow(uint8(thisframe));

end

Image Analyst on 4 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127000

I don't know if I still have the obsolete function blkproc. I do have blockproc, and in that I believe you have to pass in the bordersize as a name,value pair, like 'BorderSize', [3 3].

Algorithms Analyst on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127154

yes as you told I have passed these values like that

image=imread('lena.bmp');

fun=@(block_struct) std2(block_struct.data)*ones(size(block_struct.data))

B=blockproc(image,[12 12],fun,'BorderSize',[3 3])

Now where is overlapping region?As I intended to segment image into to overlapped local squares of size nxn where n =12 and gap g=3.

Walter Roberson on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127155

fun = @(block_struct) {block_struct.data}; B = blockproc(image,[6 6],fun,'BorderSize',[3 3]);

Now B should be a cell array, with each cell being an array 12 x 12 of pixels including the overlap.

Algorithms Analyst on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127170

Good response but getting another crucial error when I compile it

image=imread('lena.bmp');

fun=@(block_struct) {block_struct.data};

B=blockproc(image,[6 6],fun,'BordeerSize',[3 3]);

>> fun=@(block_struct) {block_struct.data}; >> B=blockproc(image,[6 6],fun,'BorderSize',[3 3]) ??? Error using ==> zeros Trailing string input must be a valid numeric class name.

Error in ==> blockprocInMemory at 122 b = zeros(final_size,class(ul_output));

Error in ==> blockproc at 248 result_image = blockprocInMemory(a,block_size,fun,border_size,...

Trailing input strings must be a valid class name?where is problem image class is double.I changes it logical(image) but still the same..

Walter Roberson on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127174

fun = @(block_struct) block_struct.data; T = blockproc(image,[6 6],fun,'BorderSize',[3 3]); B = mat2cell( T, 12 * ones(1, size(T,1)/12), 12 * ones(1, size(T,2)/12 );

Algorithms Analyst on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127179

Good but another error arrised

fun = @(block_struct) block_struct.data;

T = blockproc(image,[6 6],fun,'BorderSize',[3 3]);

B = mat2cell( T, 12 * ones(1, size(T,1)/12), 12 * ones(1, size(T,2)/12 );

Number of input vector arguments, 2, does not match the input matrix's number of dimensions, 3.

May be this is because of the sizes because size(T) is 512x512x3 but size(12*ones(1,size(T,1)/12)) is 1x42 I replicate it but not get solution..

Walter Roberson on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127182

Ummm right.

B = mat2cell( T, 12 * ones(1, size(T,1)/12), 12 * ones(1, size(T,2)/12), 3 );

(I had also missed a ')' earlier)

Algorithms Analyst on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127186

Yes another error arises in their sizes as I told earlier

size(T) is 512x512x3

and

size(12*ones(1,size(T,1))/12) is 1x42

therefore I am getting another error

Input arguments, D1 through D3, must sum to each dimension of the input matrix size, [512 512 3]. How solve this issue?Thank u very much

Walter Roberson on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127188

Please re-check size(T) against size(image). They should not be the same.

You put a ')' after ones(1,size(T,1) and before '/12' but it should not be there. Like I corrected above,

B = mat2cell( T, 12 * ones(1, size(T,1)/12), 12 * ones(1, size(T,2)/12), 3 );

Notice the divisions are inside the ones() calls.

12 * ones(1, size(T,1)/12) is another way of expressing repmat(12, 1, size(T,1)/12)

Algorithms Analyst on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127191

Yes size(T) and size(image) both are same as 512x512x3 in color case and 512x512 in grayscale.As my code below is

image=imread('lena.bmp');|%size(image) 512x512x3

fun=@(block_struct) block_struct.data

T=blockproc(image,[6 6],fun,'BorderSize',[3 3]);%size(T) 512x512x3

B = mat2cell( T, 12 * ones(1, size(T,1)/12), 12 * ones(1, size(T,2)/12), 3);

The error is the same.

Walter Roberson on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127193

You did not mention the warning,

Warning: Size vector should be a row vector with integer elements.

Unfortunately I do not have Image Processing Toolbox so I cannot experiment with blockproc().

Out of curiosity, what do you get if you use

blockproc(image, [6 6], @(block_struct) length(block_struct.data), 'BorderSize', [3 3])

It should be an array of constant values, but is it 6's or 12's ?

Walter Roberson on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127194

Ah...

T = blockproc(image,[6 6],fun,'BorderSize',[3 3], 'TrimBorder', 'false');

Okay, now we still have a problem: your 512 x 512 x 3 image is not evenly divisible into 12 x 12 with overlap of 3. 12 is divisible by 3, the overlap is divisible by 3, so (as a first-pass calculation) if the image size is not divisible by 3 then you are not going to be able to divide it exactly. What do you want to have happen with the bit that is necessarily left over? See the 'PadPartialBlocks' blockproc() option.

Algorithms Analyst on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127197

Yes exactly this is what I was thinking about it.Actually I am implementing the algorithm stated in the link

( http://philippe.noriega.free.fr/fichiers/visapp06.pdf)

I am on Image partitioning part which says about it. Please read it for any confusion only image partitioning part on page no 2.

The only solution i am thinking it is to divide it by 8x8 as 512/8 gives even number.But i need to work on overalpping region cannot find overlapping block in cell array as you stated.

Thanks you for concern..

Walter Roberson on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127199

What happens if you use TrimBorder false? What size does T come out as?

Walter Roberson on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127200

Would the later results be thrown off if you used the replicate pad option?

Algorithms Analyst on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127201

As stated in paper that

'The image is partitioned in nxn square like regions that are overlapped with the same gap g for both the image axis coordinates.So excluding the image edges,a pixel belongs to N=(n/g).^2 regions' where n=12 and g=3

Walter Roberson on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127202

Right, I read that much earlier. But mechanically, what happens when you use TrimBorder false ? Without being concerned about the partial blocks right at the moment.

Algorithms Analyst on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127204

Yes I used it but getting error as below.

??? Error using ==> blockproc>checkTrimBorder at 999 Invalid "TrimBorder" parameter. BLOCKPROC expects the TrimBorder parameter to a logical scalar.

Error in ==> blockproc>parse_inputs at 916 validateFcn(param_value);

Error in ==> blockproc at 215 input_args = parse_inputs(input_args,Input,block_size,fun,varargin{:});

Algorithms Analyst on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127206

And yes you can remove the previous results.Thanks....

Algorithms Analyst on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127208

may be the author has skipped some information about image partitioning for summarizing purpose..

Walter Roberson on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127209

T = blockproc(image,[6 6],fun,'BorderSize',[3 3], 'TrimBorder', false);

Algorithms Analyst on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127211

Ah.The size of T is now size(T)=1028x1028x3.

Algorithms Analyst on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127222

now where is overlapping region?

Image Analyst on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127225

It moves over by 6 pixels, but it takes an extra 3 pixels on each side when it gets the block of pixels, so it takes a width of 3+6+3 = 12. The window width is thus 12 but it only moves over by 6 each time, so there is an overlap of 6 (=12-6) pixels each time.

Algorithms Analyst on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127249

Thanks for your response.So Can I only show the overlap region?

Image Analyst on 5 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127261

Sure, if you want. Have blockproc() call a custom routine that you wrote. In there you have the whole 12x12 block. If you want, you could blacken the central 6x6 chunk of the block so that it is a square annulus. Then use imshow() to display that annulus. I have no idea why you'd want to do this though.

Algorithms Analyst on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127430

thankyou very much.....just for my exploration I want it...thanks alot..

Walter Roberson on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127445

The 1028 is due to there being partial block 2 pixels wide. mod(512,6) = 2. That block gets extended by the overlap, 3 pixels before and 3 after, to become a total of 8 pixel. 85 full blocks of 12, plus the partial 8, gives 1028. The 85 is floor(512/6). You need to take this partial block into account unless you request padding of the blocks out to full width.

Algorithms Analyst on 6 Feb 2013

Link

**Direct link to this comment:**

http://www.mathworks.com/matlabcentral/answers/60198#comment_127536

I am not clear in that point kindly explain it plz with some piece of code.Thanks.I further quantize the colors by using the K-means algorithm with K=16 as described in paper..

- © 1994-2014 The MathWorks, Inc.
- Site Help
- Patents
- Trademarks
- Privacy Policy
- Preventing Piracy
- Terms of Use
- RSS
- Google+

- Featured MathWorks.com Topics:
- New Products
- Support
- Documentation
- Training
- Webinars
- Newsletters
- MATLAB Trials
- Careers

## 0 Comments