图片处理的一些记录(matlab)

主要的任务是将人从背景里面提取出来然后放进新背景里面。

clear;
close all;

orl_img=imread('C:\图像库\人脸库\ORL\faceJpg\s2\1.jpg');
bg_img=imread('C:\图像库\backgrounds\10.tiff');
% imshow(bg_img);

%orl_img = imresize(orl_img,[56,46]);
% orl_img = imresize(orl_img,[84,69]);

[a b] = size(orl_img);
temp_r =zeros(a,b);
u = 60;
l = 200;
temp3 = bg_img(u:u+139,l:l+139);
%temp2 = temp3(29:140,25:116);
temp2 = temp3(1:112,1:92);%11-1
% temp2 = temp3(1:112,49:140);%11-2
% temp2 = temp3(29:140,1:92);%11-3
% temp2 = temp3(29:140,49:140);%11-4
% temp2 = temp3(1:56,1:46);%12-1
% temp2=temp3(1:84,1:69);%34-1
% temp2 = temp3(85:140,95:140);%12-4
% temp2 = temp3(1:56,95:140);%12-2
%temp2 = temp3(1:84,72:140);%34-2
% temp2 = temp3(85:140,1:46);%12-3
% temp2=temp3(57:140,1:69);%34-3
% temp2=temp3(57:140,72:140);%34-4

% figure(6);
% imshow(temp3);
%imwrite(temp3,'C:\Users\GUOPENG\Desktop\fixed1_1.tiff','tiff');

Px=[-1 0 1;-2 0 2;-1 0 1];  %sobel算子
Py=[-1 -2 -1;0 0 0;1 2 1];
for i= 1:1
    Ip=abs(filter2(Px,orl_img))+abs(filter2(Py,orl_img));
end
[m n]=size(Ip);
weight_r=zeros(m,n);

for i=1:(m-1)
    tempa=Ip(i,:);
    k=find(tempa>50);
    weight_r(i,k(2):k(length(k)-1))=1;
end
% for i = 1:m
%     temp = orl_img(i,:);
%     find_edge = find(temp>20);
%     temp_weight = weight_r(i,:);
%     find_weight = find(temp_weight);
%     [o p]=size(find_edge);
%     [f g]=size(find_weight);
%     if p>0&&g>0
%         if(find_edge(1)>find_weight(1))
%             weight_r(i,find_weight(1):find_edge(1))=0;
%         end
%         if(find_edge(p)<find_weight(g))
%             weight_r(i,find_edge(p):find_weight(g))=0;
%         end
%     end
% end
%     
for i = 1:6
    weight_r = medfilt2(weight_r,[7 7]);
end

orl_img = uint8(orl_img);
temp2 = uint8(temp2);
temp_r = uint8(temp_r);
weight_r = uint8(weight_r);
temp_r=orl_img.*weight_r+temp2.*abs(1-weight_r);
%temp = medfilt2(temp);


fin_img = uint8(temp3);
fill=find(temp_r<100);
for i = 1:length(fill)
    if(~weight_r(fill(i)))
        temp1 = reshape(temp2,[1,a*b]);
        temp_r(fill(i))=temp1(fill(i));
    end
end
%fin_img(29:140,25:116) = temp_r;
%fin_img(1:56,1:46)=temp_r;%12-1
% fin_img(1:84,1:69)=temp_r;%34-1
% fin_img(1:56,95:140)=temp_r;%12-2
%fin_img(85:140,95:140)=temp_r;%12-4
% fin_img(85:140,1:46)=temp_r;%12-3
% fin_img(1:84,72:140)=temp_r;%34-2
% fin_img(57:140,1:69)=temp_r;%34-3
% fin_img(57:140,72:140)=temp_r;%34-4

fin_img(1:112,1:92) = temp_r;%11-1
% fin_img(1:112,49:140) = temp_r;%11-2
% fin_img(29:140,49:140) = temp_r;%11-4
% fin_img(29:140,1:92) = temp_r;%11-3


fill2=find(fin_img<48);
for i = 1:length(fill2)
    if(fill2(i)<5600)
        fin_img(fill2(i))=temp3(fill2(i));
    end
    if(fill2(i)>10000)
        fin_img(fill2(i))=temp3(fill2(i));
    end
end


imwrite(fin_img,'C:\Users\GUOPENG\Desktop\11_1.tiff','tiff');
figure(1);
imshow(fin_img);
%A2=fspecial('gaussian');      %生成高斯序列
%fin_img=filter2(A2,fin_img)/255;  
%fin_img = medfilt2(fin_img);
%fin_img=adp_median(fin_img);


% Ip = uint8(Ip);
% figure(3);
% imshow(200*weight_r);
% figure(4);
% imshow(orl_img);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值