Matlab抠图代码

ID:41258310

大小:17.83 KB

页数:5页

时间:2019-08-20

Matlab抠图代码_第1页
Matlab抠图代码_第2页
Matlab抠图代码_第3页
Matlab抠图代码_第4页
Matlab抠图代码_第5页
资源描述:

《Matlab抠图代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、注:显示图像后,单击鼠标左键连出完全背景区域,双击左键结束;    图像改变后,再单击鼠标左键连出完全前景区域,双击左键结束。即可得到结果。A=imread('ppmm2.bmp');imshow(A);holdon;Threshold=1;UniBack=[0   0  255];%choosebackgroundobject,andBresultsintotheForegroundObjectandthe%BoundaryRegion%choosetheouterlineoftheboundaryregion.Singlel

2、eftclickthemousetospecifyvertice.Doubleleftclickorsinglerightclicktofinish;OuterBW=roipoly(A);B(:,:,1)=immultiply(A(:,:,1),OuterBW);B(:,:,2)=immultiply(A(:,:,2),OuterBW);B(:,:,3)=immultiply(A(:,:,3),OuterBW);Back(:,:,1)=immultiply(A(:,:,1),~OuterBW);Back(:,:,2)=immul

3、tiply(A(:,:,2),~OuterBW);Back(:,:,3)=immultiply(A(:,:,3),~OuterBW);imshow(B);%chooseforegroundobject,andCresultsintoaCircleofInterest%choosetheinnerlineoftheboundaryregion.Singleleftclickthemousetospecifyvertice.Doubleleftclickorsinglerightclicktofinish;InnerBW=roipo

4、ly(B);C(:,:,1)=immultiply(B(:,:,1),~InnerBW);C(:,:,2)=immultiply(B(:,:,2),~InnerBW);C(:,:,3)=immultiply(B(:,:,3),~InnerBW);Fore(:,:,1)=immultiply(A(:,:,1),InnerBW);Fore(:,:,2)=immultiply(A(:,:,2),InnerBW);Fore(:,:,3)=immultiply(A(:,:,3),InnerBW);imshow(C);holdoff;Raw

5、Alpha=(double(OuterBW)+double(InnerBW))/2;I=double(A);%Methodof"averaging"togetrawforeandbackgroundcolorsfori=1:size(RawAlpha,1)   forj=1:size(RawAlpha,2)     RawFore(i,j,1)=0;                RawFore(i,j,2)=0;     RawFore(i,j,3)=0;     RawBack(i,j,1)=0;              

6、  RawBack(i,j,2)=0;     RawBack(i,j,3)=0;     ifRawAlpha(i,j)==1       RawFore(i,j,:)=Fore(i,j,:);     end;     ifRawAlpha(i,j)==0       RawBack(i,j,:)=Back(i,j,:);     end;     ifRawAlpha(i,j)==0.5       r=1;       while1         TestFore=InnerBW(max(i-r,1):min(i+r,

7、size(A,1)),max(j-r,1):min(j+r,size(A,2)));         ifsize(find(TestFore),1)            [i1,j1]=find(TestFore);           i2=i1+max(i-r,1)-1;           j2=j1+max(j-r,1)-1;           Rs=double(Fore(i2,j2,:));           Ds(:,1)=diag(Rs(:,:,1));           Ds(:,2)=diag(Rs

8、(:,:,2));           Ds(:,3)=diag(Rs(:,:,3));                    ifsize(Ds,1)==1             RawFore(i,j,:)=Ds;           else      

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
正文描述:

《Matlab抠图代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、注:显示图像后,单击鼠标左键连出完全背景区域,双击左键结束;    图像改变后,再单击鼠标左键连出完全前景区域,双击左键结束。即可得到结果。A=imread('ppmm2.bmp');imshow(A);holdon;Threshold=1;UniBack=[0   0  255];%choosebackgroundobject,andBresultsintotheForegroundObjectandthe%BoundaryRegion%choosetheouterlineoftheboundaryregion.Singlel

2、eftclickthemousetospecifyvertice.Doubleleftclickorsinglerightclicktofinish;OuterBW=roipoly(A);B(:,:,1)=immultiply(A(:,:,1),OuterBW);B(:,:,2)=immultiply(A(:,:,2),OuterBW);B(:,:,3)=immultiply(A(:,:,3),OuterBW);Back(:,:,1)=immultiply(A(:,:,1),~OuterBW);Back(:,:,2)=immul

3、tiply(A(:,:,2),~OuterBW);Back(:,:,3)=immultiply(A(:,:,3),~OuterBW);imshow(B);%chooseforegroundobject,andCresultsintoaCircleofInterest%choosetheinnerlineoftheboundaryregion.Singleleftclickthemousetospecifyvertice.Doubleleftclickorsinglerightclicktofinish;InnerBW=roipo

4、ly(B);C(:,:,1)=immultiply(B(:,:,1),~InnerBW);C(:,:,2)=immultiply(B(:,:,2),~InnerBW);C(:,:,3)=immultiply(B(:,:,3),~InnerBW);Fore(:,:,1)=immultiply(A(:,:,1),InnerBW);Fore(:,:,2)=immultiply(A(:,:,2),InnerBW);Fore(:,:,3)=immultiply(A(:,:,3),InnerBW);imshow(C);holdoff;Raw

5、Alpha=(double(OuterBW)+double(InnerBW))/2;I=double(A);%Methodof"averaging"togetrawforeandbackgroundcolorsfori=1:size(RawAlpha,1)   forj=1:size(RawAlpha,2)     RawFore(i,j,1)=0;                RawFore(i,j,2)=0;     RawFore(i,j,3)=0;     RawBack(i,j,1)=0;              

6、  RawBack(i,j,2)=0;     RawBack(i,j,3)=0;     ifRawAlpha(i,j)==1       RawFore(i,j,:)=Fore(i,j,:);     end;     ifRawAlpha(i,j)==0       RawBack(i,j,:)=Back(i,j,:);     end;     ifRawAlpha(i,j)==0.5       r=1;       while1         TestFore=InnerBW(max(i-r,1):min(i+r,

7、size(A,1)),max(j-r,1):min(j+r,size(A,2)));         ifsize(find(TestFore),1)            [i1,j1]=find(TestFore);           i2=i1+max(i-r,1)-1;           j2=j1+max(j-r,1)-1;           Rs=double(Fore(i2,j2,:));           Ds(:,1)=diag(Rs(:,:,1));           Ds(:,2)=diag(Rs

8、(:,:,2));           Ds(:,3)=diag(Rs(:,:,3));                    ifsize(Ds,1)==1             RawFore(i,j,:)=Ds;           else      

显示全部收起
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。
关闭