Home » Source Code » » normxcorr2_demo.m

normxcorr2_demo.m ( File view )

From:
  • By 2010-08-05
  • View(s):65
  • Download(s):0
  • Point(s): 1
			templateSize = 11; % square template

imgWidth = 320; % rectangular image
imgHeight = 240; 

template = rand(templateSize); % template with random entries
img = rand(imgHeight, imgWidth); % similarly for the image

% randomly embed the template inside the img
embedX = round(rand*(imgWidth-templateSize-1)+1);
embedY = round(rand*(imgHeight-templateSize-1)+1);
img( embedY:embedY+templateSize-1, embedX:embedX+templateSize-1 ) = template;

% display the input for normxcorr2
H = figure(1); clf;
set(H,'name','Can you find the template?');
subplot(1,2,1);
imagesc(img);
axis('image'); title('image');
subplot(1,2,2);
imagesc(template);
axis('image'); title('template');
colormap(gray);

% perform NCC
% choose 'same' as the output shape -- ie. zero-pad the output so 
% that it's the same size as the original image
% this is not necessary, but is used for display
ncc = normxcorr2_mex(template, img, 'same');

% display the ncc
H = figure(2); clf;
set(H,'name','NCC can!');
imagesc(ncc);
axis('image'); title('normalized cross correlation');
colormap(gray);

% output where there template was embedded (centered)
fprintf('template was embedded at (%i,%i)\n', embedY+ceil((templateSize-1)/2), embedX+ceil((templateSize-1)/2));

% compute, then output where ncc 'found' the template (the highest score,
% which in this case is +1, since there is no noise)
[t mi] = max(ncc);
[t mj] = max(t);
mi = mi(mj);
fprintf('ncc found it at (%i,%i)\n', mi, mj);
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
code file cv.hcv.h130.28 kB18-08-05 11:04
code file cvabsdiff.cppcvabsdiff.cpp23.17 kB18-08-05 11:04
code file cvalloc.cppcvalloc.cpp4.41 kB18-08-05 11:04
code file cvarithm.cppcvarithm.cpp102.01 kB18-08-05 11:04
code file cvarray.cppcvarray.cpp91.94 kB18-08-05 11:04
code file cvcompat.hcvcompat.h29.95 kB18-08-05 11:04
code file cvconvert.cppcvconvert.cpp70.63 kB18-08-05 11:04
code file cvcopy.cppcvcopy.cpp42.68 kB18-08-05 11:04
code file cvdatastructs.cppcvdatastructs.cpp94.75 kB18-08-05 11:04
code file cvdxt.cppcvdxt.cpp97.92 kB18-08-05 11:04
code file cverror.cppcverror.cpp16.40 kB18-08-05 11:04
code file cverror.hcverror.h9.88 kB18-08-05 11:04
code file cvmathfuncs.cppcvmathfuncs.cpp60.98 kB18-08-05 11:04
code file cvtables.cppcvtables.cpp15.13 kB18-08-05 11:04
code file cvtemplmatch.cppcvtemplmatch.cpp70.33 kB18-08-05 11:04
code file cvtypes.hcvtypes.h46.97 kB18-08-05 11:04
code file _cv.h_cv.h11.32 kB18-08-05 11:04
code file _cvarr.h_cvarr.h5.63 kB18-08-05 11:04
code file _cvdatastructs.h_cvdatastructs.h16.36 kB18-08-05 11:04
code file _cverror.h_cverror.h3.44 kB18-08-05 11:04
code file _cvfuncn.h_cvfuncn.h14.59 kB18-08-05 11:04
code file _cvmatrix.h_cvmatrix.h10.79 kB18-08-05 11:04
code file _cvoptions.h_cvoptions.h3.68 kB18-08-05 11:04
code file _cvtables.h_cvtables.h2.75 kB18-08-05 11:04
code file _cvutils.h_cvutils.h16.12 kB18-08-05 11:04
code file _ipcv.h_ipcv.h60.97 kB18-08-05 11:04
code file _optcv.h_optcv.h28.74 kB18-08-05 11:04
code file linuxBuildReadme.txtlinuxBuildReadme.txt52.00 B18-08-05 11:15
code file MakefileMakefile114.00 B20-12-05 19:28
code file normxcorr2_demo.mnormxcorr2_demo.m1.46 kB21-12-05 22:19
code file normxcorr2_mex.cppnormxcorr2_mex.cpp3.03 kB21-12-05 21:50
源码文件 normxcorr2_mex.dllnormxcorr2_mex.dll140.00 kB21-12-05 21:50
code file normxcorr2_mex.mnormxcorr2_mex.m1.66 kB20-12-05 18:58
源码文件 normxcorr2_mex.mexglxnormxcorr2_mex.mexglx314.83 kB21-12-05 22:38
源码文件 normxcorr2_mex.mexsolnormxcorr2_mex.mexsol419.14 kB21-12-05 22:38
源码文件 normxcorr2_mex.mexw64normxcorr2_mex.mexw64197.50 kB17-01-08 08:33
code file README.txtREADME.txt1.25 kB17-06-05 10:03
code file sunBuildReadme.txtsunBuildReadme.txt744.00 B20-12-05 19:24
源码文件 mexFunction.defmexFunction.def224.00 B19-04-05 10:11
源码文件 mpisearchmex.dspmpisearchmex.dsp6.35 kB20-12-05 19:13
源码文件 mpisearchmex.dswmpisearchmex.dsw547.00 B19-04-05 10:11
源码文件 mpisearchmex.ncbmpisearchmex.ncb257.00 kB20-12-05 19:31
源码文件 mpisearchmex.optmpisearchmex.opt47.50 kB20-12-05 19:31
源码文件 mpisearchmex.plgmpisearchmex.plg3.65 kB20-12-05 19:31
源码文件 mpisearchmex.slnmpisearchmex.sln913.00 B04-07-05 11:11
源码文件 mpisearchmex.suompisearchmex.suo8.00 kB04-07-05 11:11
源码文件 mpisearchmex.vcprojmpisearchmex.vcproj14.95 kB04-07-05 11:11
源码文件 <Release><Release>0.00 B20-12-05 15:38
源码文件 <cv_src><cv_src>0.00 B20-12-05 15:38
源码文件 <windows><windows>0.00 B20-12-05 19:32
源码文件 <ncc><ncc>0.00 B01-04-09 12:33
...
Sponsored links
×

normxcorr2_demo.m (569.13 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

×

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com
×

切换到中文版?

CodeForge Chinese Version
CodeForge English Version
×

Where are you going?

×

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK
×

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D