资源简介

贝叶斯抠图算法,使用mfc实现,直接编译可运行。 运行时先打开原图片和trimap,然后点击菜单中的抠图。

资源截图

代码片段和文件信息

// Bayesianframework.cpp: implementation of the Bayesianframework class.
//
//////////////////////////////////////////////////////////////////////

#include “stdafx.h“
#include “BayesianMatting.h“
#include “Bayesianframework.h“
#include “MatMarchingMethod.h“

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

#define M_PI 3.14159265358979323846
#define KNOWN_SAMPLES 20
#define SOLVED_SAMPLES  400
#define SOLVED_RADIUS 20
#define MAX_RADIUS 300
#define MAX_ABF_IT 50
#define SQUAREDSIGMA_C 400

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

static int n4Neibors[4][2] = {{-10}{0-1}{10}{01}};
static double dDistance[MAX_RADIUS][MAX_RADIUS];
static BYTE bAttached2[2*SOLVED_RADIUS][2*SOLVED_RADIUS] = {0};
static BYTE bAttached[MAX_RADIUS][MAX_RADIUS] = {0};
Clusters UnknownPixel::s_Back;
Clusters UnknownPixel::s_Fore;

Bayesianframework::Bayesianframework()
{
m_bInitDone = false;
m_bIsAllocated = false;
m_pForeground = NULL;
m_pBackground = NULL;
m_pAlphaMap = NULL;
m_pAlpha = NULL;

m_pForevalues = NULL;
m_pBackvalues = NULL;
m_pValues = NULL;
m_pFlags = NULL;
m_pSampled = NULL;

m_pColor = NULL;
m_pMask = NULL;

m_nWidth = 0;
m_nHeight = 0;
m_nWidthBytes = 0;
m_nBytePixel = 0;
m_nPixelSize = 0;
m_nByteSize = 0;

for(int i=0;i {
for(int j=0;j {
dDistance[j][i] = dDistance[i][j] = sqrt(i*i+j*j);
}
}
}

Bayesianframework::~Bayesianframework()
{
ReleaseMemmory();
}

void Bayesianframework::Allocate()
{
m_pForeground = new BYTE[m_nByteSize];
m_pBackground = new BYTE[m_nByteSize];
m_pAlphaMatte = new BYTE[m_nByteSize];
memset(m_pForeground0m_nByteSize);
memset(m_pBackground0m_nByteSize);

m_pAlphaMap =  new BYTE[m_nPixelSize];
m_pAlpha = new double[m_nPixelSize];
m_pSampled = new BYTE[m_nPixelSize];
memset(m_pSampled0m_nPixelSize);

m_pPForesamples = new Sample*[m_nPixelSize];
m_pPBacksamples = new Sample*[m_nPixelSize];
memset(m_pPForesamples0m_nPixelSize*sizeof(Sample*));
memset(m_pPBacksamples0m_nPixelSize*sizeof(Sample*));

m_pForevalues = new float[m_nPixelSize];
m_pBackvalues = new float[m_nPixelSize];
m_pValues = new float[m_nPixelSize];
m_pFlags = new FLAG_TYPE[m_nPixelSize];

m_bIsAllocated = true;
}

void Bayesianframework::ReleaseMemmory()
{
if(m_pForeground)
delete[] m_pForeground;
if(m_pBackground)
delete[] m_pBackground;
if(m_pAlphaMap)
delete[] m_pAlphaMap;
if(m_pAlpha)
delete[] m_pAlpha;
if(m_pForevalues)
delete[] m_pForevalues;
if(m_pBackvalues)
delete[] m_pBackvalues;
if(m_pValues)
delete[] m_pValues;
if(m_pFlags)
delete[] m_pFlags;
if(m_pSampled)
delete[] m_pSampled;
///////////////////////////////////// m_Fore  not released 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      16007  2013-04-28 22:17  BayesianMatting\BayesianMatting\Bayesianframework.cpp

     文件       2708  2013-04-27 21:32  BayesianMatting\BayesianMatting\Bayesianframework.h

     文件      45988  2013-04-26 14:29  BayesianMatting\BayesianMatting\BayesianMatting.aps

     文件       3043  2013-04-27 19:50  BayesianMatting\BayesianMatting\BayesianMatting.clw

     文件       4611  2013-04-18 19:21  BayesianMatting\BayesianMatting\BayesianMatting.cpp

     文件       5778  2013-04-24 23:32  BayesianMatting\BayesianMatting\BayesianMatting.dsp

     文件        555  2013-04-18 13:34  BayesianMatting\BayesianMatting\BayesianMatting.dsw

     文件       1455  2013-04-18 13:34  BayesianMatting\BayesianMatting\BayesianMatting.h

     文件     230400  2013-07-21 08:37  BayesianMatting\BayesianMatting\BayesianMatting.ncb

     文件      55808  2013-07-21 08:37  BayesianMatting\BayesianMatting\BayesianMatting.opt

     文件        264  2013-07-16 15:26  BayesianMatting\BayesianMatting\BayesianMatting.plg

     文件      13376  2013-04-26 14:29  BayesianMatting\BayesianMatting\BayesianMatting.rc

     文件       3941  2013-04-28 22:29  BayesianMatting\BayesianMatting\BayesianMattingDoc.cpp

     文件       1833  2013-04-19 20:30  BayesianMatting\BayesianMatting\BayesianMattingDoc.h

     文件       3467  2013-04-18 19:37  BayesianMatting\BayesianMatting\BayesianMattingView.cpp

     文件       2058  2013-04-18 14:48  BayesianMatting\BayesianMatting\BayesianMattingView.h

     文件       1542  2013-04-18 13:34  BayesianMatting\BayesianMatting\ChildFrm.cpp

     文件       1397  2013-04-18 13:34  BayesianMatting\BayesianMatting\ChildFrm.h

     文件       7036  2013-04-28 15:10  BayesianMatting\BayesianMatting\Clusters.cpp

     文件       1978  2013-04-28 13:43  BayesianMatting\BayesianMatting\Clusters.h

     文件    3490816  2013-04-24 23:09  BayesianMatting\BayesianMatting\Debug\BayesianMatting.bsc

     文件      68490  2013-04-28 13:51  BayesianMatting\BayesianMatting\Debug\BayesianMatting.exp

     文件     118132  2013-04-28 13:51  BayesianMatting\BayesianMatting\Debug\BayesianMatting.lib

     文件       4731  2013-04-19 18:54  BayesianMatting\BayesianMatting\Debug\FastMattingMethod.obj

     文件          0  2013-04-19 18:54  BayesianMatting\BayesianMatting\Debug\FastMattingMethod.sbr

     文件       4563  2013-04-27 14:25  BayesianMatting\BayesianMatting\FastMarchingMethod.cpp

     文件       1586  2013-04-21 23:21  BayesianMatting\BayesianMatting\FastMarchingMethod.h

     文件     793678  2009-11-01 13:30  BayesianMatting\BayesianMatting\img\dog-input.bmp

     文件     793678  2009-10-30 15:54  BayesianMatting\BayesianMatting\img\dog-trimap.bmp

     文件     654246  2009-10-30 15:47  BayesianMatting\BayesianMatting\img\girl-input.bmp

............此处省略636个文件信息

评论

共有 条评论