📄 hyperspectraldatauncompressdlg.cpp
字号:
GetDlgItem(IDC_IMAGE_FILE_NAME)->EnableWindow(FALSE);
GetDlgItem(IDC_CONSTRUCT_IMAGE_FILE_NAME)->EnableWindow(FALSE);
GetDlgItem(IDC_UNCOMPRESS_CANCEL)->SetWindowText(_T("终止"));
m_NoticeString=_T("正在执行解压缩 ...");
UpdateData(FALSE);
m_pUnCompressThread = (HyperspectralUnCompressThread*)//创建线程
AfxBeginThread(RUNTIME_CLASS(HyperspectralUnCompressThread), THREAD_PRIORITY_NORMAL,
0, CREATE_SUSPENDED);
m_pUnCompressThread->SetOwner(this);//设置线程对应的窗口
UnCompressThreadRun=TRUE;//设置线程运行标志,此标置被置成FALSE时,线程结束
m_pUnCompressThread->ResumeThread();//启动线程
}
void CHyperspectralDataUnCompressDlg::OkUnCompressProce()
{
int Line,i,j,LineBG,LineN,AuxData_L,AuxData_cp,CodeBit_cp,Block_L,AllowMaxErr;
double AllBits;
int MaxError,MaxErr,bg,allLine,a;
double AllErrorMse,Mse;
LPCTSTR *lpConstructFileName=new LPCTSTR[BandNumber];
LPBYTE lpImageData=new BYTE[Width*BytesPerPixel+4];
LPBYTE lpConstructData;
CHyperspectralImageCode HDecode;
CHyperspectralImageCode HEncodeI;
if(CanCompare==TRUE)
{
LPCTSTR *lpImageFileName=new LPCTSTR[BandNumber];
if(HyperspectralDataFormat==BFILE)
{//如果是纯图像格式
//建立单波段文件名指针表
for(i=0;i<BandNumber;i++)lpImageFileName[i]=(LPCTSTR)lpImageFile[i];
//加载纯图像格式的高光谱数据
if(HEncodeI.LoadHyperspectralImageFile(lpImageFileName,
BandNumber,
atoi((LPCTSTR)m_ImageHeight),
atoi((LPCTSTR)m_ImageWidth),
BytesPerPixel,
atoi((LPCTSTR)m_BitsPerPixel))==FALSE)
{
//如果加载失败,发送结束进程消息。
HEncodeI.EndHyperspectralCode();
MessageBeep(0xffffffff);
MessageBox(_T("装入比较的原始图像失败"));
PostMessage(WM_USER_HYPERSPECTRAL_UNCOMPRESS_DLG,1,0);
delete lpConstructFileName;
delete lpImageFileName;
delete lpImageData;
return;
}
}
else
{//格式为(BSQ_H、BIP_H、BIL_H)的高光谱数据
if(HEncodeI.LoadHyperspectralImageFile((LPCTSTR)m_ImageFileName,
atoi((LPCTSTR)m_AuxWidth))==FALSE)
{
HEncodeI.EndHyperspectralCode();
MessageBeep(0xffffffff);
MessageBox(_T("装入比较的原始图像失败"));
PostMessage(WM_USER_HYPERSPECTRAL_UNCOMPRESS_DLG,1,0);
delete lpConstructFileName;
delete lpImageFileName;
delete lpImageData;
return;
}
}
delete lpImageFileName;
}
for(;CompleteUnCompressFileNumber<CompressFileNumbers;CompleteUnCompressFileNumber++)
{
if(CompleteUnCompressFileNumber>0)
{
m_CompressFileName=lpCompressFile[CompleteUnCompressFileNumber];
if(LoadHyperspectralCompressHead(m_CompressFileName)==TRUE)
{
IsHyperspectralCompressData=TRUE;
}
else break;
m_NoticeString=_T("正在执行解压缩 ...");
PostMessage(WM_USER_HYPERSPECTRAL_UNCOMPRESS_DLG,6,0);
}
// 1、加载高光谱压缩码流。
if(HDecode.LoadCompressBitStream(m_CompressFileName)==FALSE)break;
BytesPerPixel=HDecode.OnePixelBytes;
if(CompleteUnCompressFileNumber==0)
{
//为重建图像准备缓冲
if(HyperspectralDataFormat==BFILE)
{
//建立单波段文件名指针表
for(i=0;i<BandNumber;i++)lpConstructFileName[i]=(LPCTSTR)lpConstructFile[i];
//加载纯图像格式的高光谱数据
if(HDecode.PrepareConstructionImageBuf(lpConstructFileName)==FALSE)break;
}
else
{
if(HDecode.PrepareConstructionImageBuf((LPCTSTR)m_ConstuctFileName)==FALSE)break;
}
// 2、为各波段创建解码器。只在初始创建
HDecode.CreatCompressObject();
}
// 4、执行解压缩循环
AllBits=0;
allLine=HDecode.Height;
bg=0;
for(Line=0;Line<HDecode.Height;)
{//这是块循环层
LineBG=Line;
Block_L=*((int *)HDecode.lpBlockHead);
AuxData_L=HDecode.LoadBlockCompressHead(HDecode.lpBlockHead,AllowMaxErr,LineBG,LineN);
AuxData_cp=9;
HDecode.AllowMaxError=AllowMaxErr;
HDecode.lpCodeStreamBuf=HDecode.lpBlockHead+AuxData_L;
for(i=0;i<HDecode.BandNumber;i++)
{//各波段编码器复位
HDecode.lpCompressUnit[i]->InitialisationsCode(HDecode.OnePixelBits,HDecode.AllowMaxError);
}
CodeBit_cp=0;
for(j=0;j<LineN;j++)
{
a=(j+LineBG)*100/allLine;
if(a>bg)
{//向主窗口报告当前执行的行数
bg=a;
PostMessage(WM_USER_HYPERSPECTRAL_UNCOMPRESS_DLG,0,a);
if(UnCompressThreadRun==FALSE)break;//检查是否有中止标志
}
for(i=0;i<HDecode.BandNumber;i++)
{
//解压缩当前行图像,码流指针以比特为单位
CodeBit_cp+=HDecode.lpCompressUnit[i]->DoDecodeLine(lpImageData,
HDecode.OnePixelBytes,
HDecode.lpCodeStreamBuf,
CodeBit_cp);
//保存当前行图像数据
HDecode.SetOneLineImageData(lpImageData,i,j+LineBG);
//保当前行辅助数据
AuxData_cp+=HDecode.SetOneLineAuxData(HDecode.lpBlockHead+AuxData_cp,i,j+LineBG);
}
}
if(UnCompressThreadRun==FALSE)break;
AllBits+=CodeBit_cp;
Line+=LineN;
//块指针指向下一块
HDecode.lpBlockHead+=Block_L;
}
// 5、释放码流缓冲。
if(HDecode.CMF.IsOpen()==TRUE)
{
HDecode.CMF.Close();
HDecode.lpCodeStreamBuf=NULL;
}
AllBits/=(HDecode.Height*HDecode.Width*HDecode.BandNumber);
if(UnCompressThreadRun==FALSE)break;
//进行图象比较
PostMessage(WM_USER_HYPERSPECTRAL_UNCOMPRESS_DLG,2,0);
if(HDecode.Width==HEncodeI.Width&&
HEncodeI.Height==HDecode.Height&&
HEncodeI.BandNumber==HDecode.BandNumber&&
HEncodeI.OnePixelBytes==HDecode.OnePixelBytes)
{
lpConstructData=new BYTE[HDecode.Width*HDecode.OnePixelBytes+4];
AllErrorMse=0;
MaxError=0;
allLine=BandNumber*HEncodeI.Height;
bg=0;
if(HyperspectralDataFormat==BFILE||HyperspectralDataFormat==BSQ_H)
{//逐波段比较
for(i=0;i<BandNumber;i++)
{
for(j=0;j<HEncodeI.Height;j++)
{
a=i*j*100/allLine;
if(a>bg)
{//向主窗口报告当前执行的进度
bg=a;
PostMessage(WM_USER_HYPERSPECTRAL_UNCOMPRESS_DLG,3,bg);
if(UnCompressThreadRun==FALSE)break;//检查是否有中止标志
}
HEncodeI.GetOneLineImageData(lpImageData,i,j);
HDecode.GetOneLineImageData(lpConstructData,i,j);
CalculateOneLineImageErr(lpImageData,lpConstructData,HEncodeI.OnePixelBytes,
HEncodeI.Width,MaxErr,Mse);
if(MaxError<MaxErr)MaxError=MaxErr;
AllErrorMse+=Mse;
}
if(j<HEncodeI.Height)break;
}
}
else
{//逐行比较
for(j=0;j<HEncodeI.Height;j++)
{
for(i=0;i<BandNumber;i++)
{
a=i*j*100/allLine;
if(a>bg)
{//向主窗口报告当前执行的进度
bg=a;
PostMessage(WM_USER_HYPERSPECTRAL_UNCOMPRESS_DLG,3,bg);
if(UnCompressThreadRun==FALSE)break;//检查是否有中止标志
}
HEncodeI.GetOneLineImageData(lpImageData,i,j);
HDecode.GetOneLineImageData(lpConstructData,i,j);
CalculateOneLineImageErr(lpImageData,lpConstructData,HEncodeI.OnePixelBytes,
HEncodeI.Width,MaxErr,Mse);
if(MaxError<MaxErr)MaxError=MaxErr;
AllErrorMse+=Mse;
}
if(i<BandNumber)break;
}
}
delete lpConstructData;
if(UnCompressThreadRun==TRUE)
{
if(AllowReport==FALSE)
{
AllErrorMse/=(HDecode.BandNumber*HDecode.Height*HDecode.Width);
if(AllErrorMse<=0)m_PSNRString.Format(_T("------"));
else
{
AllErrorMse=10*log10((1<<(HDecode.OnePixelBits*2))/AllErrorMse);
m_PSNRString.Format(_T("%.6fdb"),AllErrorMse);
}
m_MaxError.Format(_T("%d"),MaxError);
m_RateString.Format(_T("%.6fbits/pixel"),AllBits);
m_CompressRate.Format(_T("%.6f"),HDecode.OnePixelBits/AllBits);
}
else
{
AllErrorMse/=(HDecode.BandNumber*HDecode.Height*HDecode.Width);
if(AllErrorMse<=0)m_PSNRString.Format(_T("------ "));
else
{
AllErrorMse=10*log10((1<<(HDecode.OnePixelBits*2))/AllErrorMse);
m_PSNRString.Format(_T("%-8.5f "),AllErrorMse);
}
m_MaxError.Format(_T(" %-3d "),MaxError);
m_RateString.Format(_T("%-8.6f "),AllBits);
m_CompressRate.Format(_T("%-6.3f "),HDecode.OnePixelBits/AllBits);
Report+=m_MaxError;
Report+=m_CompressRate;
Report+=m_RateString;
Report+=m_PSNRString;
Report+=_T("\r\n");
}
PostMessage(WM_USER_HYPERSPECTRAL_UNCOMPRESS_DLG,6,0);
}
}
}
delete lpImageData;
delete lpConstructFileName;
if(CanCompare==TRUE)HEncodeI.EndHyperspectralCode();
HDecode.EndHyperspectralCode();
UnCompressComplete=TRUE;
PostMessage(WM_USER_HYPERSPECTRAL_UNCOMPRESS_DLG,1,0);
}
void CHyperspectralDataUnCompressDlg::CalculateOneLineImageErr(LPBYTE ImageLine,
LPBYTE CompareImageLine,
int BytesPerPix,
int OneLineWidth,
int &MaxError,
double &ErrMse)
{
int i,pp,pc,MaxErr,err;
double Mse;
Mse=0;MaxErr=0;
if(BytesPerPix==1)
{
for(i=0;i<OneLineWidth;i++)
{
pp=((unsigned char)ImageLine[i]);
pc=((unsigned char)CompareImageLine[i]);
if((err=pp-pc)<0)err=-err;
if(MaxErr<err)MaxErr=err;
Mse+=(err*err);
}
}
else if(BytesPerPix==2)
{
OneLineWidth*=2;
for(i=0;i<OneLineWidth;i+=2)
{
pp=*((unsigned short int *)(ImageLine+i));
pc=*((unsigned short int *)(CompareImageLine+i));
if((err=pp-pc)<0)err=-err;
if(MaxErr<err)MaxErr=err;
Mse+=(err*err);
}
}
MaxError=MaxErr;
ErrMse=Mse;
}
/////////////////////////////////////////////////////////////////////////////
// HyperspectralUnCompressThread
IMPLEMENT_DYNCREATE(HyperspectralUnCompressThread, CWinThread)
HyperspectralUnCompressThread::HyperspectralUnCompressThread()
{
m_bDone = FALSE;
m_pOwner = NULL;
m_bAutoDelete = FALSE;
}
HyperspectralUnCompressThread::~HyperspectralUnCompressThread()
{
}
BOOL HyperspectralUnCompressThread::InitInstance()
{
// TODO: perform and per-thread initialization here
return TRUE;
}
int HyperspectralUnCompressThread::ExitInstance()
{
// TODO: perform any per-thread cleanup here
return CWinThread::ExitInstance();
}
BEGIN_MESSAGE_MAP(HyperspectralUnCompressThread, CWinThread)
//{{AFX_MSG_MAP(HyperspectralUnCompressThread)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// HyperspectralUnCompressThread message handlers
int HyperspectralUnCompressThread::Run()
{
// TODO: Add your specialized code here and/or call the base class
m_pOwner->OkUnCompressProce();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -