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

Learn moreOpportunities for recent engineering grads.

Apply TodayTo resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Asked by angel on 29 Mar 2013

i've divided the image into 16x16 blocks i.e total of 256 blocks.

now i want to calculate the correlation between the blocks...

can anybody help me...

*No products are associated with this question.*

Answer by Matt J on 29 Mar 2013

Accepted answer

Using File Exchange: MAT2TILES

Blocks=mat2tiles(grayImage,[16,16]);

data=cellfun(@(x)x(:)-mean(x(:)), Blocks, 'uni',0 );

data=[data{:}];

Correlations = data.'*data;

Here, Correlations(i,j) is the correlation (my definition) of the i-th and j-th block. I'm not sure if this suits your definition (see my comments above).

Show 1 older comment

angel on 30 Mar 2013

let me tell u the whole procedure which i want...

the above code which i've give divides the image into non-overlapping blocks 16x16. After that i've code the following

lets have a look on it:

for row = 1 : blockSizeR : rows for col = 1 : blockSizeC : columns row1 = row; row2 = row1 + blockSizeR - 1; row2 = min(rows, row2);

% Determine starting and ending columns. col1 = col; col2 = col1 + blockSizeC - 1; col2 = min(columns, col2); % Don't let it go outside the image. % Extract out the block into a single subimage. oneBlock = grayImage(row1:row2, col1:col2); subplot(16,16,blockNumber); imshow(oneBlock); glcml=0; glcmr=0; glcm=0; glcmLR=0; glcm=graycomatrix(oneBlock,'NumLevels',16); %glcm=graycomatrix(oneBlock); for x=1:wholeBlockRows for y=1:wholeBlockCols glcml=glcml+x*glcm(x,y); glcmr=glcmr+y*glcm(x,y); glcmLR=abs(glcml-glcmr); end end glcmLRD(blockNumber)=glcmLR; %fprintf('\ndifference of block %d is %d\n',blockNumber,glcmLRD(blockNumber)); caption2 = sprintf('Block #%d\n of %d', blockNumber,blocks); title(caption2, 'FontSize', fontSize); %drawnow; blockNumber = blockNumber + 1;

end end

here i've calculated the GLCM MEAN of each and every block.

glcml is for left hand equation corresponding to 'x'

glcmr is for right hand equation corresponding to 'y'

glcmLR is the difference between between the two i.e (glcml-glcmr).

[S,blockNumber]=sort(glcmLRD);

u=unique(S(:));

grayColor=0; for i=1:length(u) matchIndex=(S(:)==u(i)); count=length(find(S(:)==u(i))); %disp(matchIndex); matchBlock=blockNumber(matchIndex); %grayColor=0; if(count>1) fprintf('\nblock') fprintf(' %d ',matchBlock); [B1]=matchBlock; end

end

after calculating the difference i've sort the GglcmLR values and there are many blocks whose glcmLR values are the same..

u can notice i've stored the unique values of glcmLR in 'u'.

here i captured only those blocks whose glcmLR values are same as u can see this [B1].

like

- block 23, block 34 and block 67 having glcmLR value is 3

- block 56, block 78 having glcmLR value let say 7

- block 89, block 32 and block 43 having glcmLR value 2

now guide me how to calculate correlation between these blocks????

Matt J on 30 Mar 2013

**Undefined function 'mat2tiles' for input arguments of type 'uint8'.**

You were meant to download mat2tiles from the link I gave you.

**now guide me how to calculate correlation between these blocks????**

This is the third time you've neglected to define what you mean by "correlation". Show us how you would compute the correlation of 2 blocks in some simplified example and explain what problem you're having extending it to many blocks.

angel on 8 Apr 2013

yet i've not calculated correlation but my idea behind this is:

correlation=corr2(block1,block2);

now tell me how to calculate the correlation of these:

block 23, block 34 and block 67 having glcmLR value is 3

block 56, block 78 having glcmLR value let say 7

block 89, block 32 and block 43 having glcmLR value 2

can anybody tell me how to do this

## 4 Comments

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/69081#comment_139776

In what form do the blocks exist? Do you have a 16x16 cell array, each cell containing a 16x16 block?

And how do

youdefine correlation between blocks? Will the result for each pair of blocks be a scalar or something else?Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/69081#comment_139783

sir i've total of 256 blocks i.e 16 rows and 16 columns.. after that

i've divided the image into following way...

here blockSizeR = 16 and blockSizeC = 16

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/69081#comment_139799

I repeat, how do

youdefine correlation between blocks? Will the result for each pair of blocks be a scalar or something else? If you have 2 blocks will xcorr2(block1,block2) give you the correlation in the form that you want?Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/69081#comment_139926

scalar value sir...i.e single value..