?? hyperspectraldatacompressdlg.cpp
字號:
R[i]=new double[HEncode.BandNumber];
for(j=0;j<HEncode.BandNumber;j++)R[i][j]=0;
}
if(HEncode.HyperspectralDataFormat==BFILE||HEncode.HyperspectralDataFormat==BSQ_H)
{//逐波段統計
allLine=HEncode.BandNumber*HEncode.BandNumber/2;
bg=0;a=0;
for(i=0;i<HEncode.BandNumber;i++)
{
for(j=0;j<HEncode.Height;j++)
{//統計均方及均值
HEncode.GetOneLineImageData(lpImageData1[j],i,j);
StatisticOneLineImage(lpImageData1[j],HEncode.OnePixelBytes,
HEncode.Width,Mse,M);
R[i][i]+=Mse;
AllM[i]+=M;
}
a++;
if(((a*100)/allLine)>bg)
{//向主窗口報告當前執行的進度
bg=(a*100)/allLine;
PostMessage(WM_USER_HYPERSPECTRAL_COMPRESS_DLG,2,bg);
if(TestRelativeThreadRun==FALSE)break;//檢查是否有中止標志
}
if(i<HEncode.BandNumber-1)
{
for(k=i+1;k<HEncode.BandNumber;k++)
{
a++;
if(((a*100)/allLine)>bg)
{//向主窗口報告當前執行的進度
bg=(a*100)/allLine;
PostMessage(WM_USER_HYPERSPECTRAL_COMPRESS_DLG,2,bg);
if(TestRelativeThreadRun==FALSE)break;//檢查是否有中止標志
}
for(j=0;j<HEncode.Height;j++)
{//統計相關函數
HEncode.GetOneLineImageData(lpImageData2,k,j);
StatisticOneLineTwoImage(lpImageData1[j],
lpImageData2,
HEncode.OnePixelBytes,
HEncode.Width,
Relative);
R[i][k]+=Relative;
}
}
if(k<HEncode.BandNumber)break;
}
}
}
else
{//逐行統計
allLine=HEncode.Height;
bg=0;
for(j=0;j<HEncode.Height;j++)
{
if((j*100/allLine)>bg)
{//向主窗口報告當前執行的進度
bg=j*100/allLine;
PostMessage(WM_USER_HYPERSPECTRAL_COMPRESS_DLG,2,bg);
if(TestRelativeThreadRun==FALSE)break;//檢查是否有中止標志
}
for(i=0;i<HEncode.BandNumber;i++)
{
HEncode.GetOneLineImageData(lpImageData1[i],i,j);
StatisticOneLineImage(lpImageData1[i],HEncode.OnePixelBytes,
HEncode.Width,Mse,M);
R[i][i]+=Mse;
AllM[i]+=M;
if(i<HEncode.BandNumber-1)
{
for(k=i+1;k<HEncode.BandNumber;k++)
{
//統計相關函數
HEncode.GetOneLineImageData(lpImageData2,k,j);
StatisticOneLineTwoImage(lpImageData1[i],
lpImageData2,
HEncode.OnePixelBytes,
HEncode.Width,
Relative);
R[i][k]+=Relative;
}
}
}
}
}
for(i=0;i<HEncode.Height;i++)
{
delete lpImageData1[i];
}
delete lpImageData1;
delete lpImageData2;
if(TestRelativeThreadRun==FALSE)
{
delete AllM;
for(i=0;i<HEncode.BandNumber;i++)
{
delete R[i];
}
delete R;
HEncode.EndHyperspectralCode();
PostMessage(WM_USER_HYPERSPECTRAL_COMPRESS_DLG,3,0);
return;
}
for(i=0;i<HEncode.BandNumber;i++)
{
AllM[i]/=HEncode.Height;//均值
R[i][i]/=HEncode.Height;
R[i][i]=sqrt(R[i][i]-AllM[i]*AllM[i]);//方差
}
for(i=0;i<HEncode.BandNumber;i++)
{
if(i<HEncode.BandNumber-1)
{
for(k=i+1;k<HEncode.BandNumber;k++)
{
R[i][k]/=HEncode.Height;
R[i][k]-=AllM[i]*AllM[k];//協方差
R[i][k]/=(R[i][i]*R[k][k]);//相關系數
R[k][i]=R[i][k];//矩陣對稱
}
}
R[i][i]=1;
}
int *lpPredictBand=new int[HEncode.BandNumber];
lpPredictBand[0]=-1;//第一個波段是不進行波段間預測的。
for(i=1;i<HEncode.BandNumber;i++)
{
for(j=0,M=0;j<i;j++)
{//從前面的波段中尋找預測波段。
if(M<R[i][j])
{
M=R[i][j];
lpPredictBand[i]=j;
}
}
if(M<0.85)lpPredictBand[i]=-1;
}
delete AllM;
for(i=0;i<HEncode.BandNumber;i++)
{
delete R[i];
}
delete R;
PredictBandList.Empty();
CString s;
for(i=0;i<HEncode.BandNumber;i++)
{
s.Format(_T("%d "),lpPredictBand[i]);
PredictBandList+=s;
}
delete lpPredictBand;
TestRelativeComplate=TRUE;
HEncode.EndHyperspectralCode();
PostMessage(WM_USER_HYPERSPECTRAL_COMPRESS_DLG,3,0);
}
void CHyperspectralDataCompressDlg::StatisticOneLineImage(LPBYTE lpImageLine1,
int BytesPerPixel,
int OneLineWidth,
double &Mse1,
double &M1)
{//統計圖像行均值與均方值
int i,p1;
Mse1=M1=0;
if(OneLineWidth<=0||BytesPerPixel<=0)return;
if(BytesPerPixel==1)
{
for(i=0;i<OneLineWidth;i++)
{
p1=((unsigned char)lpImageLine1[i]);
M1+=p1;
Mse1+=p1*p1;
}
}
else if(BytesPerPixel==2)
{
OneLineWidth*=2;
for(i=0;i<OneLineWidth;i+=2)
{
p1=*((unsigned short int *)(lpImageLine1+i));
M1+=p1;
Mse1+=p1*p1;
}
OneLineWidth/=2;
}
M1/=OneLineWidth;
Mse1/=OneLineWidth;
}
void CHyperspectralDataCompressDlg::StatisticOneLineTwoImage(LPBYTE lpImageLine1,
LPBYTE lpImageLine2,
int BytesPerPixel,
int OneLineWidth,
double &Relative)
{//統計兩圖像行的相關函數
int i,p1,p2;
Relative=0;
if(OneLineWidth<=0||BytesPerPixel<=0)return;
if(BytesPerPixel==1)
{
for(i=0;i<OneLineWidth;i++)
{
p1=((unsigned char)lpImageLine1[i]);
p2=((unsigned char)lpImageLine2[i]);
Relative+=p1*p2;
}
}
else if(BytesPerPixel==2)
{
OneLineWidth*=2;
for(i=0;i<OneLineWidth;i+=2)
{
p1=*((unsigned short int *)(lpImageLine1+i));
p2=*((unsigned short int *)(lpImageLine2+i));
Relative+=p1*p2;
}
OneLineWidth/=2;
}
Relative/=OneLineWidth;
}
void CHyperspectralDataCompressDlg::OnKillfocusImageWidth()
{
UpdateData(TRUE);
if(PureImageFormat==TRUE)
{
AllDataWidth=m_ImageWidth;
}
}
void CHyperspectralDataCompressDlg::OnKillfocusAuxDataWidth()
{
//輔助數據寬度的輸入控制
UpdateData(TRUE);
if(m_AuxDataWidth>=0&&m_AuxDataWidth<AllDataWidth)
{
if(PureImageFormat==FALSE)m_ImageWidth=AllDataWidth-m_AuxDataWidth;
else if(m_AuxDataWidth>0)m_AuxDataWidth=0;
UpdateData(FALSE);
}
}
void CHyperspectralDataCompressDlg::OnKillfocusLinesPerBlock()
{
//壓縮塊行數的輸入控制
UpdateData(TRUE);
if(m_LinesPerBlock<MIN_LINES_PER_BLOCK)
{
m_LinesPerBlock=MIN_LINES_PER_BLOCK;
UpdateData(FALSE);
}
else if(m_LinesPerBlock>m_ImageHeight)
{
m_LinesPerBlock=m_ImageHeight;
UpdateData(FALSE);
}
else if(m_LinesPerBlock>MAX_LINES_PER_BLOCK)
{
m_LinesPerBlock=MAX_LINES_PER_BLOCK;
UpdateData(FALSE);
}
}
void CHyperspectralDataCompressDlg::UpdateControlList(BOOL UpdateMode)//FALSE: 數據->控件,TRUE:控件->數據
{
int i,j,Seat;
CString s;
LVITEM lvitem;
TCHAR Blist[32];
if(UpdateMode==TRUE)
{//控件->數據
UpdateData(TRUE);
PredictBandList.Empty();
j=m_RelativeList.GetItemCount();
s=_T(" ");
for (i = 0; i < j; i++)
{
PredictBandList+=m_RelativeList.GetItemText(i,1);
PredictBandList+=s;
}
}
else
{//數據->控件
m_RelativeList.DeleteAllItems();
lvitem.mask = LVIF_TEXT | LVIF_STATE| LVIF_DI_SETITEM;
for (i = 0,Seat=0; i < m_BandNumber; i++)
{
s.Format(_T("%d"),i);
lvitem.iItem = i;
lvitem.iSubItem = 0;
lvitem.pszText = s.GetBuffer(s.GetLength());
lvitem.cchTextMax=4;
lvitem.lParam=i;
lvitem.stateMask=LVM_EDITLABEL;
lvitem.state=LVM_EDITLABEL;
j = m_RelativeList.InsertItem(&lvitem);
GetNextDataSeat((LPCTSTR)PredictBandList,Blist,Seat);
lvitem.iItem = j;
lvitem.iSubItem = 1;
lvitem.pszText = Blist;
lvitem.cchTextMax=4;
lvitem.lParam=i|(lvitem.iSubItem<<16);
lvitem.stateMask=LVM_EDITLABEL;
lvitem.state=LVM_EDITLABEL;
m_RelativeList.SetItem(&lvitem);
}
UpdateData(FALSE);
}
}
int CHyperspectralDataCompressDlg::GetNextDataSeat(LPCTSTR lpAsc,LPSTR lpOne,int &Seat)
{
int i=0;
for(;lpAsc[Seat]!='-'&&(lpAsc[Seat]>'9'||lpAsc[Seat]<'0')&&lpAsc[Seat]!='\0';Seat++);
if(lpAsc[Seat]!='\0')
{
for(;(lpAsc[Seat]=='-'||(lpAsc[Seat]<='9'&&lpAsc[Seat]>='0'))&&lpAsc[Seat]!='\0';Seat++)
{
lpOne[i++]=lpAsc[Seat];
}
lpOne[i]='\0';
}
return i;
}
void CHyperspectralDataCompressDlg::InitPredictBandString()
{
PredictBandList.Empty();
for(int i=0;i<m_BandNumber;i++)
{
PredictBandList+=_T("-1 ");
}
}
void CHyperspectralDataCompressDlg::OnDblclkCompressRelativeList(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// 雙擊列表某項,如可編輯,則響應之。
// 實現方法:創建僅含編輯控件無頭對話框,將其大小和位置置于列表項處,當輸入聚焦移開此編輯框但
// 未移開本程序時,就認為輸入確認。響應Esc鍵就認為是取消。
CRect Rect,ListRect;
int ColLeft;//存放列左邊界位置
int ItemTop,ItemNumber,ItemHeight,i,x,y;
m_RelativeList.GetWindowRect(&ListRect);//取控鍵屏幕矩形
m_RelativeList.GetSubItemRect(0,0,LVIR_BOUNDS,Rect);//取初始列表對象矩形,為空時值不定
//目的是確定列表對象縱向初始位置和單對象的高度
ItemNumber=m_RelativeList.GetItemCount();//列表數目
ItemTop=Rect.top;//列表對象縱向初始位置
ItemHeight=Rect.Height();//列表對象的高度
//計算列左邊界位置
ColLeft=m_RelativeList.GetColumnWidth(0);
x=pNMListView->ptAction.x;//當前的點擊坐標,相對于ListCtrl控鍵
y=pNMListView->ptAction.y;
i=(y-ItemTop)/ItemHeight;//計算點擊點所在的列表項
//計算點擊點所在的列
if(x<=ColLeft){*pResult = 0;return;}
m_RelativeList.GetSubItemRect(i,1,LVIR_BOUNDS,Rect);//獲取子項的矩形
Rect.top+=(ListRect.top+2);//將子項矩形映射成屏幕矩形
Rect.left+=(ListRect.left+2);
Rect.bottom+=(ListRect.top+2);
Rect.right+=(ListRect.left+2);
TCHAR asc[1024];
CString s,str;
CSmallEdit *pEdit=new CSmallEdit;
if(pEdit!=NULL)
{
pEdit->Rect=Rect;//將創建的編輯框矩形置成子項矩形
m_RelativeList.GetItemText( i, 1, asc, 255);
pEdit->m_Text=asc;
pEdit->Item.x=i;//為返回具體子項提供信息
pEdit->Item.y=1;
pEdit->RemoveEditStyle=ES_MULTILINE|ES_AUTOVSCROLL;
if(pEdit->Create(NULL,NULL,0,CRect(0,0,0,0),this)==TRUE)//用無模態對話框,是要在對話框外可響應
{// ES_READONLY ES_WANTRETURN 注:this 是接收返回WM_USER_SMALL_EDIT消息的窗口
pEdit->ShowWindow(SW_SHOW);
}
}
*pResult = 0;
}
LRESULT CHyperspectralDataCompressDlg::OnSmallEditRecvMessage(WPARAM wParam, LPARAM lParam)
{
CSmallEdit *pEdit=(CSmallEdit *)lParam;
m_RelativeList.SetItemText(pEdit->Item.x,pEdit->Item.y,(LPCTSTR)pEdit->m_Text);
UpdateControlList(TRUE);
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// HyperspectralCompressThread
IMPLEMENT_DYNCREATE(HyperspectralCompressThread, CWinThread)
HyperspectralCompressThread::HyperspectralCompressThread()
{
m_bDone = FALSE;
m_pOwner = NULL;
m_bAutoDelete = FALSE;
}
HyperspectralCompressThread::~HyperspectralCompressThread()
{
}
BOOL HyperspectralCompressThread::InitInstance()
{
// TODO: perform and per-thread initialization here
return TRUE;
}
int HyperspectralCompressThread::ExitInstance()
{
// TODO: perform any per-thread cleanup here
return CWinThread::ExitInstance();
}
BEGIN_MESSAGE_MAP(HyperspectralCompressThread, CWinThread)
//{{AFX_MSG_MAP(HyperspectralCompressThread)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// HyperspectralCompressThread message handlers
int HyperspectralCompressThread::Run()
{
// TODO: Add your specialized code here and/or call the base class
m_pOwner->OkCompressProce();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// HyperspectralTestRelativeThread
IMPLEMENT_DYNCREATE(HyperspectralTestRelativeThread, CWinThread)
HyperspectralTestRelativeThread::HyperspectralTestRelativeThread()
{
m_bDone = FALSE;
m_pOwner = NULL;
m_bAutoDelete = FALSE;
}
HyperspectralTestRelativeThread::~HyperspectralTestRelativeThread()
{
}
BOOL HyperspectralTestRelativeThread::InitInstance()
{
// TODO: perform and per-thread initialization here
return TRUE;
}
int HyperspectralTestRelativeThread::ExitInstance()
{
// TODO: perform any per-thread cleanup here
return CWinThread::ExitInstance();
}
BEGIN_MESSAGE_MAP(HyperspectralTestRelativeThread, CWinThread)
//{{AFX_MSG_MAP(HyperspectralTestRelativeThread)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// HyperspectralTestRelativeThread message handlers
int HyperspectralTestRelativeThread::Run()
{
// TODO: Add your specialized code here and/or call the base class
m_pOwner->OkTestRelativeProce();
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -