function BW=refine_face_detection(I)
I1=I;
R=I1(:,:,1);
G=I1(:,:,2);
B=I1(:,:,3);
Y=0.299*R+0.587*G+0.114*B;
Cb=-0.1687*R-0.3313*G+0.5000*B+128;
for Cb=133:165
r=(Cb-128)*1.402+Y;
r1=find(R==r);
R(r1)=255;
G(r1)=255;
B(r1)=255;
end
I1(:,:,1)=R;
I1(:,:,2)=G;
I3(:,:,3)=B;
J=im2bw(I1,0.99);
SE1=strel('square',8);
BW1=imdilate(J,SE1);
BW1 = imfill(BW1,'holes');
SE1=strel('square',20);
BW1=imerode(BW1,SE1);
SE1=strel('square',12);
BW1=imdilate(BW1,SE1);
[B,L,N]=bwboundaries(BW1,'noholes');
a=zeros(1,N);
for i1=1:N
a(i1)=length(find(L==i1));
end
a1=find(a==max(a));
L1=(abs(L-a1))*255;
I2=double(rgb2gray(I));
I3=uint8(I2-L1);
BW=double(I3);
这个是调用函数
clear all;
close all;
clc;
B=imread('3.jpg');
C=imread('4.jpg');
BW1=refine_face_detection(B);
BW2=refine_face_detection(C);
set(0,'defaultFigurePosition',[100,100,1200,450]);
set(0,'defaultFigureColor',[1 1 1])
figure,
subplot(121),imshow(BW1);
subplot(122),imshow(BW2);
这个是主函数
为什么我运行不了,然后出现红色语句的报错
I1=I;
R=I1(:,:,1);
G=I1(:,:,2);
B=I1(:,:,3);
Y=0.299*R+0.587*G+0.114*B;
Cb=-0.1687*R-0.3313*G+0.5000*B+128;
for Cb=133:165
r=(Cb-128)*1.402+Y;
r1=find(R==r);
R(r1)=255;
G(r1)=255;
B(r1)=255;
end
I1(:,:,1)=R;
I1(:,:,2)=G;
I3(:,:,3)=B;
J=im2bw(I1,0.99);
SE1=strel('square',8);
BW1=imdilate(J,SE1);
BW1 = imfill(BW1,'holes');
SE1=strel('square',20);
BW1=imerode(BW1,SE1);
SE1=strel('square',12);
BW1=imdilate(BW1,SE1);
[B,L,N]=bwboundaries(BW1,'noholes');
a=zeros(1,N);
for i1=1:N
a(i1)=length(find(L==i1));
end
a1=find(a==max(a));
L1=(abs(L-a1))*255;
I2=double(rgb2gray(I));
I3=uint8(I2-L1);
BW=double(I3);
这个是调用函数
clear all;
close all;
clc;
B=imread('3.jpg');
C=imread('4.jpg');
BW1=refine_face_detection(B);
BW2=refine_face_detection(C);
set(0,'defaultFigurePosition',[100,100,1200,450]);
set(0,'defaultFigureColor',[1 1 1])
figure,
subplot(121),imshow(BW1);
subplot(122),imshow(BW2);
这个是主函数
为什么我运行不了,然后出现红色语句的报错