📄 ondetecthmm.txt
字号:
void CLSBAnalysisDoc::OnDetectHmm()
{
//确保打开文件不为空
ASSERT(m_strPathName != _T(""));
//................得到图像基本信息....................
DWORD dwHeight = image->GetHeight(); //高
DWORD dwWidth = image->GetWidth(); //宽
DWORD dwEffWidth = image->GetEffWidth(); //实际宽度,对灰度图象为4倍数后的宽度;对彩色图像,为灰度图象宽度的3倍
DWORD dwImgSize = dwHeight * dwEffWidth; //图像数据大小
DWORD dwColors = image->GetNumColors(); //颜色数
WORD wBpp = image->GetBpp(); //位数
BYTE* pImg = NULL; //图像数据指针
pImg = image->GetBits();
// HMM 估计LSB替换的嵌入率
int T;
HMM hmm;
int N;
int M;
double **alpha;
double **beta;
double **gamma;
int *O;
// int c;
int seed; /* seed for random number generator */
int niter;
double logprobinit, logprobfinal;
/* you can initialize the hmm model three ways:
i) with a model stored in a file, which also sets
the number of states N and number of symbols M.
ii) with a random model by just specifyin N and M
on the command line.
iii) with a specific random model by specifying N, M
and seed on the command line.
*/
/* read the observed sequence */
T = 64;
O = new int[dwWidth];
O = O - 1;
for (DWORD i = 0; i < dwWidth; i++)
{
O[i+1] = (int)pImg[i];
// O[i+1] = (int)(pImg[i] + 1);
}
/* initialize the hmm model */
N = 256;
M = 256;
seed = hmmgetseed();
// WienerFilt(pImg, dwWidth, dwHeight, 3, 3, 0.5);
// InitHMM2(pImg, dwWidth, dwHeight, &hmm, N, M, seed);
InitHMM(&hmm, N, M, seed);
/* allocate memory */
alpha = dmatrix(1, T, 1, hmm.N);
beta = dmatrix(1, T, 1, hmm.N);
gamma = dmatrix(1, T, 1, hmm.N);
/* call Baum Welch2 */
double theita = BaumWelch2(&hmm, T, O, alpha, beta, gamma, &niter,
&logprobinit, &logprobfinal);
/* free memory */
// free_ivector(O, 1, T);
FreeHMM(&hmm);
free_dmatrix(alpha, 1, T, 1, hmm.N);
free_dmatrix(beta, 1, T, 1, hmm.N);
free_dmatrix(gamma, 1, T, 1, hmm.N);
delete image; image = NULL;
if (O != NULL)
{
delete [](char*)(O+1);
O = NULL;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -