{"id":576,"date":"2013-04-08T23:38:20","date_gmt":"2013-04-09T02:38:20","guid":{"rendered":"http:\/\/www.taioque.com.br\/?p=576"},"modified":"2013-05-30T18:43:45","modified_gmt":"2013-05-30T21:43:45","slug":"script-matlab-usando-fuzy-e-chi-quadrado-para-reconhecimento-facial","status":"publish","type":"post","link":"http:\/\/www.networktips.com.br\/?p=576","title":{"rendered":"Script &#8211; Matlab usando Fuzzy e chi-quadrado para reconhecimento facial"},"content":{"rendered":"<div style=\"padding-bottom:20px; padding-top:10px;\" class=\"hupso-share-buttons\"><!-- Hupso Share Buttons - https:\/\/www.hupso.com\/share\/ --><a class=\"hupso_toolbar\" href=\"https:\/\/www.hupso.com\/share\/\"><img src=\"http:\/\/static.hupso.com\/share\/buttons\/dot.png\" style=\"border:0px; padding-top: 5px; float:left;\" alt=\"Share Button\"\/><\/a><script type=\"text\/javascript\">var hupso_services_t=new Array(\"Twitter\",\"Facebook\",\"Google Plus\",\"Linkedin\",\"Email\");var hupso_background_t=\"#EAF4FF\";var hupso_border_t=\"#66CCFF\";var hupso_toolbar_size_t=\"medium\";var hupso_image_folder_url = \"\";var hupso_twitter_via=\"jorgeltaioque\";var hupso_url_t=\"\";var hupso_title_t=\"Script%20-%20Matlab%20usando%20Fuzzy%20e%20chi-quadrado%20para%20reconhecimento%20facial\";<\/script><script type=\"text\/javascript\" src=\"http:\/\/static.hupso.com\/share\/js\/share_toolbar.js\"><\/script><!-- Hupso Share Buttons --><\/div><pre lang=\"php\" line=\"1\">\r\n%limpando variaveis e terminal.\r\n%cleaning the variables and terminal\r\nclear all;\r\nclose all;\r\nclc;\r\n\r\n%inicia contador de tempo\r\n%start counter of time\r\ntic;\r\n\r\n%procura imagem inicial\r\n%Search initial image\r\nimagefiles = dir('*.pgm');      \r\nnfiles = length(imagefiles);  \r\n\tforResult = zeros(1,nfiles);\r\n\ty = randi([1, nfiles]);\r\n\t\r\n\tfor ii=1:nfiles\r\n\t\tif (ii == y)\r\n\t\tcurrentfilename = imagefiles(ii).name;\r\n\t\tinputImage = imread(currentfilename);\r\n\t\timages{ii} = inputImage;\r\n\t\tend\r\n\tend\r\n\r\n\r\n\t\tinputImage=inputImage;\r\n\t\tdiferente = currentfilename;\r\n\r\n%seta tamanho da janela de verifica\u00e7\u00e3o\r\n%set window size\r\nwindowSize=3;\r\n\r\ninputImage=inputImage;\r\n\r\n%executa fun\u00e7\u00e3o fuzy\r\n%execuit function fuzy\r\nres = fuzy(inputImage, windowSize, 0.950);\r\n\r\n% 0.950 melhor valor que encontrei para fuzy\r\n\r\n\r\n%pega parametros da imagen para criar histograma\r\n%get parameters of image to create histogram\r\nlarg = size(res,2) ;\r\nalt  = size(res,1) ;\r\nminimo = min(min(res)) ;\r\nmaximo = max(max(res)) ;\r\nimg_contraste = 255 * ( double(res - minimo) \/ double(maximo - minimo) );\r\n\r\nhistograma = zeros(1,256) ;\r\n\r\n%criando histograma\r\n%creating histegram\r\nfor i = 1 : alt\r\n    for j = 1 : larg\r\n        histograma(floor(img_contraste(i,j)+1)) = histograma(floor(img_contraste(i,j)+1)) + 1 ;\r\n    end\r\nend\r\n\r\n\t%calculando histograma\r\n\t%calculating histogram\r\n\tresultado1 = sum(histograma);\r\n\t\r\n\t%mostra resultados na janela figura\r\n\t%show results in window figure\r\n\tfigure,\r\n\tsubplot(2,3,1); plot(1:256,histograma,'-b');\r\n\ttitle('Histograma Original');\r\n\tsubplot(2,3,3); imshow(inputImage);\r\n\ttitle('Imagem Original');\r\n\tdrawnow \r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\t%procura imagen canditada \r\n\t%Search image candidate\r\n\timagefiles = dir('*.pgm');      \r\n\tnfiles = length(imagefiles); \r\n\t\r\n\t%Vector of results\r\n\t%Vetor de resultados\r\n\tforResult = zeros(1,nfiles);\r\n\tresultchi = 999999999999999;\r\n\t\r\n\tfor ii=1:nfiles\r\n\r\n\tcurrentfilename = imagefiles(ii).name;\r\n\r\n\tz = strcmp( currentfilename, diferente );\r\n\tif (z==0)\r\n\r\n\tinputImage2 = imread(currentfilename);\r\n\timages{ii} = inputImage2;\r\n\r\n\r\nwindowSize=3;\r\n\r\ninputImage2=inputImage2;\r\n\r\n\r\n%executando fun\u00e7\u00e3o fuzy\r\n%running fuzy function\r\nres2 = fuzy(inputImage2, windowSize, 0.950);\r\n\r\n%pega parametros do fuzy para criar histograma\r\n%get parameters of fuzy to create histogram\r\nlarg = size(res2,2) ;\r\nalt  = size(res2,1) ;\r\nminimo = min(min(res2)) ;\r\nmaximo = max(max(res2)) ;\r\nimg_contraste2 = 255 * ( double(res2 - minimo) \/ double(maximo - minimo) );\r\n\r\nhistograma2 = zeros(1,256) ;\r\n\r\n%criando histograma\r\n%creating histegram\r\nfor i = 1 : alt\r\n    for j = 1 : larg\r\n        histograma2(floor(img_contraste2(i,j)+1)) = histograma2(floor(img_contraste2(i,j)+1)) + 1 ;\r\n    end\r\nend\r\n\r\n\t%calculando chi-quadrado\r\n\t%calculating chi-square\r\n\treschi = sum((histograma - histograma2).^2);\r\n\t\r\n\t%vetor para resultados do chi\r\n\t% Vector for results of chi\r\n\tforResult(ii) = reschi;\r\n\t\r\n\t%procura menor resultado do chi\r\n\t%search menor result of chi\r\n\tif ( reschi < resultchi )\r\n\tresultchi = reschi;\r\n\treshistograma = histograma2;\r\n\tresresultado = res2;\r\n\tresimage = inputImage2;\r\n\tend \r\n\r\n\t\r\n\tsubplot(2,3,4); plot(1:256,histograma2,'-b');\r\n\ttitle('Histograma');\r\n\tsubplot(2,3,6); imshow(inputImage2);\r\n\ttitle('Imagem Candidata');\r\n\tdrawnow \r\n\tii\r\n\r\n\tend\r\nend\r\n\r\n\t%mostra resultado\r\n\t%show result\r\n\tsubplot(2,3,4); plot(1:256,reshistograma,'-b');\r\n\ttitle('RESULTADO');\r\n\tsubplot(2,3,6); imshow(resimage);\r\n\ttitle('RESULTADO');\r\n\tdrawnow \r\n\r\n\r\n%mostra tempo de procesamento\r\n%show processing time\r\ntime=toc;\r\ntime\r\n<\/pre>\n<p>Fun\u00e7\u00e3o fuzy<\/p>\n<pre lang=\"php\" line=\"1\" escaped=\"true\">\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n% LFP - Local Fuzzy Pattern\r\n%\r\n% Input arguments:\r\n% img - Gray scale image.\r\n% neighborSize - number of sample point in an square window.\r\n% beta - pertinence function argument.\r\n%\r\nfunction result = LFP(img, neighborSize, beta)\r\nif neighborSize < 3 || floor(neighborSize\/2) == 0\r\nerror('A vizinhan\u00e7a deve ser um n\u00famero \u00edmpar maior ou igual a 3!');\r\nend;\r\nimg = double(img);\r\n% Tamanho da imagem original\r\n[ysize xsize] = size(img);\r\nif(xsize < neighborSize || ysize < neighborSize)\r\nerror('Imagem muito pequena. Deve ter pelo menos o tamanho da janela.');\r\nend\r\n% weightMatrix = [1 1 1 1 1; 1 1 1 1 1; 1 1 1 1 1; 1 1 1 1 1; 1 1 1 1 1];\r\nweightMatrix = [1 1 1; 1 1 1; 1 1 1]; %matriz de pesos 1\r\n%weightMatrix = [1 1 1; 1 0 1; 1 1 1]; %matriz de pesos 2\r\nborder = fix(neighborSize\/2);\r\ndataMatrix = img(2*border : ysize - border, 2*border : xsize - border);\r\n[matrixSizeY matrixSizeX] = size(dataMatrix);\r\npertinenceSum = zeros(matrixSizeY, matrixSizeX);\r\nweightSum = 0;\r\nfor i = 1 : neighborSize\r\nfor j = 1 : neighborSize\r\nweight = weightMatrix(i, j);\r\nwindowData = img(i : (i+matrixSizeY) - 1, j : (j+matrixSizeX) - 1);\r\nexpData = windowData - dataMatrix;\r\npert = 1.\/(1 + exp(-expData\/beta));\r\npertinenceSum = pertinenceSum + (pert * weight);\r\nweightSum = weightSum + weight;\r\nend;\r\nend;\r\nresult = pertinenceSum \/ weightSum;\r\n\r\n<\/pre>\n<p><iframe width=\"584\" height=\"329\" src=\"http:\/\/www.youtube.com\/embed\/CWerXxo8gvA?feature=oembed\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<div style=\"padding-bottom:20px; padding-top:10px;\" class=\"hupso-share-buttons\"><!-- Hupso Share Buttons - https:\/\/www.hupso.com\/share\/ --><a class=\"hupso_toolbar\" href=\"https:\/\/www.hupso.com\/share\/\"><img src=\"http:\/\/static.hupso.com\/share\/buttons\/dot.png\" style=\"border:0px; padding-top: 5px; float:left;\" alt=\"Share Button\"\/><\/a><script type=\"text\/javascript\">var hupso_services_t=new Array(\"Twitter\",\"Facebook\",\"Google Plus\",\"Linkedin\",\"Email\");var hupso_background_t=\"#EAF4FF\";var hupso_border_t=\"#66CCFF\";var hupso_toolbar_size_t=\"medium\";var hupso_image_folder_url = \"\";var hupso_twitter_via=\"jorgeltaioque\";var hupso_url_t=\"\";var hupso_title_t=\"Script%20-%20Matlab%20usando%20Fuzzy%20e%20chi-quadrado%20para%20reconhecimento%20facial\";<\/script><script type=\"text\/javascript\" src=\"http:\/\/static.hupso.com\/share\/js\/share_toolbar.js\"><\/script><!-- Hupso Share Buttons --><\/div><p>%limpando variaveis e terminal. %cleaning the variables and terminal clear all; close all; clc; %inicia contador de tempo %start counter of time tic; %procura imagem inicial %Search initial image imagefiles = dir(&#8216;*.pgm&#8217;); nfiles = length(imagefiles); forResult = zeros(1,nfiles); y = &hellip; <a href=\"http:\/\/www.networktips.com.br\/?p=576\">Continue lendo <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1135,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"http:\/\/www.networktips.com.br\/index.php?rest_route=\/wp\/v2\/posts\/576"}],"collection":[{"href":"http:\/\/www.networktips.com.br\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.networktips.com.br\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.networktips.com.br\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.networktips.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=576"}],"version-history":[{"count":8,"href":"http:\/\/www.networktips.com.br\/index.php?rest_route=\/wp\/v2\/posts\/576\/revisions"}],"predecessor-version":[{"id":605,"href":"http:\/\/www.networktips.com.br\/index.php?rest_route=\/wp\/v2\/posts\/576\/revisions\/605"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.networktips.com.br\/index.php?rest_route=\/wp\/v2\/media\/1135"}],"wp:attachment":[{"href":"http:\/\/www.networktips.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.networktips.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=576"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.networktips.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}