?? waveletdoc.cpp
字號:
spTransData1[i] = new short [biWidth];
m_WaveletCoeff[i] = new short [biWidth];
}
//創(chuàng)建圖像小波變換類
CWaveletTrans *pTrans;
//從設(shè)備緩存中獲取原始圖像數(shù)據(jù)
for (i=0;i<=2;i++)
{
for(y=0; y<(int)biHeight; y++)
{
for( x=0; x<(int)biWidth; x++)
{
cur = y*biAlign+3*x;
spOriginData[biHeight-1-y][x]=(short)(lpData[cur+i]);
}
}
//完成一次圖像小波變換
pTrans->DWT_Once(spOriginData,spTransData0,spTransData1,biHeight,biHeight/2,biWidth,biWidth/2,1,1.414);
//允許圖像復(fù)原操作標志
m_bOnce = TRUE;
m_bTwice = FALSE;
m_bTribl = FALSE;
//m_bOnce = m_bOnce & ~m_bTwice & ~m_bTribl & ~m_bFilter;
MaxPixVal=spTransData1[0][0];
MinPixVal=spTransData1[0][0];
for( y=0; y<(int)biHeight; y++)
{
for( x=0; x<(int)biWidth; x++)
{
if(MaxPixVal<spTransData1[y][x])
MaxPixVal=spTransData1[y][x];
if(MinPixVal>spTransData1[y][x])
MinPixVal=spTransData1[y][x];
//m_WvltCoeff[y][x] = spTransData1[y][x];
}
}
Diff=MaxPixVal-MinPixVal;
for(y=0; y<(int)biHeight; y++)
{
for(x=0; x<(int)biWidth; x++)
{
//因為小波變換后的小波系數(shù)有可能超過255甚至更多,那么就將
//小波系數(shù)的范圍映射到0~255區(qū)間內(nèi),以后出現(xiàn)類似的處理,目的都是一樣的
fTempBufforDisp=spTransData1[biHeight-1-y][x];
fTempBufforDisp-=MinPixVal;
long num;
num=1<<(lpBitmapInfoHeader->biBitCount/3);
fTempBufforDisp*=(num-1);
fTempBufforDisp/=Diff;
cur= y*biAlign+3*x; //current pixel
m_pstore[cur+i]=spTransData1[biHeight-1-y][x];
m_pTransfered[cur+i]= (unsigned char)fTempBufforDisp;
/*
m_pTransfered[cur] = (unsigned char)fTempBufforDisp;
m_pTransfered[cur+1]= (unsigned char)fTempBufforDisp;
m_pTransfered[cur+2]= (unsigned char)fTempBufforDisp;
*/
}
}
}
//顯示圖像的小波系數(shù)
UpdateAllViews(NULL);
//刪除臨時的數(shù)據(jù)空間
delete spOriginData;
delete spTransData0;
delete spTransData1;
return;
}
void CWaveletDoc::OnWaveletTwo()
{
//讀取數(shù)字圖像的文件頭,獲取圖像的屬性參數(shù)
LPBITMAPINFOHEADER lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pBitmap+14);
LPBITMAPFILEHEADER lpBitmapFileHeader = (LPBITMAPFILEHEADER)m_pBitmap;
unsigned char *lpData = m_pBitmap + lpBitmapFileHeader->bfOffBits;
unsigned long biHeight = lpBitmapInfoHeader->biHeight;
unsigned long biWidth = lpBitmapInfoHeader->biWidth;
unsigned long biAlign = (biWidth*3+3)/4 *4;
unsigned long bmSize = biHeight * biAlign;
if(m_pTransfered==NULL)
{
m_pTransfered=(unsigned char*) malloc (bmSize);
m_pstore=new short [bmSize];
}
if(m_pTransfered==NULL)
return;
//圖像矩陣坐標與像素數(shù)值
int x,y,cur;
unsigned char tempR, tempG, tempB;
float fTempBufforDisp;
short MaxPixVal,MinPixVal,Diff;
short **spOriginData, **spTransData0, **spTransData1;
//分配數(shù)據(jù)空間
spOriginData = new short* [biHeight];
spTransData0 = new short* [biHeight];
spTransData1 = new short* [biHeight];
m_WaveletCoeff = new short * [biHeight];
for(int i = 0; i < biHeight; i ++)
{
spOriginData[i] = new short [biWidth];
spTransData0[i] = new short [biWidth];
spTransData1[i] = new short [biWidth];
m_WaveletCoeff[i] = new short [biWidth];
}
//創(chuàng)建圖像小波變化類
CWaveletTrans *pTrans;
//從設(shè)備緩存中獲取原始圖像數(shù)據(jù)
for (i=0;i<=2;i++)
{
for(y=0; y<(int)biHeight; y++)
{
for( x=0; x<(int)biWidth; x++)
{
cur = y*biAlign+3*x;
spOriginData[biHeight-1-y][x]=(short)(lpData[cur+i]);
/*
tempB=lpData[cur];
tempG=lpData[cur+1];
tempR=lpData[cur+2];
spOriginData[biHeight-1-y][x]=(short)(0.3*tempR+0.59*tempG+0.11*tempB); //no problem
*/
}
}
//完成圖像的兩次小波變換
pTrans->DWT_Two(spOriginData,spTransData0,spTransData1,biHeight,biHeight/2,biWidth,biWidth/2,2,1.414);
//允許圖像復(fù)原操作標志
m_bOnce = FALSE;
m_bTribl = FALSE;
m_bTwice = TRUE;
//m_bTwice = m_bTwice & ~m_bTribl & ~m_bOnce & ~m_bFilter;
MaxPixVal=spTransData1[0][0];
MinPixVal=spTransData1[0][0];
//計算得到圖像小波系數(shù)的極大值與極小值
for( y=0; y<(int)biHeight; y++)
{
for( x=0; x<(int)biWidth; x++)
{
if(MaxPixVal<spTransData1[y][x])
MaxPixVal=spTransData1[y][x];
if(MinPixVal>spTransData1[y][x])
MinPixVal=spTransData1[y][x];
//m_WvltCoeff[y][x] = spTransData1[y][x];
}
}
//計算獲得小波系數(shù)的極值差
Diff=MaxPixVal-MinPixVal;
//小波系數(shù)經(jīng)過處理后,放入顯示緩存中
for(y=0; y<(int)biHeight; y++)
{
for(x=0; x<(int)biWidth; x++)
{
//因為小波變換后的小波系數(shù)有可能超過255甚至更多,那么就將
//小波系數(shù)的范圍映射到0~255區(qū)間內(nèi),以后出現(xiàn)類似的處理,目的都是一樣的
fTempBufforDisp=spTransData1[biHeight-1-y][x];
fTempBufforDisp-=MinPixVal;
long num;
num=1<<(lpBitmapInfoHeader->biBitCount/3);
fTempBufforDisp*=num-1;
fTempBufforDisp/=Diff;
cur= y*biAlign+3*x; //current pixel
m_pstore[cur+i]=spTransData1[biHeight-1-y][x];
m_pTransfered[cur+i]= (unsigned char)fTempBufforDisp;
/*
m_pTransfered[cur] = (unsigned char)fTempBufforDisp;
m_pTransfered[cur+1]= (unsigned char)fTempBufforDisp;
m_pTransfered[cur+2]= (unsigned char)fTempBufforDisp;
*/
}
}
}
//顯示圖像的小波系數(shù)
UpdateAllViews(NULL);
//刪除臨時的數(shù)據(jù)空間
delete spOriginData;
delete spTransData0;
delete spTransData1;
return;
}
void CWaveletDoc::OnWaveletThree()
{
//讀取數(shù)字圖像的文件頭,獲取圖像的屬性參數(shù)
LPBITMAPINFOHEADER lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pBitmap+14);
LPBITMAPFILEHEADER lpBitmapFileHeader = (LPBITMAPFILEHEADER)m_pBitmap;
unsigned char *lpData = m_pBitmap + lpBitmapFileHeader->bfOffBits;
unsigned long biHeight = lpBitmapInfoHeader->biHeight;
unsigned long biWidth = lpBitmapInfoHeader->biWidth;
unsigned long biAlign = (biWidth*3+3)/4 *4;
unsigned long bmSize = biHeight * biAlign;
if(m_pTransfered==NULL)
{
m_pTransfered=(unsigned char*) malloc (bmSize);
m_pstore=new short [bmSize];
}
if(m_pTransfered==NULL)
return;
//圖像矩陣坐標與像素數(shù)據(jù)
int x,y,cur;
unsigned char tempR, tempG, tempB;
float fTempBufforDisp;
short MaxPixVal,MinPixVal,Diff;
short **spOriginData, **spTransData0, **spTransData1;
//分配圖像小波變換的數(shù)據(jù)內(nèi)存空間
spOriginData = new short* [biHeight];
spTransData0 = new short* [biHeight];
spTransData1 = new short* [biHeight];
m_WaveletCoeff = new short * [biHeight];
for(int i = 0; i < biHeight; i ++)
{
spOriginData[i] = new short [biWidth];
spTransData0[i] = new short [biWidth];
spTransData1[i] = new short [biWidth];
m_WaveletCoeff[i] = new short [biWidth];
}
//創(chuàng)建圖像小波類
CWaveletTrans *pTrans;
//從設(shè)備的圖像緩存中獲取原始圖像的數(shù)據(jù)
for (i=0;i<=2;i++)
{
for(y=0; y<(int)biHeight; y++)
{
for( x=0; x<(int)biWidth; x++)
{
cur = y*biAlign+3*x;
spOriginData[biHeight-1-y][x]=lpData[cur+i];
/*
tempB=lpData[cur];
tempG=lpData[cur+1];
tempR=lpData[cur+2];
spOriginData[biHeight-1-y][x]=(short)(0.3*tempR+0.59*tempG+0.11*tempB); //no problem
*/
}
}
//完成圖像的三次小波變換
pTrans->DWT_Three(spOriginData,spTransData0,spTransData1,biHeight,biHeight/2,biWidth,biWidth/2,3,1.414);
//允許圖像復(fù)員操作標志
m_bOnce = FALSE;
m_bTwice = FALSE;
m_bTribl = TRUE;
//m_bTribl = m_bTribl & ~m_bTwice & ~m_bOnce & ~m_bFilter;
MaxPixVal=spTransData1[0][0];
MinPixVal=spTransData1[0][0];
//得到小波系數(shù)的極大值和極小值
for( y=0; y<(int)biHeight; y++)
{
for( x=0; x<(int)biWidth; x++)
{
if(MaxPixVal<spTransData1[y][x])
MaxPixVal=spTransData1[y][x];
if(MinPixVal>spTransData1[y][x])
MinPixVal=spTransData1[y][x];
//m_WvltCoeff[y][x] = spTransData1[y][x];
}
}
//計算出小波系數(shù)的極值差
Diff=MaxPixVal-MinPixVal;
//將圖像的小波數(shù)據(jù)處理后放入顯示緩存中
for(y=0; y<(int)biHeight; y++)
{
for(x=0; x<(int)biWidth; x++)
{
//因為小波變換后的小波系數(shù)有可能超過255甚至更多,那么就將
//小波系數(shù)的范圍映射到0~255區(qū)間內(nèi),以后出現(xiàn)類似的處理,目的都是一樣的
fTempBufforDisp=spTransData1[biHeight-1-y][x];
fTempBufforDisp-=MinPixVal;
long num;
num=1<<(lpBitmapInfoHeader->biBitCount/3);
fTempBufforDisp*=num-1;
fTempBufforDisp/=Diff;
cur= y*biAlign+3*x; //current pixel
m_pstore[cur+i]=spTransData1[biHeight-1-y][x];
m_pTransfered[cur+i]= (unsigned char)fTempBufforDisp;
/*
m_pTransfered[cur] = (unsigned char)fTempBufforDisp;
m_pTransfered[cur+1]= (unsigned char)fTempBufforDisp;
m_pTransfered[cur+2]= (unsigned char)fTempBufforDisp;
*/
}
}
}
//刪除臨時的數(shù)據(jù)空間
delete spOriginData;
delete spTransData0;
delete spTransData1;
//顯示圖像的小波變換
UpdateAllViews(NULL);
return;
}
void CWaveletDoc::OnDwtNibianhuan()
{
// TODO: Add your command handler code here
//讀取數(shù)字圖像的文件頭,獲取圖像的屬性參數(shù)
LPBITMAPINFOHEADER lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pBitmap+14);
LPBITMAPFILEHEADER lpBitmapFileHeader = (LPBITMAPFILEHEADER)m_pBitmap;
unsigned char *lpData = m_pBitmap + lpBitmapFileHeader->bfOffBits;
unsigned long biHeight = lpBitmapInfoHeader->biHeight;
unsigned long biWidth = lpBitmapInfoHeader->biWidth;
unsigned long biAlign = (biWidth*3+3)/4 *4;
unsigned long bmSize = biHeight * biAlign;
if(m_pTransfered==NULL)
m_pTransfered=(unsigned char*) malloc (bmSize);
if(m_pTransfered==NULL)
return;
//圖像矩陣的坐標
int x,y,cur;
//圖像數(shù)據(jù)與圖像處理數(shù)據(jù)的存放空間
short **spOriginData, **spTransData0;
spOriginData = new short* [biHeight];
spTransData0 = new short* [biHeight];
//分配數(shù)據(jù)的內(nèi)存空間
for(int i = 0; i < biHeight; i ++)
{
spOriginData[i] = new short [biWidth];
spTransData0[i] = new short [biWidth];
}
//創(chuàng)建數(shù)字處理類
CWaveletNibianhua *pDip;
//如果圖像只經(jīng)過一次小波變換,則進行相應(yīng)的逆變換
for (i=0;i<=2;i++)
{
for(y=0; y<(int)biHeight; y++)
{
for(x=0; x<(int)biWidth; x++)
{
cur= y*biAlign+3*x;
m_WaveletCoeff[biHeight-1-y][x]=m_pstore[cur+i];
}
}
if(m_bOnce)
{
pDip->FuYuan(spOriginData, spTransData0, m_WaveletCoeff,biHeight,biHeight/2,biWidth,biWidth/2,1,1.414);
if (i==2)
m_bOnce = FALSE;
//delete m_WvltCoeff;
}
//如果圖像只經(jīng)過兩次小波變換,則進行相應(yīng)的逆變換
else if(m_bTwice)
{
pDip->FuYuan(spOriginData, spTransData0, m_WaveletCoeff,biHeight ,biHeight/2,biWidth,biWidth/2,2,1.414);
if (i==2)
m_bTwice = FALSE;
}
//如果圖像只經(jīng)過三次小波變換,則進行相應(yīng)的逆變換
else if(m_bTribl)
{
pDip->FuYuan(spOriginData, spTransData0, m_WaveletCoeff, biHeight, biHeight/2,biWidth,biWidth/2,3,1.414);
if (i==2)
m_bTribl = FALSE;
//delete m_WvltCoeff;
}
//判斷是否有小波系數(shù)可以進行圖像的復(fù)原
else if(m_bFilter)
{
MessageBoxA(NULL,_T("沒有找到可用小波系數(shù),或者是未做小波變換"),_T("Message"),MB_ICONEXCLAMATION|MB_OK);
m_bFilter = FALSE;
}
//將圖像數(shù)據(jù)放入顯示緩存中
for(y=0; y<(int)biHeight; y++)
{
for(x=0; x<(int)biWidth; x++)
{
cur= y*biAlign+3*x; //current pixel
m_pTransfered[cur+i]= (unsigned char)spOriginData[biHeight-1-y][x];
}
}
}//for i
delete m_WaveletCoeff;
m_WaveletCoeff=NULL;
//顯示圖像復(fù)原的結(jié)果
UpdateAllViews(NULL);
//刪除臨時的數(shù)據(jù)內(nèi)存空間
delete spOriginData;
delete spTransData0;
}
void CWaveletDoc::OnCodeEzw()
{
// TODO: Add your command handler code here
CEzwCode Ezw;
int k=0;
LPBITMAPINFOHEADER lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pBitmap+14);
int biHeight = lpBitmapInfoHeader->biHeight;
int biWidth = lpBitmapInfoHeader->biWidth;
for (k=0;k<=2;k++)
Ezw.EzwQualitition(minthr,biHeight,biWidth,k,m_pstore,&fsize);
return;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -