1 ;
2 Matlab ; 3; 4(); 5 11-5( );(:)
1
2
345 2;
3()
( )
1. ()
:
:;
f (x, y)() f (x, y)
T:f(x,y)>Tg(x,y)=0()
f(x,y)Tg(x,y)=1 ()
Matlab ():
I=imread(xl-130-16.tiff);
f=rgb2gray(I); % g=zeros(size(f));
id=f <= T;g(id)=1;2 (Matlab ) 3. k-meansEM mean-shift 4. () : A B ( B ) B A : A B A B A B AB matlab:se=strel(disk,3); % A1=imdilate(A,se); % (A) matlab:se=strel(disk,10); % (10520)A2=imerode(A,se); % () A B A B ,A B B :A B = ( AB) BA B A B ,A B = ( A B)B matlab: se=strel(square,20); fo=imopen(A,se); figure,imshow(fo);title() fc=imclose(f,se); figure,imshow(fc);title() imfill(): BW2 = imfill(A, ‘holes’); : L=bwlabel(A); % A figure,map=[0 0 0;jet(10)];imshow(L+1,map);5. 6. Robert Sobel Prewitt LoG Canny Matlab :edge( [, edge ] [, ]) edge(img, ‘sobel’); edge ‘sobel’, ‘prewitt’, ‘log’, ‘roberts’, ‘canny’1 MATLAB ;2 ; 3 ;4 1 ;2 MATLAB ;3 (U ) 4 1 ;2 ;3 ;4 : A41.25 (:+()+()+ 1. 2. 1 MATLABimreadavireadmmreader;2 ;2 MATLAB;3 strel 1. tic;clear allmov = mmreader(‘???.avi’);x = read(mov,2);fr_size = size(x);width = fr_size(2);height = fr_size(1);c =zeros(height, width);for k=1:mov.NumberOfFrames-1x = read(mov,k);y = read(mov,k+1);m = rgb2gray(x);n = rgb2gray(y);q=im2double(n); w=im2double(m);c=qw ;t=40; %% t=t/255;%%double id = c > t;
cc =zeroes(fr_size);
cc(id) = 1; figure(1),subplot(2,2,1),imshow(m) subplot(2,2,2),imshow(n)
% 1
subplot(2,2,3),imshow(c) figure(2),imshow(cc) ;
Mov1(k) = im2frame(uint8(cc),gray);
end movie2avi(Mov1,fd_output,fps,15);
% put frames into movie
2.
2.1
% This M-file uses average model for background pixels clear all;
N = 40;% N frames to train the Gaussian model
h = fspecial(gaussian);
imagedata = filter2(h,rgb2gray(imread(****.bmp))); mu = imagedata;
[m,n] = size(mu);
pro = zeros(m,n);
for i=1:N
%
filename = sprintf(******/0%d.bmp,i); % tmp =filter2(h,rgb2gray(imread(filename)));
mu = mu+tmp;%(tmp+(i-1)*sav_mu)./i;%
end;
mu=mu./N; figure(1),imshow(uint8(mu)); % test the new frame
for num = N+1:500
filename = sprintf(**********/0%d.bmp,num); imagedata = filter2(h,rgb2gray(imread(filename)));
t=20; %
pro = abs(imagedata-mu)> t; imshow(pro),title(sprintf(frame number %d,floor(num))); %%update mean
mu = (mu*(num-1) +imagedata)/num; %(1-a)*mu+a*(imagedata-mu);
% display the results
Mov1(num-N) = im2frame(uint8(255*pro),gray); % put frames into movie
end;
movie2avi(Mov1,ave_output_20,fps,15);
2.2
% This M-file uses single Gaussian model for background pixels
clear all;
N = 40;% N frames to train the Gaussian model
h = fspecial(gaussian);
imagedata = filter2(h,rgb2gray(imread(*****.bmp))); mu = imagedata;
[m,n] = size(mu);
cov = zeros(m,n);
pro = zeros(m,n);
sav_mu = mu;
a = 0.01;
%
for i=1:N
filename = sprintf(***/0%d.bmp,i);
tmp =filter2(h,rgb2gray(imread(filename)));
mu = (tmp+(i-1)*sav_mu)./i;
cov = ((tmp-mu).^2+(i-1)*cov)./(i)+(mu-sav_mu).^2; sav_mu = mu;
end;
cov = cov+0.001; %cov0
% test the new frame for num = N+1:500
filename = sprintf(vipman_bmp/0%d.bmp,num);
imagedata = double(filter2(h,rgb2gray(imread(filename))));
T=1e-3; %
pro = (2*pi)^(-1/2)*exp(-0.5*(imagedata-mu).^2./cov)./sqrt(cov)< T;%% update covariance and meanmu = mu +a*(1-pro).*(imagedata-mu); %(1-a)*mu+a*(imagedata-mu);cov = cov + a*(1-pro).*((imagedata-mu).^2-cov);%(1-a)*cov+a*(imagedata-mu).^2; % display the resultsimshow(mat2gray(pro)),title(sprintf(‘frame number %d’,floor(num))); Mov1(num-N) = im2frame(uint8(255*pro),gray); % put frames into movie pause(0.000001);%end; movie2avi(Mov1,’gaussian_output’,’fps’,15);2.3 () () 1 MATLAB ;2 ; 3 ;4 ;3 1 ;2 MATLAB ;3 (U ) 4 1 ;2 ;3 : A41.25 (:+()+()+ .1. text + Harr-cascade ;1 ;2 Matlab 1 :(1) ;(2) ;(3) 1.1 HSV HSV HSV – 3-1 HS HS HmaxH min 3-1 HS 3-1 HS Smin =0.23,Smax =0.68,Hmin =0,Hmax =50:files=dir(‘*.jpg’); for i=1:length(files)s=files(i).name; I=imread(s);Smin SmaxI1=rgb2hsv(I);h=I1(:,:,1);s=I1(:,:,2);id = s > 0.23 & s < 0.68 & h > 0 & h < 50; figure,subplot(2,1,1),imshow(I), subplot(2,1,2),imshow(id)end1.2 YCbCr YCbCr : x = (Cb,Cr)T :p(x)=1 exp1(xm)T 1(xm) 212 2 m = (Cb,Cr)T = Cb,Cb Cb,Cr Cr,Cb Cr,Cr :Cb =117.44Cr =157.56Cb,Cb = 299.46Cb,Cr =12.14Cr,Cb =12.14Cr,Cr =160.13files=dir(‘*.jpg’); for i=1:length(files)s=files(i).name;I=imread(s);I=imresize(I,0.1);I1=rgb2ycbcr(I);I1=double(I1);cb=I1(:,:,2);cr=I1(:,:,3);mu=[117.44 157.56]’;sig=[299.46 12.14;12.14 160.13]; p=drawGaussian(mu,sig,cb(:),cr(:));p=reshape(p,size(cb)); figure(1),subplot(2,2,1),imshow(I), subplot(2,2,2),imshow(p)p1 = p > 0.5; subplot(2,2,3),imshow(p1);
end
1.3
bwlabel
:
bwopen
bwclose bwareaopen bwlabel
2 Harr-cascade
Adaboost Adaboost
Adaboost ()
MATLAB Computer Vision System Toolbox ()( ):
% Create a cascade detector object. faceDetector = vision.CascadeObjectDetector();
Read an image
I = imread(face.jpg); I=im2double(I);
bbox = step(faceDetector, I);
% Draw the returned bounding box around the detected face.
boxInserter = vision.ShapeInserter(BorderColor,Custom, CustomBorderColor,[255 255 0]); J = step(boxInserter, I,bbox);
figure, imshow(J), title(Detected face);
1 MATLAB ;
2 ;
3
4
1 Windows XP 2 Matlab2012b
3
4 (U ) 5
1 ;
2 ;
3 4
1 matlab
:
1 PCA
2
3 matlab :
1 PCA()
PCA : K-L
PCA ; ; PCA
1 MATLAB ;
2 400 (40 10 )
:
(1) 5/8 5/2
() (2) 30/38 10/2 5/8 5/2 (
)
:
clear;
n = 1; p=1;
for i=1:40
a=1:10;
Ind = a(:,randperm(size(a,2))); for h = 1:5
j= Ind(1,h); File=[C:UsersdellDesktopORLs,sprintf(%d,i),,sprintf(%d,j),.pgm]; Filesave=[C:UsersdellDesktop
ew,sprintf(%d,1),,sprintf(%03d,n),.pgm];
copyfile(File,Filesave)
n = n + 1; end
for h = 6:10
j= Ind(1,h);
File=[C:UsersdellDesktopORLs,sprintf(%d,i),,sprintf(%d,j),.pgm]; Filesave=[C:UsersdellDesktop
ew,sprintf(%d,2),,sprintf(%03d,p),.pgm]; copyfile(File,Filesave)
p = p + 1;
end end
3
1 N 200
X = [x1 x2 x200 ]
2200X
1 200
x = 200 xi x = x x
i=1
X=[x1 x2 x200 ]
3
:
% path = uigetdir;
img_path = dir(strcat(path,*.pgm)); img_num = length(img_path); imagedata = [];
if img_num >0
for j = 1:img_num
img_name = img_path(j).name;
temp = imread(strcat(path, /, img_name)); temp = double(temp(:));
imagedata = [imagedata, temp];
end
end
wts = size(imagedata,2);
% img_pj = mean(imagedata,2); for i = 1:wts
imagedata(:,i) = imagedata(:,i) img_pj; end
covMat = imagedata*imagedata;
4
:
%:[PC,latent,explained]=pcacov(X) X (PC)% X (latent) %(explained)
[COEFF, latent, explained] = pcacov(covMat); % 95%
i = 1;
proportion = 0;
while(proportion < 95)proportion = proportion + explained(i); i = i+1;endk = i – 1;%V = imagedata*COEFF; % N*M V = V(:,1:k);% PCA k*MW = V’*imagedata;msgbox([”])5 PCA :im=imread(test_face.jpg);im = double(im(:));objectone = V’*(im – imgpj);distance = 1e8; for k = 1:wtstemp(k) = norm(objectone – W(:,k)); end[s_temp,id]=sort(temp,ascend);6 () % 5 1 ;2 MATLAB ;3 (U )4 1 5 ;2 ; 3 ;4 1 Matlab GUI
Reviews
There are no reviews yet.