calculate correlation between the blocks

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

4 Comments

In what form do the blocks exist? Do you have a 16x16 cell array, each cell containing a 16x16 block?
And how do you define correlation between blocks? Will the result for each pair of blocks be a scalar or something else?
sir i've total of 256 blocks i.e 16 rows and 16 columns.. after that
  • ive calculated the GLCM MEAN of each and every block...
  • like block 34 56 and 67 have GLCM MEAN value 1241..
  • or block 78 12 32 and 45 have GLCM MEAN value 898.. i want to find the correlation between the blocks..
i've divided the image into following way...
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);
here blockSizeR = 16 and blockSizeC = 16
Matt J
Matt J on 29 Mar 2013
Edited: Matt J on 29 Mar 2013
I repeat, how do you define 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?
scalar value sir...i.e single value..

Sign in to comment.

 Accepted Answer

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

4 Comments

showing error
Undefined function 'mat2tiles' for input arguments of type 'uint8'.
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????
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.
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

Sign in to comment.

More Answers (0)

Asked:

on 29 Mar 2013

Community Treasure Hunt

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

Start Hunting!