MATLAB Answers^{™}

- 54 questions
- 1 answer
- 1 accepted answer
- Reputation: 4

Accepted Answer by Image Analyst

- 0 questions
- 15,889 answers
- 5,144 accepted answers
- Reputation: 25,880

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.*

- 0 questions
- 15,889 answers
- 5,144 accepted answers
- Reputation: 25,880

**Direct link to this answer:**

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

Answer by Image Analyst
on 29 Jan 2013

- 0 questions
- 15,889 answers
- 5,144 accepted answers
- Reputation: 25,880

Accepted answer

Use blockproc() with the BorderSize option.

Show 29 older comments

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))')

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.

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

Link

**Direct link to this comment:**

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

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.

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.

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..

Link

**Direct link to this comment:**

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

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..

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)

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

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)

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.

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 ?

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.

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..

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?

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?

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

Link

**Direct link to this comment:**

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

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{:});

Link

**Direct link to this comment:**

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

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

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..

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);

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.

Link

**Direct link to this comment:**

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

now where is overlapping region?

Link

**Direct link to this comment:**

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

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?

Link

**Direct link to this comment:**

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

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..

Link

**Direct link to this comment:**

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

Link

**Direct link to this comment:**

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

Opportunities for recent engineering grads.

## 0 Comments