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:
Template Matching

Subject: Template Matching

From: akane ajibana

Date: 30 Mar, 2008 07:18:02

Message: 1 of 50

hi everyone..
i have need help on template matching. i have an image that
need to be match with 3 subimage(template images).can anyone
teach me on the coding in Matlab

Subject: Template Matching

From: ImageAnalyst

Date: 30 Mar, 2008 21:29:25

Message: 2 of 50

On Mar 30, 3:18=A0am, "akane ajibana" <androalpha...@yahoo.com> wrote:
> hi everyone..
> i have need help on template matching. i have an image that
> need to be match with 3 subimage(template images).can anyone
> teach me on the coding in Matlab
------------------------------------------------
akane:
Just scan it across your image (using 2 nested for loops). Hit every
pixel in the image multiplying the image under the template by your
template. Check to see if it attains the value it should if your
image exactly matched your template. You might be able to send your
template and your image into the conv2() function and avoid the nested
for loops. Are you using a gray scale image, binary image, color
image, or 3D volume image?

What exactly have you tried yet? Post your code. Post images if you
can.
Regards,
ImageAnalyst

Subject: Template Matching

From: androalpha_v7@yahoo.com

Date: 3 Apr, 2008 08:56:23

Message: 3 of 50

thanx ImageAnalyst;

the image i will use is in grayscale..
can u all suggest the other matching 2 image techique that available
in MAtlab

Subject: Template Matching

From: Dave Robinson

Date: 3 Apr, 2008 10:52:02

Message: 4 of 50

androalpha_v7@yahoo.com wrote in message <5bd63180-92b7-
401f-acac-fe5c63f19d7d@q27g2000prf.googlegroups.com>...
> thanx ImageAnalyst;
>
> the image i will use is in grayscale..
> can u all suggest the other matching 2 image techique
that available
> in MAtlab

Providing that the subimages you are searching for do not
rotate, and are the same scale as your templates, then
probably an efficient way of doing what you want is to use
fast correlation.

Take your three template images, and place them in a blank
frame which has the same size as the image you are scanning.

Do a 2D fast Fourier transform on your search image, and
your three buffered template images. Multiply pixel by
pixel (.*) the Fourier domain version of your search image
(remember these will be complex numbers) by the complex
conjugate of the Fourier transforms of your buffered
template images inturn. The inverse transform of these
three product transforms which will show a bright spot at
the point where your template exists within your search
image.

If your target position is close to the edge, then you
should increase the size of your 'blank buffer' frames to
m+n-1 where m is the size of your search image, and n is
the size of your templates. In this case embed your search
image into an identical buffer frame.

From memory I think that the Filter operation (imfilt()?)
in the image toolbox does this complete operation for you,
but you must remember to set the operation to undertake
correlation - not convolution.

Regards

Dave Robinson

Subject: Template Matching

From: androalpha_v7@yahoo.com

Date: 3 Apr, 2008 23:07:11

Message: 5 of 50

what do you mean by "Take your three template images, and place them
in a blank
frame which has the same size as the image you are scanning."

what exactly the right coding to do it....

Subject: Template Matching

From: androalpha_v7@yahoo.com

Date: 4 Apr, 2008 06:43:26

Message: 6 of 50

can i do the correlation if the template and original image is in
different size?

Subject: Template Matching

From: Dave Robinson

Date: 4 Apr, 2008 08:46:02

Message: 7 of 50

androalpha_v7@yahoo.com wrote in message <60ed041e-aaaa-
43b5-aa08-876e61f69f74@r9g2000prd.googlegroups.com>...
> can i do the correlation if the template and original
image is in
> different size?

Yes, using the scanning method outlined by one of the
previous helpers (or a method that hides the image
buffering from you).

The Fast Fourier transform has the property of generating a
complex array with the same number of elements as the image
has pixels. You need to multiply two Transforms
together 'pixel by pixel' - it therefore follows that the
number of elements in your search image transform must be
the same as the number of elements in your template
transform array. Clearly there is an apparent problem
between these two observations when the template is a
different size to your search image. However this is
trivially dealt with by creating an empty buffer whose size
is the same as the search image (or bigger - see my earlier
comments) using something like 'zeros(y,x)' then simply
copy your template image into the top left hand corner of
the blank buffer, then proceed as suggested.

Hope that helps

Dave Robinson

Subject: Template Matching

From: Peter Bone

Date: 4 Apr, 2008 10:12:02

Message: 8 of 50

"akane ajibana" <androalpha_v7@yahoo.com> wrote in message
<fsnera$t69$1@fred.mathworks.com>...
> hi everyone..
> i have need help on template matching. i have an image that
> need to be match with 3 subimage(template images).can anyone
> teach me on the coding in Matlab

The images cannot be different sizes so you will have to pad
out the smaller image with zeros to make it the same size.
The images must also be square.

% fourier transform both images
fi = fft2(i);
fr = fft2(ref);

% perform phase correlation (amplitude is normalized)
fc = fi .* conj(fr);
fcn = fc ./ abs(fc);
c = real(ifft2(fcn));

% find the peak in the correlation plane
[v index] = max(c(:));
[y x] = ind2sub(siz,index);
% invert quadrants due to fft shift
mid = siz(1) / 2;
y = y - sign(y-mid-0.5) * mid;
x = x - sign(x-mid-0.5) * mid;

Subject: Template Matching

From: androalpha_v7@yahoo.com

Date: 4 Apr, 2008 14:10:28

Message: 9 of 50

how about to fill some area in the image so that the desire shape is
fullfill...?
it's there any clue to do it...

Subject: Template Matching

From: androalpha_v7@yahoo.com

Date: 4 Apr, 2008 14:13:51

Message: 10 of 50


How have to pad out the smaller image with zeros to make it
so that the image in same size. ?

Subject: Template Matching

From: Peter Bone

Date: 4 Apr, 2008 15:56:03

Message: 11 of 50

androalpha_v7@yahoo.com wrote in message
<517f4bf4-8260-497e-b194-c7abe5c92080@a9g2000prl.googlegroups.com>...
>
> How have to pad out the smaller image with zeros to make it
> so that the image in same size. ?

a is the square small image, b is the square large image, c
is the zero padded image of a

a = rand(64);
b = rand(128);

sizA = size(a);
sizB = size(b);

c = zeros(sizB);
start = floor((sizB(1) - sizA(1)) / 2);
c(start:start+sizA(1)-1,start:start+sizA(1)-1) = a;

imshow(c)
figure
imshow(b)

Subject: Template Matching

From: Bob

Date: 4 Apr, 2008 17:37:29

Message: 12 of 50

Sure:
>> doc normxcorr2 %Image Processing Toolbox
>> doc xcorr2 %core MATLAB

Cheers
>> bob


On Apr 4, 2:43 am, androalpha...@yahoo.com wrote:
> can i do the correlation if the template and original image is in
> different size?

Subject: Template Matching

From: androalpha_v7@yahoo.com

Date: 5 Apr, 2008 02:59:44

Message: 13 of 50

subimage=x,y and z
original image = a;

if x match with a; do 'done'
    else 'match with b';
if b match with a; do 'done'
   else 'match with c';
if c match with a; do done
   else 'end'

done = display gui"image is match"
end = display gui 'image not match"

how to do the coding?
do i need to have a data base..?
if i do...what step should i do to link the database with the command
windows
in matlab?
'

Subject: Template Matching

From: androalpha_v7@yahoo.com

Date: 7 Apr, 2008 03:45:08

Message: 14 of 50

i have A image to expand the size of it so that it have same size with
B image.
A image =[38 51]
B image=[423 800}

so how to do it?

Subject: Template Matching

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 7 Apr, 2008 05:42:54

Message: 15 of 50

In article <647eb1a7-98ee-4b77-9d3a-6b42906c15e2@j1g2000prb.googlegroups.com>,
 <androalpha_v7@yahoo.com> wrote:
>i have A image to expand the size of it so that it have same size with
>B image.
>A image =[38 51]
>B image=[423 800}

>so how to do it?

You have a problem that those two images do not have the same
aspect ratio. Therefor in order to expand the size of A, you
are either going to need to leave some empty space in the enlarged
image, or you are going to have to stretch the x and y axes
unequally.

There are several different image resizing algorithms, with
different properties. For example, some of the algorithms
concentrate on preserving sharp edges and some of them do not.
In your situation, what (if any) characteristics of the source image
are important to preserve in the enlarged image?

--
  "He wove a great web of knowledge, linking everything together,
  and sat modestly at a switchboard at the center, eager to help."
                                              -- Walter Kerr

Subject: Template Matching

From: androalpha_v7@yahoo.com

Date: 7 Apr, 2008 07:11:30

Message: 16 of 50

> There are several different image resizing algorithms, with
> different properties. For example, some of the algorithms
> concentrate on preserving sharp edges and some of them do not.
> In your situation, what (if any) characteristics of the source image
> are important to preserve in the enlarged image?

thanx walter for the advice..

A=image(image of any ships)
B=subimage (containing number assigned to a ship)

the idea of my assignment is like fingerprint recognition...but i want
to implement it using
matlab template matching..
so if the image contain the sbimage(no.assigned to ships)...then we
can say its match..
not only that..
i have other 2 subimage to match with A before i can say this image is
match...

so do u have any idea?

Subject: Template Matching

From: Dave Robinson

Date: 7 Apr, 2008 09:03:03

Message: 17 of 50

androalpha_v7@yahoo.com wrote in message <36d513fb-3cc7-
49e7-8397-3b3fefc79825@j1g2000prb.googlegroups.com>...
> > There are several different image resizing algorithms,
with
> > different properties. For example, some of the
algorithms
> > concentrate on preserving sharp edges and some of them
do not.
> > In your situation, what (if any) characteristics of the
source image
> > are important to preserve in the enlarged image?
>
> thanx walter for the advice..
>
> A=image(image of any ships)
> B=subimage (containing number assigned to a ship)
>
> the idea of my assignment is like fingerprint
recognition...but i want
> to implement it using
> matlab template matching..
> so if the image contain the sbimage(no.assigned to
ships)...then we
> can say its match..
> not only that..
> i have other 2 subimage to match with A before i can say
this image is
> match...
>
> so do u have any idea?
>
For your application you DO NOT want to stretch your images
to the same size. It is essential that the spatial scale
between your search image and template remain fixed. Using
Walter's technique will change the scaling of your
template, so you will no longer be able to find a match
between the template and the Search Image.

What you have to do is embed your template image into a
blank frame, so that if you view the resulting buffered
image you see your template, the same size as it started
and a large region of black pixels. Walters suggestions
will essentially fill your buffer with a scaled version of
your template.

Pete Bone's response tells you how to do what you need.

Regards

Dave Robinson

Subject: Template Matching

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 7 Apr, 2008 14:27:01

Message: 18 of 50

In article <ftco07$9sl$1@fred.mathworks.com>,
Dave Robinson <dave.robinson@somewhere.biz> wrote:

>For your application you DO NOT want to stretch your images
>to the same size. It is essential that the spatial scale
>between your search image and template remain fixed. Using
>Walter's technique will change the scaling of your
>template, so you will no longer be able to find a match
>between the template and the Search Image.

>What you have to do is embed your template image into a
>blank frame, so that if you view the resulting buffered
>image you see your template, the same size as it started
>and a large region of black pixels. Walters suggestions
>will essentially fill your buffer with a scaled version of
>your template.

You are not representing what I said accurately. What I wrote was,

>>You have a problem that those two images do not have the same
>>aspect ratio. Therefor in order to expand the size of A, you
>>are either going to need to leave some empty space in the enlarged
>>image, or you are going to have to stretch the x and y axes
>>unequally.

and I then proceeded to ask what characteristics were important
in the image expansion, so that we could figure out what kind
of expansion to use. Your "blank frame" option is the same as
my conditional "empty space" option, and my image magnification
option was accompanied by a warning that it would stretch the
axes unequally.
--
  "It is surprising what a man can do when he has to, and how
  little most men will do when they don't have to."
                                              -- Walter Linn

Subject: Template Matching

From: Dave Robinson

Date: 7 Apr, 2008 16:15:04

Message: 19 of 50

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <ftdavl$7dc$1@canopus.cc.umanitoba.ca>...
> In article <ftco07$9sl$1@fred.mathworks.com>,
> Dave Robinson <dave.robinson@somewhere.biz> wrote:
>
> >For your application you DO NOT want to stretch your
images
> >to the same size. It is essential that the spatial scale
> >between your search image and template remain fixed.
Using
> >Walter's technique will change the scaling of your
> >template, so you will no longer be able to find a match
> >between the template and the Search Image.
>
> >What you have to do is embed your template image into a
> >blank frame, so that if you view the resulting buffered
> >image you see your template, the same size as it started
> >and a large region of black pixels. Walters suggestions
> >will essentially fill your buffer with a scaled version
of
> >your template.
>
> You are not representing what I said accurately. What I
wrote was,
>
> >>You have a problem that those two images do not have
the same
> >>aspect ratio. Therefor in order to expand the size of
A, you
> >>are either going to need to leave some empty space in
the enlarged
> >>image, or you are going to have to stretch the x and y
axes
> >>unequally.
>
> and I then proceeded to ask what characteristics were
important
> in the image expansion, so that we could figure out what
kind
> of expansion to use. Your "blank frame" option is the
same as
> my conditional "empty space" option, and my image
magnification
> option was accompanied by a warning that it would stretch
the
> axes unequally.

Hi Walter

No critisism of your solution was meant, indeed it was a
full and valid explanation (as usual;-) of what the
original question you responded to asked.

I just got the impression that the guy had not understood
the help that had been provided with earlier postings, and
wanted to make sure that he wasn't flying off at a tangent.

Sorry if I upset you, it wasn't intentional

Regards

Dave Robinson

Subject: Template Matching

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 7 Apr, 2008 16:55:44

Message: 20 of 50

In article <ftco07$9sl$1@fred.mathworks.com>,
Dave Robinson <dave.robinson@somewhere.biz> wrote:
>androalpha_v7@yahoo.com wrote in message <36d513fb-3cc7-
>49e7-8397-3b3fefc79825@j1g2000prb.googlegroups.com>...

>> A=image(image of any ships)
>> B=subimage (containing number assigned to a ship)

>For your application you DO NOT want to stretch your images
>to the same size. It is essential that the spatial scale
>between your search image and template remain fixed. Using
>Walter's technique will change the scaling of your
>template, so you will no longer be able to find a match
>between the template and the Search Image.

>What you have to do is embed your template image into a
>blank frame, so that if you view the resulting buffered
>image you see your template, the same size as it started
>and a large region of black pixels. Walters suggestions
>will essentially fill your buffer with a scaled version of
>your template.

I am confused about which is the "template" image in this
situation. It seems to me that the "template" is image B,
which I -gather- is a high-resolution ship number, with it
being necessary to find test the ship number against image A
in order to attempt to recognize which ship is present in image A.
But if these thoughts are true, then if image A got resized
to larger, then it would not be the -template- that got
embedded in a frame, or the -template- that got scaled, it would
be the image of the ship. And it seems to me that if the component
relationship I have described is what the original poster intended,
then either no rescaling is needed at all or else the scaling required
would be such that one would blow up the image of the ship so that
the ship number assumed the same scale as the template, thus requiring
that the ship image be blown up to noticably -larger- than the template.
(Which at least might solve the aspect ratio issues.)

But I haven't done any template matching, and I am not certain I
have understood properly what A and B are.
--
  "Eightly percent of the people in the world are fools and the
  rest of us are in danger of contamination." -- Walter Matthau

Subject: Template Matching

From: androalpha_v7@yahoo.com

Date: 8 Apr, 2008 10:31:30

Message: 21 of 50

seem i have cause a trouble here
so let me example
i have a image that have many type of fruit and vegetable..
i have a template image that have an image of apple..
both have the size i have mention before...

i have a problem to pad the template image
becoz after this i want to do the cross correlation between those two
image
as far as i know both image must have same size
so how to do it?

Subject: Template Matching

From: Yumnam Kirani Singh

Date: 8 Apr, 2008 11:13:29

Message: 22 of 50

Why so many stuffs on Template matching? It is almost the same as comparing two matrices for equality. Am I seriously wrong?

Subject: Template Matching

From: androalpha_v7@yahoo.com

Date: 8 Apr, 2008 11:53:22

Message: 23 of 50

On Apr 8, 7:13 pm, Yumnam Kirani Singh <kirani.si...@gmail.com> wrote:
> Why so many stuffs on Template matching? It is almost the same as comparing two matrices for equality. Am I seriously wrong?

sorry about it...
i'm still working on template matching since i have no background
about matlab..

so please kindly advice on this feel

Subject: Template Matching

From: androalpha_v7@yahoo.com

Date: 8 Apr, 2008 11:57:29

Message: 24 of 50

On Apr 8, 7:13 pm, Yumnam Kirani Singh <kirani.si...@gmail.com> wrote:
> Why so many stuffs on Template matching? It is almost the same as comparing two matrices for equality. Am I seriously wrong?

sorry about it...
i'm still working on template matching since i have no background
about matlab..

so please kindly advice me on this field..

Subject: Template Matching

From: Greg Heath

Date: 8 Apr, 2008 13:05:05

Message: 25 of 50

On Apr 8, 7:57=A0am, androalpha...@yahoo.com wrote:
> On Apr 8, 7:13 pm, Yumnam Kirani Singh <kirani.si...@gmail.com> wrote:
>
> > Why so many stuffs on Template matching? It is almost the same as compar=
ing two matrices for equality. Am I seriously wrong?
>
> sorry about it...
> i'm still working on template matching since i have no background
> about matlab..
>
> so please kindly advice me on this field..

Equality comparison doesn't take into account translations, rotations
and
scaling. Nor does it take into consideration the matching of a
subimage
with the template.

Hope this helps.

Greg

Subject: Template Matching

From: ImageAnalyst

Date: 8 Apr, 2008 13:20:55

Message: 26 of 50

On Apr 8, 7:13=A0am, Yumnam Kirani Singh <kirani.si...@gmail.com> wrote:
> Why so many stuffs on Template matching? It is almost the same as comparin=
g two matrices for equality. Am I seriously wrong?

Yep, you are. Your concept works only in the most simple case. So
simple in fact that you'll never see it in the real world. It would
only happen in specially written simulations where you specifically
made it so. The real world will have situations as described in Greg
Heath's message, plus other things he didn't mention (but I'm sure
knows about) such as noise, partial occlusions (this is a very tough
complication, e.g. only part of the apple is visible), orientation
changes (e.g. you're trying to find apples and you have the bottom of
an apple in your image but your template is the side view of an
apple), different shapes/templates (e.g. find tanks given that there
are dozens of different models of tanks), color differences (apples
come in many different colors and color patterns), etc. In general
this can be a very tough problem - numerous people have gotten Ph.D.'s
in the subject. Or, if given as homework by a kind professor, it may
be crafted to be relatively simple.
Regards,
ImageAnalyst

Subject: Template Matching

From: androalpha_v7@yahoo.com

Date: 8 Apr, 2008 22:37:31

Message: 27 of 50

> Yep, you are. Your concept works only in the most simple case. So
> simple in fact that you'll never see it in the real world. It would
> only happen in specially written simulations where you specifically
> made it so. The real world will have situations as described in Greg
> Heath's message, plus other things he didn't mention (but I'm sure
> knows about) such as noise, partial occlusions (this is a very tough
> complication, e.g. only part of the apple is visible), orientation
> changes (e.g. you're trying to find apples and you have the bottom of
> an apple in your image but your template is the side view of an
> apple), different shapes/templates (e.g. find tanks given that there
> are dozens of different models of tanks), color differences (apples
> come in many different colors and color patterns), etc. In general
> this can be a very tough problem - numerous people have gotten Ph.D.'s
> in the subject. Or, if given as homework by a kind professor, it may
> be crafted to be relatively simple.

Yes, you are right...everyone starting to talk to me saying that this
a basic concept.but
for me it's no easy to do it..
it's been a hard time for me to do it for the past 2 weeks...
i have about one week left to finish this...
so please any one...help me on this field

Subject: Template Matching

From: ImageAnalyst

Date: 9 Apr, 2008 02:49:43

Message: 28 of 50

On Apr 8, 6:37=A0pm, androalpha...@yahoo.com wrote:
> > Yep, you are. =A0Your concept works only in the most simple case. =A0So
> > simple in fact that you'll never see it in the real world. =A0It would
> > only happen in specially written simulations where you specifically
> > made it so. =A0The real world will have situations as described in Greg
> > Heath's message, plus other things he didn't mention (but I'm sure
> > knows about) such as noise, partial occlusions (this is a very tough
> > complication, e.g. only part of the apple is visible), orientation
> > changes (e.g. you're trying to find apples and you have the bottom of
> > an apple in your image but your template is the side view of an
> > apple), different shapes/templates (e.g. find tanks given that there
> > are dozens of different models of tanks), color differences (apples
> > come in many different colors and color patterns), etc. =A0In general
> > this can be a very tough problem - numerous people have gotten Ph.D.'s
> > in the subject. =A0Or, if given as homework by a kind professor, it may
> > be crafted to be relatively simple.
>
> Yes, you are right...everyone starting to talk to me saying that this
> a basic concept.but
> for me it's no easy to do it..
> it's been a hard time for me to do it for the past 2 weeks...
> i have about one week left to finish this...
> so please any one...help me on this field

Well why don't you post some images and a template(s) so we know what
you're trying to find and where you need to look for it? Otherwise
you'll just have to make do with the general answers you've gotten so
far.
Regards,
ImageAnalyst

Subject: Template Matching

From: androalpha_v7@yahoo.com

Date: 9 Apr, 2008 06:29:57

Message: 29 of 50

Thanx ImageAnalyst for concerning...
If u could give me yr emel than it will
much easier for me to post some image
so that you can take a look on it...

Subject: Template Matching

From: akane

Date: 9 Apr, 2008 07:21:26

Message: 30 of 50

Since this a usenet group so it's impossible to post any image or file
If anyone interested with my project, please do tell me your e-mel
So that i can send u the files@image

Please do help me
akane

Subject: Template Matching

From: Sven

Date: 9 Apr, 2008 07:40:19

Message: 31 of 50

akane <androalpha_v7@yahoo.com> wrote in message
<563ff25e-11bf-4619-b869-7f01c290dc94@v26g2000prm.googlegroups.com>...
> Since this a usenet group so it's impossible to post any
image or file
> If anyone interested with my project, please do tell me
your e-mel
> So that i can send u the files@image
>
> Please do help me
> akane

May I suggest that you instead use a free image hosting
service (such as http://imageshack.us/), rather than asking
for individual peoples' email. After you upload your
image(s), post a *detailed* description of what you are
trying to achieve, what you have succeeded with, and the
specific problems you now have.

I think people will be willing (and able) to help you if you
do this.

Thanks,
Sven.

Subject: Template Matching

From: akane

Date: 9 Apr, 2008 09:36:29

Message: 32 of 50

Thanx for the advice Sven....

Subject: Template Matching

From: akane

Date: 9 Apr, 2008 09:40:43

Message: 33 of 50

On Apr 9, 3:40 pm, "Sven " <sven.holco...@gmail.deleteme.com> wrote:
> akane <androalpha...@yahoo.com> wrote in message
>
> <563ff25e-11bf-4619-b869-7f01c290d...@v26g2000prm.googlegroups.com>...
>
> > Since this a usenet group so it's impossible to post any
> image or file
> > If anyone interested with my project, please do tell me
> your e-mel
> > So that i can send u the files@image
>
> > Please do help me
> > akane
>
> May I suggest that you instead use a free image hosting
> service (such ashttp://imageshack.us/), rather than asking
> for individual peoples' email. After you upload your
> image(s), post a *detailed* description of what you are
> trying to achieve, what you have succeeded with, and the
> specific problems you now have.
>
> I think people will be willing (and able) to help you if you
> do this.
>
> Thanks,
> Sven.

it's there other website that u all can suggest

Subject: Template Matching

From: Yumnam Kirani Singh

Date: 9 Apr, 2008 10:02:38

Message: 34 of 50

How does the question of translation and rotation comes in template matching? How more comparisions are required other than checking whether a given image is equal to a template image or not? The question of how many template are used in your database is different issue. Let's learn how to simplyfy the things rather thank making things complex and making unnecessarily difficult.

Subject: Template Matching

From: poonam jadhav

Date: 9 Apr, 2008 11:16:02

Message: 35 of 50

Hi everyone
i want to find out the translation(shift) between the two
images(ref and test) using matlab,in order to registered
them.For that i am using phase correlation method
but i am not getting proper result.So i have refered the
code mentioned in this mail.
but i am not understanding
[y x] = ind2sub(siz,index);

Here what is the value of variable "siz"
pls reply me
"Peter Bone" <peterbone@hotmail.com> wrote in message
<ft4uti$a7o$1@fred.mathworks.com>...
> "akane ajibana" <androalpha_v7@yahoo.com> wrote in message
> <fsnera$t69$1@fred.mathworks.com>...
> > hi everyone..
> > i have need help on template matching. i have an image
that
> > need to be match with 3 subimage(template images).can
anyone
> > teach me on the coding in Matlab
>
> The images cannot be different sizes so you will have to
pad
> out the smaller image with zeros to make it the same size.
> The images must also be square.
>
> % fourier transform both images
> fi = fft2(i);
> fr = fft2(ref);
>
> % perform phase correlation (amplitude is normalized)
> fc = fi .* conj(fr);
> fcn = fc ./ abs(fc);
> c = real(ifft2(fcn));
>
> % find the peak in the correlation plane
> [v index] = max(c(:));
> [y x] = ind2sub(siz,index);
> % invert quadrants due to fft shift
> mid = siz(1) / 2;
> y = y - sign(y-mid-0.5) * mid;
> x = x - sign(x-mid-0.5) * mid;
>

Subject: Template Matching

From: poonam jadhav

Date: 11 Apr, 2008 09:38:16

Message: 36 of 50

Hi,
i want to find out shift between two images using phase
correlation.
i have referred the following code ,but i am not getting the
plot of ifft ,so pls help me for plotting it



"Peter Bone" <peterbone@hotmail.com> wrote in message
<ft4uti$a7o$1@fred.mathworks.com>...
> "akane ajibana" <androalpha_v7@yahoo.com> wrote in message
> <fsnera$t69$1@fred.mathworks.com>...
> > hi everyone..
> > i have need help on template matching. i have an image that
> > need to be match with 3 subimage(template images).can anyone
> > teach me on the coding in Matlab
>
> The images cannot be different sizes so you will have to pad
> out the smaller image with zeros to make it the same size.
> The images must also be square.
>
> % fourier transform both images
> fi = fft2(i);
> fr = fft2(ref);
>
> % perform phase correlation (amplitude is normalized)
> fc = fi .* conj(fr);
> fcn = fc ./ abs(fc);
> c = real(ifft2(fcn));
>
> % find the peak in the correlation plane
> [v index] = max(c(:));
> [y x] = ind2sub(siz,index);
> % invert quadrants due to fft shift
> mid = siz(1) / 2;
> y = y - sign(y-mid-0.5) * mid;
> x = x - sign(x-mid-0.5) * mid;
>

Subject: Template Matching

From: poonam jadhav

Date: 11 Apr, 2008 09:38:17

Message: 37 of 50

Hi,
i want to find out shift between two images using phase
correlation.
i have referred the following code ,but i am not getting the
plot of ifft ,so pls help me for plotting it



"Peter Bone" <peterbone@hotmail.com> wrote in message
<ft4uti$a7o$1@fred.mathworks.com>...
> "akane ajibana" <androalpha_v7@yahoo.com> wrote in message
> <fsnera$t69$1@fred.mathworks.com>...
> > hi everyone..
> > i have need help on template matching. i have an image that
> > need to be match with 3 subimage(template images).can anyone
> > teach me on the coding in Matlab
>
> The images cannot be different sizes so you will have to pad
> out the smaller image with zeros to make it the same size.
> The images must also be square.
>
> % fourier transform both images
> fi = fft2(i);
> fr = fft2(ref);
>
> % perform phase correlation (amplitude is normalized)
> fc = fi .* conj(fr);
> fcn = fc ./ abs(fc);
> c = real(ifft2(fcn));
>
> % find the peak in the correlation plane
> [v index] = max(c(:));
> [y x] = ind2sub(siz,index);
> % invert quadrants due to fft shift
> mid = siz(1) / 2;
> y = y - sign(y-mid-0.5) * mid;
> x = x - sign(x-mid-0.5) * mid;
>

Subject: Template Matching

From: poonam jadhav

Date: 11 Apr, 2008 09:43:53

Message: 38 of 50

Hi,
i want to find out shift between two images using phase
correlation.
i have referred the following code ,but i am not getting the
plot of ifft ,so pls help me for plotting it



"Peter Bone" <peterbone@hotmail.com> wrote in message
<ft4uti$a7o$1@fred.mathworks.com>...
> "akane ajibana" <androalpha_v7@yahoo.com> wrote in message
> <fsnera$t69$1@fred.mathworks.com>...
> > hi everyone..
> > i have need help on template matching. i have an image that
> > need to be match with 3 subimage(template images).can anyone
> > teach me on the coding in Matlab
>
> The images cannot be different sizes so you will have to pad
> out the smaller image with zeros to make it the same size.
> The images must also be square.
>
> % fourier transform both images
> fi = fft2(i);
> fr = fft2(ref);
>
> % perform phase correlation (amplitude is normalized)
> fc = fi .* conj(fr);
> fcn = fc ./ abs(fc);
> c = real(ifft2(fcn));
>
> % find the peak in the correlation plane
> [v index] = max(c(:));
> [y x] = ind2sub(siz,index);
> % invert quadrants due to fft shift
> mid = siz(1) / 2;
> y = y - sign(y-mid-0.5) * mid;
> x = x - sign(x-mid-0.5) * mid;
>

Subject: Template Matching

From: poonam jadhav

Date: 11 Apr, 2008 10:03:02

Message: 39 of 50

Hi,
i want to find out shift between two images using phase
correlation.
i have referred the following code ,but i am not getting the
plot of ifft ,so pls help me for plotting it



"Peter Bone" <peterbone@hotmail.com> wrote in message
<ft4uti$a7o$1@fred.mathworks.com>...
> "akane ajibana" <androalpha_v7@yahoo.com> wrote in message
> <fsnera$t69$1@fred.mathworks.com>...
> > hi everyone..
> > i have need help on template matching. i have an image that
> > need to be match with 3 subimage(template images).can anyone
> > teach me on the coding in Matlab
>
> The images cannot be different sizes so you will have to pad
> out the smaller image with zeros to make it the same size.
> The images must also be square.
>
> % fourier transform both images
> fi = fft2(i);
> fr = fft2(ref);
>
> % perform phase correlation (amplitude is normalized)
> fc = fi .* conj(fr);
> fcn = fc ./ abs(fc);
> c = real(ifft2(fcn));
>
> % find the peak in the correlation plane
> [v index] = max(c(:));
> [y x] = ind2sub(siz,index);
> % invert quadrants due to fft shift
> mid = siz(1) / 2;
> y = y - sign(y-mid-0.5) * mid;
> x = x - sign(x-mid-0.5) * mid;
>

Subject: Template Matching

From: Peter Bone

Date: 11 Apr, 2008 10:03:32

Message: 40 of 50

"poonam jadhav" <poonamsonar@gmail.com> wrote in message
<ftnbsp$gmp$1@fred.mathworks.com>...
> Hi,
> i want to find out shift between two images using phase
> correlation.
> i have referred the following code ,but i am not getting the
> plot of ifft ,so pls help me for plotting it

mesh(c)

Subject: Template Matching

From: Peter Bone

Date: 11 Apr, 2008 10:06:17

Message: 41 of 50

"poonam jadhav" <poonamsonar@gmail.com> wrote in message
<ftnbsp$gmp$1@fred.mathworks.com>...
> Hi,
> i want to find out shift between two images using phase
> correlation.
> i have referred the following code ,but i am not getting the
> plot of ifft ,so pls help me for plotting it

mesh(c)

Subject: Template Matching

From: Peter Bone

Date: 11 Apr, 2008 10:06:18

Message: 42 of 50

"poonam jadhav" <poonamsonar@gmail.com> wrote in message
<ftnbsp$gmp$1@fred.mathworks.com>...
> Hi,
> i want to find out shift between two images using phase
> correlation.
> i have referred the following code ,but i am not getting the
> plot of ifft ,so pls help me for plotting it

mesh(c)

Subject: Template Matching

From: Peter Bone

Date: 11 Apr, 2008 10:09:42

Message: 43 of 50

"poonam jadhav" <poonamsonar@gmail.com> wrote in message
<ftnbsp$gmp$1@fred.mathworks.com>...
> Hi,
> i want to find out shift between two images using phase
> correlation.
> i have referred the following code ,but i am not getting the
> plot of ifft ,so pls help me for plotting it

mesh(c)

Subject: Template Matching

From: poonam jadhav

Date: 15 Apr, 2008 06:56:02

Message: 44 of 50

"Peter Bone" <peterbone@hotmail.com> wrote in message
hi
i want to find out shift in 2 images (image registration).
for that i am using correlation technique.In oreder to
find the shift ,i have to find location of peak in
iif.plot ifft ,but i am not getting it.My code is as
follows
x=imread('mvr1.jpg')
y=imread('mvr2.jpg')
X=fft2(double(x))
Y=fft2(double(y))
CY=conj(Y)
Z=X.*CY
NR=(Z./(abs(X.*CY)))
R=real(ifft(NR))

so here i have to plot R
i have tried meshgrid function,but not getting proper
result.so anybody help me regarding it


<ft4uti$a7o$1@fred.mathworks.com>...
> "akane ajibana" <androalpha_v7@yahoo.com> wrote in
message
> <fsnera$t69$1@fred.mathworks.com>...
> > hi everyone..
> > i have need help on template matching. i have an image
that
> > need to be match with 3 subimage(template images).can
anyone
> > teach me on the coding in Matlab
>
> The images cannot be different sizes so you will have to
pad
> out the smaller image with zeros to make it the same
size.
> The images must also be square.
>
> % fourier transform both images
> fi = fft2(i);
> fr = fft2(ref);
>
> % perform phase correlation (amplitude is normalized)
> fc = fi .* conj(fr);
> fcn = fc ./ abs(fc);
> c = real(ifft2(fcn));
>
> % find the peak in the correlation plane
> [v index] = max(c(:));
> [y x] = ind2sub(siz,index);
> % invert quadrants due to fft shift
> mid = siz(1) / 2;
> y = y - sign(y-mid-0.5) * mid;
> x = x - sign(x-mid-0.5) * mid;
>

Subject: Template Matching

From: Hanaa

Date: 15 Apr, 2009 02:23:01

Message: 45 of 50

"poonam jadhav" <poonamsonar@gmail.com> wrote in message <fu1ji2$ls0$1@fred.mathworks.com>...
> "Peter Bone" <peterbone@hotmail.com> wrote in message
> hi
> i want to find out shift in 2 images (image registration).
> for that i am using correlation technique.In oreder to
> find the shift ,i have to find location of peak in
> iif.plot ifft ,but i am not getting it.My code is as
> follows
> x=imread('mvr1.jpg')
> y=imread('mvr2.jpg')
> X=fft2(double(x))
> Y=fft2(double(y))
> CY=conj(Y)
> Z=X.*CY
> NR=(Z./(abs(X.*CY)))
> R=real(ifft(NR))
>
> so here i have to plot R
> i have tried meshgrid function,but not getting proper
> result.so anybody help me regarding it
>
>
> <ft4uti$a7o$1@fred.mathworks.com>...
> > "akane ajibana" <androalpha_v7@yahoo.com> wrote in
> message
> > <fsnera$t69$1@fred.mathworks.com>...
> > > hi everyone..
> > > i have need help on template matching. i have an image
> that
> > > need to be match with 3 subimage(template images).can
> anyone
> > > teach me on the coding in Matlab
> >
> > The images cannot be different sizes so you will have to
> pad
> > out the smaller image with zeros to make it the same
> size.
> > The images must also be square.
> >
> > % fourier transform both images
> > fi = fft2(i);
> > fr = fft2(ref);
> >
> > % perform phase correlation (amplitude is normalized)
> > fc = fi .* conj(fr);
> > fcn = fc ./ abs(fc);
> > c = real(ifft2(fcn));
> >
> > % find the peak in the correlation plane
> > [v index] = max(c(:));
> > [y x] = ind2sub(siz,index);
> > % invert quadrants due to fft shift
> > mid = siz(1) / 2;
> > y = y - sign(y-mid-0.5) * mid;
> > x = x - sign(x-mid-0.5) * mid;
> >
>




Hello everyone..

This is my first time using template matching. I'm working on detecting the facial features, using MatLab.
Can anyone teach me the algorithm on how can I resize my template image to the input image, for my case resizing my eye template to the input image hence getting the best match.

I'd be grateful for your help.
Thanks! :)

Subject: Template Matching

From: Hanaa

Date: 15 Apr, 2009 02:25:04

Message: 46 of 50

"poonam jadhav" <poonamsonar@gmail.com> wrote in message <fu1ji2$ls0$1@fred.mathworks.com>...
> "Peter Bone" <peterbone@hotmail.com> wrote in message
> hi
> i want to find out shift in 2 images (image registration).
> for that i am using correlation technique.In oreder to
> find the shift ,i have to find location of peak in
> iif.plot ifft ,but i am not getting it.My code is as
> follows
> x=imread('mvr1.jpg')
> y=imread('mvr2.jpg')
> X=fft2(double(x))
> Y=fft2(double(y))
> CY=conj(Y)
> Z=X.*CY
> NR=(Z./(abs(X.*CY)))
> R=real(ifft(NR))
>
> so here i have to plot R
> i have tried meshgrid function,but not getting proper
> result.so anybody help me regarding it
>
>
> <ft4uti$a7o$1@fred.mathworks.com>...
> > "akane ajibana" <androalpha_v7@yahoo.com> wrote in
> message
> > <fsnera$t69$1@fred.mathworks.com>...
> > > hi everyone..
> > > i have need help on template matching. i have an image
> that
> > > need to be match with 3 subimage(template images).can
> anyone
> > > teach me on the coding in Matlab
> >
> > The images cannot be different sizes so you will have to
> pad
> > out the smaller image with zeros to make it the same
> size.
> > The images must also be square.
> >
> > % fourier transform both images
> > fi = fft2(i);
> > fr = fft2(ref);
> >
> > % perform phase correlation (amplitude is normalized)
> > fc = fi .* conj(fr);
> > fcn = fc ./ abs(fc);
> > c = real(ifft2(fcn));
> >
> > % find the peak in the correlation plane
> > [v index] = max(c(:));
> > [y x] = ind2sub(siz,index);
> > % invert quadrants due to fft shift
> > mid = siz(1) / 2;
> > y = y - sign(y-mid-0.5) * mid;
> > x = x - sign(x-mid-0.5) * mid;
> >
>
Hello everyone..

This is my first time using template matching. I'm working on detecting the facial features, using MatLab.
Can anyone teach me the algorithm on how can I resize my template image to the input image, for my case resizing my eye template to the input image hence getting the best match.

I'd be grateful for your help.
Thanks! :)

Subject: Template Matching

From: Karina

Date: 26 Jan, 2010 01:18:04

Message: 47 of 50

Dear Peter,
for you code below, what seems to be the value of "siz"? And what means " invert quadrants due to fft shift"? What is the final result - which values?
Would be very helpful!


"Peter Bone" <peterbone@hotmail.com> wrote in message <ft4uti$a7o$1@fred.mathworks.com>...
> "akane ajibana" <androalpha_v7@yahoo.com> wrote in message
> <fsnera$t69$1@fred.mathworks.com>...
> > hi everyone..
> > i have need help on template matching. i have an image that
> > need to be match with 3 subimage(template images).can anyone
> > teach me on the coding in Matlab
>
> The images cannot be different sizes so you will have to pad
> out the smaller image with zeros to make it the same size.
> The images must also be square.
>
> % fourier transform both images
> fi = fft2(i);
> fr = fft2(ref);
>
> % perform phase correlation (amplitude is normalized)
> fc = fi .* conj(fr);
> fcn = fc ./ abs(fc);
> c = real(ifft2(fcn));
>
> % find the peak in the correlation plane
> [v index] = max(c(:));
> [y x] = ind2sub(siz,index);
> % invert quadrants due to fft shift
> mid = siz(1) / 2;
> y = y - sign(y-mid-0.5) * mid;
> x = x - sign(x-mid-0.5) * mid;
>

Subject: Template Matching

From: Nureddin abulgasem

Date: 14 Oct, 2010 12:23:04

Message: 48 of 50

androalpha_v7@yahoo.com wrote in message <5bd63180-92b7-401f-acac-fe5c63f19d7d@q27g2000prf.googlegroups.com>...
> thanx ImageAnalyst;
>
> the image i will use is in grayscale..
> can u all suggest the other matching 2 image techique that available
> in MAtlab

Subject: Template Matching

From: sanyukta

Date: 8 Jan, 2012 05:48:07

Message: 49 of 50

androalpha_v7@yahoo.com wrote in message <86d11b30-6118-441d-a55c-db1ab921b59c@o1g2000pra.googlegroups.com>...
> how about to fill some area in the image so that the desire shape is
> fullfill...?
> it's there any clue to do it...
> [y x] = ind2sub(siz,index);
what does siz mean here?

Subject: Template Matching

From: Talha

Date: 16 Dec, 2013 15:18:51

Message: 50 of 50

Instead of
% find the peak in the correlation plane
[v index] = max(c(:));
[y x] = ind2sub(siz,index);

You can also use below command to get the peak
[y x]= find(c==max(c(:)))

On Sunday, January 8, 2012 10:48:07 AM UTC+5, sanyukta wrote:

> androalpha_v7@yahoo.com wrote in message <86d11b30-6118-441d-a55c-db1ab921b59c@o1g2000pra.googlegroups.com>...
>
> > how about to fill some area in the image so that the desire shape is
>
> > fullfill...?
>
> > it's there any clue to do it...
>
> > [y x] = ind2sub(siz,index);
>
> what does siz mean here?

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