Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Image Cross-Correlation

Subject: Image Cross-Correlation

From: Twilighter

Date: 7 Jun, 2011 13:18:20

Message: 1 of 8

I need to make a cross-correlation between two images

for image watermarking application

what i do is that i decompose the image into its dwt coefficeint then cross-correlate it with the watermark image

but the final array is all a NaN value

what is wrong do i do

Note: the DWT subbad which i cross-correlate it with the watermark both are of thes same size

here is what i do ...


watermarked_image=double(imread('dwt_watermarked.bmp'));

% read in original watermark
orig_watermark=rgb2gray(imread('WaterMark.jpg'))
orig_watermark=double(M);

% determine size of original watermark
Mo=size(orig_watermark,1); %Height
No=size(orig_watermark,2); %Width

% initalize message to all ones
message_vector=ones(1,Mo*No);

%[cA1,cH1,cV1,cD1] = dwt2(watermarked_image,'haar');

dwtmode('sym');
[C,S]=wavedec2(watermarked_image,3,'Haar');
cA3=appcoef2(C,S,'Haar',3);
ccA3=cA3;
[cH3,cV3,cD3] = detcoef2('all',C,S,3);
[cH1,cV1,cD1] = detcoef2('all',C,S,1);

WMreshape=reshape(orig_watermark,1,Mo*No);
cH1Reshape=reshape(cH1,1,Mo*No);
cV1Reshape=reshape(cV1,1,Mo*No);

for (kk=1:length(message_vector))
    
    correlation_h(kk)=corr2(cH1Reshape(1,kk),WMreshape(1,kk));
    correlation_v(kk)=corr2(cV1Reshape(1,kk),WMreshape(1,kk));
    correlation(kk)=(correlation_h(1,kk)+correlation_v(1,kk))/2;
end



all the values of the final "correlation" matrixis a NaN Value

thanx for your positive responese

Subject: Image Cross-Correlation

From: Roger Stafford

Date: 7 Jun, 2011 15:09:19

Message: 2 of 8

"Twilighter " <mscmatlab@gmail.com> wrote in message <isl8es$lab$1@newscl01ah.mathworks.com>...
> .......
> correlation_h(kk)=corr2(cH1Reshape(1,kk),WMreshape(1,kk));
> .......
> all the values of the final "correlation" matrixis a NaN Value
- - - - - - - -
  In your final for-loop you are applying 'corr2' to individual pairs of elements, and that will give you a NaN because you will be dividing zero by zero that way.

  The function 'corr2' is intended to be used on a pair of entire arrays of the same size as in:

 r = corr2(orig_watermark,cH1);

(provided these are the same size.) Read the documentation.

Roger Stafford

Subject: Image Cross-Correlation

From: Twilighter

Date: 8 Jun, 2011 14:01:05

Message: 3 of 8

Thank you for your reply ...
then how can i make the task i want.

to do a cross- correlation between the two images to match them or compare them & the result is an image too not one single value?

Subject: Image Cross-Correlation

From: Roger Stafford

Date: 8 Jun, 2011 17:34:04

Message: 4 of 8

"Twilighter " <mscmatlab@gmail.com> wrote in message <isnvb1$hmj$1@newscl01ah.mathworks.com>...
> Thank you for your reply ...
> then how can i make the task i want.
>
> to do a cross- correlation between the two images to match them or compare them & the result is an image too not one single value?
- - - - - - - - - - -
  I don't quite understand what you are asking. As you say, performing a cross correlation between two images with 'corr2' will simply give you a single scalar quantity which ranges between -1 and +1. A value near 0 means the images are uncorrelated, near +1 they are strongly correlated, and near -1 one is strongly correlated with the negative of the other. Nothing in this will give you another image.

  There is another cross-correlation function in the Image Processing Toolbox called 'normxcorr2' which obtains the cross correlation between a given template and a larger image for each of the possible positions of the template relative to the image. Users can utilize this to determine areas in the larger image that have a strong correlation with the template. If this sounds like something that interests you I would recommend a careful study of the pertinent document at:

 http://www.mathworks.com/help/toolbox/images/ref/normxcorr2.html

  One might consider this pattern of cross correlation values from 'normxcorr2' as constituting an image if it were rescaled to fit image ranges, but it would be a rather strange image.

Roger Stafford

Subject: Image Cross-Correlation

From: Twilighter

Date: 9 Jun, 2011 17:14:05

Message: 5 of 8

thank you your informative reply

i did read about corr2 & normxcorr2 functions in matlab help well, they dont quite meet my requirement

my application is mainly about image watermarking

i embed the watermark in the dwt coefficient & in the part of watermark extraction, it's usually done by using a correlation between the watermarked image & the watermark itself ... i wrote the part which simulate what i need to do in an earlier post

and the output should be something looking like the watermark

that's why i need to use correlation and get an image as an output

so, i really dunno how to implement that or if there is a function in matlab that could give me an output like that?

can you direct me where i should look for something like this?

Subject: Image Cross-Correlation

From: ImageAnalyst

Date: 9 Jun, 2011 21:05:50

Message: 6 of 8

For something involved like this, you need to come up with the
algorithm. We're not going to put that much work into your project -
that's too much to ask of us, you have to do that.
Since you asked, I direct you to check out section 23.3 here:
http://iris.usc.edu/Vision-Notes/bibliography/contentschar.html#OCR,%20Document%20Analysis%20and%20Character%20Recognition%20Systems

Pick an algorithm that looks promising, take a stab at programming it
up in MATLAB, then come back here with any MATLAB programming
questions (not questions related to the paper because we're not going
to figure out the paper and explain it to you).

Subject: Image Cross-Correlation

From: Twilighter

Date: 9 Jun, 2011 21:36:02

Message: 7 of 8

thank you for your reply

i already wrote the code which i came up with over here & all what i was asking about what is, what is wrong in my logic ...

i could be not understanding the concept of the correlation between two images which results to an image in the first place, and that leads to a faulty implementation ....

all what i read about in many papers about this point that this can be determined by cross-correlation, no more details ... just this vague line.

so i thought it's a straight forward implementation ... but it seems there are more in-between the lines

that's why we turn to experts cause we are just beginners ...

thanx

Subject: Image Cross-Correlation

From: ImageAnalyst

Date: 9 Jun, 2011 22:23:46

Message: 8 of 8

Well I don't have the wavelet toolbox and whatever else toolboxes you
need, so I'm afraid I can't help you. Maybe others could if you
posted your images somewhere where they could download them and try
them. I have no idea if the algorithm you gave up in your first post
is a good one or not. It sounds like corr() is not the right
function, and you say you tried normxcorr2 and that didn't work so it
sounds like you're not even exactly sure how to implement the
algorithm and I don't know what you did. It sounds like your best
hope is for someone familiar with wavelets and watermarking to be able
to download your images and try to debug your code for you. (That
wouldn't be me, but good luck.)

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us