I need help in matching of test image with the database image

1 次查看(过去 30 天)
clc; clear all; close all; tic; format LONG I = imread('E:\8th sem project\numbers and alphabets images database\two.jpg'); bwim1=adaptivethreshold(I,11,0.03,0); % adaptive thresholding of the image imwrite(bwim1,'new.png','bitdepth',1); I5 = imread('new.png'); %imtool(I) %b = bwtraceboundary(I,[273, 13],'S') %[x,y] = bwboundaries(I,8) [x,y] = find(I5 == 0); xr = round(x); yr = round(y); %l = length(x); l = 11; xc = sum(x)/l; yc = sum(y)/l; % Resizing of the image. % I6 = imresize(I,[120,120]); % imwrite(I6,'neww.jpg'); % I7 = imread('neww.jpg'); grayi = rgb2gray(I); for t = 1:l r(t) = sqrt((x(t) - xc)^2 + (y(t) - yc)^2); idx(t) = sub2ind(size(grayi),xr(t),yr(t)); g(t) = grayi(idx(t)); %g(t) = grayi(xr(t),yr(t)); phi(t) = double(r(t)*g(t));
end
for n = 1:l-1 b = 0; for t = 1:l b(t) = (phi(t).*exp(-2*j*pi*n*(t)/l)); end a(n) = sum(b)/l; a(l) = sum(r); s(n) = abs(a(n))/a(l); end S = s(1:10);
len = 0;
s1 = 0;
x1 = 0;
y1 = 0;
i =2;
minm = 0;
mi = 1;
srcFiles2 = dir('E:\8th sem project\Adaptive thresholding\Attachments_201555\*.png');
for k = 1:length(srcFiles2)
filename = strcat('E:\8th sem project\Adaptive thresholding\Attachments_201555\',srcFiles2(k).name);
I1 = imread(filename);
[x1,y1] = find(I1 == 0);
xr1 = round(x1);
yr1 = round(y1);
%len = length(x1);
len = 11;
xc1 = sum(x1)/len;
yc1 = sum(y1)/len;
srcFiles3 = dir('E:\8th sem project\Adaptive thresholding\ORIGINAL\*.jpg'); for k1 = 1:length(srcFiles3) filenames = strcat('E:\8th sem project\Adaptive thresholding\ORIGINAL\',srcFiles3(k1).name); I51 = imread(filenames); grayi1 = rgb2gray(I51);
for t1 = 1:len r1(t1) = sqrt((x1(t1) - xc1)^2 + (y1(t1) - yc1)^2); idx1 = sub2ind(size(grayi1),xr1(t1),yr1(t1)); g1(t1) = grayi1(idx1); phi1(t1) = double(r1(t1)*g1(t1));
end
for n1 = 1:len-1 b1 = 0; for t1 = 1:len b1(t1) = (phi1(t1).*exp(-2*j*pi*n1*(t1)/l)); end a1(n1) = sum(b1)/len; a1(len) = sum(r1);%supposed to be a(0) but matlab doesn't allow 0 to be as the index value. %a(n) = [sum(phi(1:l)*exp(-2*j*3.14*n*(1:l)/l))]/l; s1(n) = abs(a1(n1))/a1(len); end S1 = s1(1:10);
D(k) = sqrt(sum((S - S1).^2))
if (k==1)
minm = D(k);
else
m(i) = D(k);
end
if (k>1)
if(m(i) < minm)
minm = m(i);
mi = k;
end
end
i = i +1;
a1 = 0;
end
end
minimum = min(D)
%f = find(min(D))
disp(srcFiles2(mi).name)
toc
This is my entire code.
But it is incorrectly matching.
For one as the test image input, i got six as the output.
Please help me improvise this.
I have 6 images per gesture in my database and saved after adaptive thresholding.
function bw=adaptivethreshold(IM,ws,C,tm) %ADAPTIVETHRESHOLD An adaptive thresholding algorithm that seperates the %foreground from the background with nonuniform illumination. % bw=adaptivethreshold(IM,ws,C) outputs a binary image bw with the local % threshold mean-C or median-C to the image IM. % ws is the local window size. % tm is 0 or 1, a switch between mean and median. tm=0 mean(default); tm=1 median. % % Contributed by Guanglei Xiong (<mailto:xgl99@mails.tsinghua.edu.cn xgl99@mails.tsinghua.edu.cn>) % at Tsinghua University, Beijing, China. % % For more information, please see % http://homepages.inf.ed.ac.uk/rbf/HIPR2/adpthrsh.htm
if (nargin<3) error('You must provide the image IM, the window size ws, and C.'); elseif (nargin==3) tm=0; elseif (tm~=0 && tm~=1) error('tm must be 0 or 1.'); end
IM=mat2gray(IM);
if tm==0 mIM=imfilter(IM,fspecial('average',ws),'replicate'); else mIM=medfilt2(IM,[ws ws]); end sIM=mIM-IM-C; bw=im2bw(sIM,0); bw=imcomplement(bw); bw = imresize(bw,[120,120]); imwrite(bw,'bwi.png'); bw = imread('bwi.png');
This is my adaptive thresholding code. Please reply as soon as possible. Thanking you.

回答(1 个)

Cindy Solomon
Cindy Solomon 2015-5-7
Hi Pooja,
Please follow the MATLAB Answers guidelines for asking good questions.
Specifically, please post a substantial question in comprehensible English that is brief, complete, and clear with formatted code.
If this is related to homework, please also see this page as well for clarification on how to get help on homework questions.
  2 个评论
Joseph Cheng
Joseph Cheng 2015-5-7
编辑:Joseph Cheng 2015-5-7
Those links should be incorporated as a disclaimer when posting question. I keep loosing the links to those pages.
Image Analyst
Image Analyst 2015-5-7
I've made all the usual such links bookmarks so I can access them easily.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by