资源简介
该代码为poisson抠图的matlab代码,可放心使用。
显示图像后,单击鼠标左键连出完全背景区域,双击左键结束;
图像改变后,再单击鼠标左键连出完全前景区域,双击左键结束。即可得到结果
代码片段和文件信息
clc;
clear;
% Global Poisson METHOD
% By Guan Li May 2004
A=imread(‘cat.jpg‘);
imshow(A);
hold on;
Threshold = 1;
UniBack=[0
0
255];
% choose background object and B results into the Foreground object and the
% Boundary Region
% set(handles.text5 ‘String‘ ‘Please choose the outer line of the boundary region. Single left click the mouse to specify vertice.Double left click or single right click to finish‘);
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) = immultiply(A(::2)~OuterBW);
Back(::3) = immultiply(A(::3)~OuterBW);
imshow(B);
% choose foreground object and C results into a Circle of Interest
% set(handles.text5 ‘String‘ ‘Please choose the inner line of the boundary region. Single left click the mouse to specify vertice.Double left click or single right click to finish‘);
InnerBW = roipoly(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);
hold off;
% set(handles.text5 ‘String‘ ‘Calculating Raw Fore & BackGround......................‘);
RawAlpha = (double(OuterBW)+double(InnerBW))/2;
%imshow(uint8(RawAlpha*255));
I = double(A);
% Method of “averaging“ to get raw fore and background colors
for i = 1:size(RawAlpha1)
for j = 1:size(RawAlpha2)
RawFore(ij1)=0;
RawFore(ij2)=0;
RawFore(ij3)=0;
RawBack(ij1)=0;
RawBack(ij2)=0;
RawBack(ij3)=0;
if RawAlpha(ij) == 1
RawFore(ij:)=Fore(ij:);
end;
if RawAlpha(ij) == 0
RawBack(ij:)=Back(ij:);
end;
if RawAlpha(ij) == 0.5
r=1;
while 1
TestFore = InnerBW(max(i-r1):min(i+rsize(A1))max(j-r1):min(j+rsize(A2)));
if size(find(TestFore)1)
[i1 j1] = find(TestFore);
i2 = i1 + max(i-r1) -1;
j2 = j1 + max(j-r1) -1;
Rs = double(Fore(i2j2:));
Ds(:1)=diag(Rs(::1));
Ds(:2)=diag(Rs(::2));
Ds(:3)=diag(Rs(::3));
if size(Ds1) == 1
RawFore(ij:) =Ds;
else
RawFore(ij:) = sum(Ds) / size(Ds1);
end;
clear Ds;
break;
else
r=r+1;
end;
end;
r=1;
while 1
- 上一篇:熵值法的高效matlab源程序
- 下一篇:30进制计数器
相关资源
- 熵值法的高效matlab源程序
- matlab中tstem函数
- 超分辨率的matlab工具箱
- 低通抽样定理 matlab实现
- 灰度AGV路径识别matlab程序
- MATLAB R2017b linux
- 长周期光栅光谱matlab仿真
- MATLAB中图像分割迭代法求阈值
- jpeg图像压缩matlab程序
- 生物地理学算法BBO及与差分进化算法
- 用matlab实现角点检测源代码
- MATLAB实现Canny图像边缘检测
- 基于Lucas–Kanade算法的光流估计MATLA
- MDS无线传感器网络定位算法MATLAB程序
- 数字锁相环DPLL matlab 仿真代码
- Matlab常微分方程的解法
- radon变换车牌倾斜校正Matlab代码
- K-L变换算法
- 求解二次规划问题的拉格朗日及有效
- 雷电感应电压matlab
- 有约束的最小最大值matlab程序
- bpsk在高斯白噪声信道中调制解调MAT
- 基于MATLAB的图像增强处理
- 卡尔曼滤波算法原理及MATLAB源程序
- MATLAB 软件最大功率跟踪
- MATLAB软件BOOST电路仿真
- 蚁群算法解决TSP问题MATLAB程序
- DCT变换和DFT变换 数字图像压缩 Mat
- 二值化算法:Otsu算法、Bernsen算法、
- LSB 数字水印,matlab源程序,很好的资
评论
共有 条评论