关于matlab的svm代码不懂,请教大神

BePilgrim 2016-11-04 10:47:08
% Version : 1.0
% Date : 12.26.2010
% Author : Omid Sakhi
% http://www.facedetectioncode.com

function im_out = imscan (net,im)

close all

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% PARAMETERS
SCAN_FOLDER = 'imscan/';
UT_FOLDER = 'imscan/under-thresh/';
TEMPLATE1 = 'template1.png';
TEMPLATE2 = 'template2.png';
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


warning off;
delete ([UT_FOLDER,'*.*']);
delete ([SCAN_FOLDER,'*.*']);

[m n]=size(im);

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% First Section
C1 = mminmax(double(im));
C2 = mminmax(double(imread (TEMPLATE1)));
C3 = mminmax(double(imread (TEMPLATE2)));
Corr_1 = double(conv2 (C1,C2,'same'));
Corr_2 = double(conv2 (C1,C3,'same'));
Cell.state = int8(imregionalmax(Corr_1) | imregionalmax(Corr_2));
Cell.state(1:13,:)=-1;
Cell.state(end-13:end,:)=-1;
Cell.state(:,1:9)=-1;
Cell.state(:,end-9:end)=-1;
Cell.net = ones(m,n)*-1;
[LUTm LUTn]= find(Cell.state == 1);
imshow(im);
hold on
plot(LUTn,LUTm,'.y');pause(0.01);

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Second Section
xo = [-1,-1,-1, 0, 0,+1,+1,+1]; %offset
yo = [-1, 0,+1,-1,+1,-1, 0,+1]; %offset
while (1==1)
[y, x] = find(Cell.state==1,1);
if isempty(y)
break;
end
imcut = im(y-13:y+13,x-9:x+8);
Cell.state(y,x) = -1;
Cell.net(y,x) = svmclassify(net,im2vec(imcut)');
if (Cell.net(y,x) == 1)
plot(x,y,'.g');pause(0.01);
for k=1:8
nx = x + xo(k);
ny = y + yo(k);
if (Cell.state(ny,nx) ~= -1)
Cell.state(ny,nx) = 1;
end
end
else
plot(x,y,'.r');pause(0.01);
end
end

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Third Section
hold off
figure;imshow (Cell.net,[]);
xy_ = Cell.net > 0;
xy_ = imregionalmax(xy_);
xy_ = imdilate (xy_,strel('disk',2,4));
[LabelMatrix,nLabel] = bwlabeln(xy_,4);
CentroidMatrix = regionprops(LabelMatrix,'centroid');
xy_ = zeros(m,n);
for i = 1:nLabel
xy_(fix(CentroidMatrix(i).Centroid(2)),...
fix(CentroidMatrix(i).Centroid(1))) = 1;
end
xy_ = drawrec(xy_,[27 18]);
im_out (:,:,1) = im;
im_out (:,:,2) = im;
im_out (:,:,3) = im;
for i = 1:m
for j=1:n
if xy_(i,j)==1
im_out (i,j,1)=0;
im_out (i,j,2)=255;
im_out (i,j,3)=0;
end
end
end
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function out = drawrec (in,w)

[m n]=size(in);
[LUTm LUTn]=find(in);
out = zeros (m,n);
for i =1:size(LUTm,1)
try
out (LUTm(i),LUTn(i))=0;
end
try
out (LUTm(i)-14:LUTm(i)+13,LUTn(i)-9)=1;
end
try
out (LUTm(i)-14:LUTm(i)+13,LUTn(i)+8)=1;
end
try
out (LUTm(i)-14,LUTn(i)-9:LUTn(i)+8)=1;
end
try
out (LUTm(i)+13,LUTn(i)-9:LUTn(i)+8)=1;
end
end
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function output = mminmax(input)

max_ = max(max(input));
min_ = min(min(input));

output = ((input-min_)/(max_-min_) - 0.5) * 2;
...全文
467 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
BePilgrim 2016-11-07
  • 打赏
  • 举报
回复
求教求教,新手,困顿中
BePilgrim 2016-11-07
  • 打赏
  • 举报
回复
state 和net的关系是什么?
BePilgrim 2016-11-07
  • 打赏
  • 举报
回复
请教im2vec的函数功能

4,446

社区成员

发帖
与我相关
我的任务
社区描述
图形图像/机器视觉
社区管理员
  • 机器视觉
  • 迪菲赫尔曼
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧