?? imageprocessingview.cpp
字號:
// ImageProcessingView.cpp : implementation of the CImageProcessingView class
//
#include "stdafx.h"
#include "ImageProcessing.h"
#include "ImageProcessingDoc.h"
#include "ImageProcessingView.h"
#include "GlobalApi.h"
#include <complex>
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CImageProcessingView
IMPLEMENT_DYNCREATE(CImageProcessingView, CScrollView)
BEGIN_MESSAGE_MAP(CImageProcessingView, CScrollView)
//{{AFX_MSG_MAP(CImageProcessingView)
ON_COMMAND(ID_EDGE_CANNY, OnEdgeCanny)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CImageProcessingView construction/destruction
CImageProcessingView::CImageProcessingView()
{
// 為小波變換設置的參數
// 臨時存放小波變換系數內存
m_pDbImage = NULL;
// 設置當前層數
m_nDWTCurDepth = 0;
// 設置小波基緊支集長度
m_nSupp = 1;
}
CImageProcessingView::~CImageProcessingView()
{
// 釋放已分配內存
if(m_pDbImage){
delete[]m_pDbImage;
m_pDbImage = NULL;
}
}
BOOL CImageProcessingView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CImageProcessingView drawing
void CImageProcessingView::OnDraw(CDC* pDC)
{
CImageProcessingDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CSize sizeDibDisplay;
if(!pDoc->m_pDibInit->IsEmpty()){
sizeDibDisplay = pDoc->m_pDibInit->GetDimensions();
pDoc->m_pDibInit->Draw(pDC,CPoint(0,0),sizeDibDisplay);
}
}
void CImageProcessingView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CImageProcessingDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CSize sizeTotal = pDoc->m_pDibInit->GetDimensions();
SetScrollSizes(MM_TEXT, sizeTotal);
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CImageProcessingView printing
BOOL CImageProcessingView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CImageProcessingView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CImageProcessingView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CImageProcessingView diagnostics
#ifdef _DEBUG
void CImageProcessingView::AssertValid() const
{
CScrollView::AssertValid();
}
void CImageProcessingView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CImageProcessingDoc* CImageProcessingView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImageProcessingDoc)));
return (CImageProcessingDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CImageProcessingView message handlers
/*************************************************************************
*
* \函數名稱:
* OnFft2d()
*
* \輸入參數:
* 無
*
* \返回值:
* 無
*
* \說明:
* 運行二維快速傅立葉變換
*
*************************************************************************
*/
//DEL void CImageProcessingView::OnFft2d()
//DEL {
//DEL //圖象FFT變換
//DEL
//DEL // 更改光標形狀
//DEL BeginWaitCursor();
//DEL
//DEL // 循環控制變量
//DEL int y;
//DEL int x;
//DEL
//DEL // 獲得Doc類的指針
//DEL CImageProcessingDoc * pDoc = (CImageProcessingDoc *)this->GetDocument();
//DEL
//DEL CDib * pDib = pDoc->m_pDibInit;
//DEL
//DEL // 獲得圖象的頭文件信息
//DEL LPBITMAPINFOHEADER lpBMIH=pDib->m_lpBMIH;
//DEL
//DEL // 判斷是否是8-bpp位圖(這里為了方便,只處理8-bpp位圖的離散傅立葉變換)
//DEL if (lpBMIH->biBitCount != 8)
//DEL {
//DEL // 提示用戶
//DEL MessageBox("目前只支持256色位圖的離散傅立葉變換!", "系統提示" ,
//DEL MB_ICONINFORMATION | MB_OK);
//DEL
//DEL // 返回
//DEL return;
//DEL }
//DEL
//DEL // 圖象的寬長
//DEL CSize sizeImage ;
//DEL int nWidth ;
//DEL int nHeight;
//DEL
//DEL // 獲得圖象的寬長
//DEL sizeImage = pDib->GetDimensions() ;
//DEL
//DEL nWidth = sizeImage.cx;
//DEL nHeight= sizeImage.cy;
//DEL
//DEL // 臨時變量
//DEL double dTmpOne;
//DEL double dTmpTwo;
//DEL
//DEL // 傅立葉變換豎直方向點數
//DEL int nTransHeight ;
//DEL
//DEL // 傅立葉變換水平方向點數
//DEL int nTransWidth ;
//DEL
//DEL // 計算進行傅立葉變換的點數 (2的整數次冪)
//DEL dTmpOne = log(nWidth)/log(2);
//DEL dTmpTwo = ceil(dTmpOne) ;
//DEL dTmpTwo = pow(2,dTmpTwo) ;
//DEL nTransWidth = (int) dTmpTwo ;
//DEL
//DEL // 計算進行傅立葉變換的點數 (2的整數次冪)
//DEL dTmpOne = log(nHeight)/log(2);
//DEL dTmpTwo = ceil(dTmpOne) ;
//DEL dTmpTwo = pow(2,dTmpTwo) ;
//DEL nTransHeight = (int) dTmpTwo ;
//DEL
//DEL // 計算圖象數據存儲每行需要的字節數
//DEL // BMP文件的每行數據存儲是DWORD對齊的
//DEL int nSaveWidth;
//DEL nSaveWidth = ( (nWidth << 3) + 31)/32 * 4 ;
//DEL
//DEL // 指向圖象數據的指針
//DEL LPBYTE lpImage ;
//DEL lpImage = pDib->m_lpImage ;
//DEL
//DEL // 圖象象素值
//DEL unsigned char unchValue;
//DEL
//DEL
//DEL // 指向時域數據的指針
//DEL complex<double> * pCTData ;
//DEL
//DEL // 指向頻域數據的指針
//DEL complex<double> * pCFData ;
//DEL
//DEL // 分配內存
//DEL pCTData=new complex<double>[nTransWidth * nTransHeight];
//DEL pCFData=new complex<double>[nTransWidth * nTransHeight];
//DEL
//DEL // 初始化
//DEL // 圖象數據的寬和高不一定是2的整數次冪,所以pCTData
//DEL // 有一部分數據需要補0
//DEL for(y=0; y<nTransHeight; y++)
//DEL {
//DEL for(x=0; x<nTransWidth; x++)
//DEL {
//DEL pCTData[y*nTransWidth + x]=complex<double>(0,0);
//DEL }
//DEL }
//DEL
//DEL // 把圖象數據傳給pCTData
//DEL for(y=0; y<nHeight; y++)
//DEL {
//DEL for(x=0; x<nWidth; x++)
//DEL {
//DEL unchValue = lpImage[y*nSaveWidth +x];
//DEL pCTData[y*nTransWidth + x]=complex<double>(unchValue,0);
//DEL }
//DEL }
//DEL
//DEL // 傅立葉正變換
//DEL DIBFFT_2D(pCTData, nWidth, nHeight, pCFData) ;
//DEL
//DEL // 臨時變量
//DEL double dTmp;
//DEL
//DEL for(y=0; y<nHeight; y++)
//DEL {
//DEL for(x=0; x<nWidth; x++)
//DEL {
//DEL dTmp = pCFData[y * nTransWidth + x].real()
//DEL * pCFData[y * nTransWidth + x].real()
//DEL + pCFData[y * nTransWidth + x].imag()
//DEL * pCFData[y * nTransWidth + x].imag();
//DEL
//DEL dTmp = sqrt(dTmp) ;
//DEL
//DEL // 為了顯示,需要對幅度的大小進行伸縮
//DEL dTmp /= 100 ;
//DEL
//DEL // 限制圖象數據的大小
//DEL dTmp = min(dTmp, 255) ;
//DEL
//DEL lpImage[y*nSaveWidth +x] = (unsigned char)(int)dTmp;
//DEL }
//DEL }
//DEL
//DEL // 為了在屏幕上顯示,我們把幅度值大的部分用黑色顯示
//DEL for(y=0; y<nHeight; y++)
//DEL {
//DEL for(x=0; x<nWidth; x++)
//DEL {
//DEL lpImage[y*nSaveWidth +x] = 255 - lpImage[y*nSaveWidth +x];
//DEL }
//DEL }
//DEL
//DEL // 刷新屏幕
//DEL Invalidate();
//DEL
//DEL // 釋放內存
//DEL delete pCTData;
//DEL delete pCFData;
//DEL pCTData = NULL;
//DEL pCFData = NULL;
//DEL
//DEL // 設置臟標記
//DEL pDoc->SetModifiedFlag(TRUE);
//DEL
//DEL // 更新視圖
//DEL pDoc->UpdateAllViews(NULL);
//DEL
//DEL // 恢復光標形狀
//DEL EndWaitCursor();
//DEL }
/*************************************************************************
*
* \函數名稱:
* OnDft2d()
*
* \輸入參數:
* 無
*
* \返回值:
* 無
*
* \說明:
* 運行二維傅立葉變換
*
*************************************************************************
*/
//DEL void CImageProcessingView::OnDft2d()
//DEL {
//DEL //圖象離散傅立葉變換
//DEL
//DEL //提示用戶,直接進行離散傅立葉變換的時間很長
//DEL MessageBox("沒有使用FFT,時間可能很長!", "作者提示" ,
//DEL MB_ICONINFORMATION | MB_OK);
//DEL
//DEL //更改光標形狀
//DEL BeginWaitCursor();
//DEL
//DEL // 循環控制變量
//DEL int y;
//DEL int x;
//DEL
//DEL CImageProcessingDoc * pDoc = (CImageProcessingDoc *)this->GetDocument();
//DEL CDib * pDib = pDoc->m_pDibInit;
//DEL
//DEL // 獲得圖象的頭文件信息
//DEL LPBITMAPINFOHEADER lpBMIH=pDib->m_lpBMIH;
//DEL
//DEL // 判斷是否是8-bpp位圖(這里為了方便,只處理8-bpp位圖的離散傅立葉變換)
//DEL if (lpBMIH->biBitCount != 8)
//DEL {
//DEL // 提示用戶
//DEL MessageBox("目前只支持256色位圖的離散傅立葉變換!", "系統提示" ,
//DEL MB_ICONINFORMATION | MB_OK);
//DEL
//DEL // 返回
//DEL return;
//DEL }
//DEL
//DEL //圖象的長寬大小
//DEL CSize sizeImage = pDib->GetDimensions();
//DEL int nWidth = sizeImage.cx ;
//DEL int nHeight = sizeImage.cy ;
//DEL
//DEL // 計算圖象數據存儲每行需要的字節數
//DEL // BMP文件的每行數據存儲是DWORD對齊的
//DEL int nSaveWidth;
//DEL nSaveWidth = ( (nWidth << 3) + 31)/32 * 4 ;
//DEL
//DEL // 指向圖象數據的指針
//DEL LPBYTE lpImage ;
//DEL lpImage = pDib->m_lpImage ;
//DEL
//DEL double * pTrRstRpart = new double [nWidth*nHeight];
//DEL double * pTrRstIpart = new double [nWidth*nHeight];
//DEL
//DEL ::DIBDFT_2D(pDib, pTrRstRpart,pTrRstIpart);
//DEL
//DEL // 臨時變量
//DEL double dTmp;
//DEL
//DEL for(y=0; y<nHeight; y++)
//DEL {
//DEL for(x=0; x<nWidth; x++)
//DEL {
//DEL dTmp = pTrRstRpart[y*nWidth + x] * pTrRstRpart[y*nWidth + x]
//DEL + pTrRstIpart[y*nWidth + x] * pTrRstIpart[y*nWidth + x];
//DEL
//DEL dTmp = sqrt(dTmp) ;
//DEL
//DEL // 為了顯示,需要對幅度的大小進行伸縮
//DEL dTmp /= 100 ;
//DEL
//DEL // 限制圖象數據的大小
//DEL dTmp = min(dTmp, 255) ;
//DEL
//DEL lpImage[y*nSaveWidth +x] = (unsigned char)(int)dTmp;
//DEL }
//DEL }
//DEL
//DEL // 為了在屏幕上顯示,我們把幅度值大的部分用黑色顯示
//DEL for(y=0; y<nHeight; y++)
//DEL {
//DEL for(x=0; x<nWidth; x++)
//DEL {
//DEL lpImage[y*nSaveWidth +x] = 255 - lpImage[y*nSaveWidth +x];
//DEL }
//DEL }
//DEL
//DEL // 釋放內存
//DEL delete pTrRstRpart;
//DEL pTrRstRpart=NULL ;
//DEL
//DEL delete pTrRstIpart;
//DEL pTrRstIpart=NULL ;
//DEL
//DEL // 設置臟標記
//DEL pDoc->SetModifiedFlag(TRUE);
//DEL
//DEL // 更新視圖
//DEL pDoc->UpdateAllViews(NULL);
//DEL
//DEL // 恢復光標形狀
//DEL EndWaitCursor();
//DEL
//DEL // 刷新屏幕
//DEL Invalidate();
//DEL }
//DEL void CImageProcessingView::OnFreqDct()
//DEL {
//DEL // 圖象的離散余弦變換
//DEL
//DEL // 更改光標形狀
//DEL BeginWaitCursor();
//DEL
//DEL // 獲取文檔
//DEL CImageProcessingDoc* pDoc = GetDocument();
//DEL
//DEL // 獲得圖象CDib類的指針
//DEL CDib * pDib = pDoc->m_pDibInit;
//DEL
//DEL // 獲得圖象的頭文件信息
//DEL LPBITMAPINFOHEADER lpBMIH=pDib->m_lpBMIH;
//DEL
//DEL // 判斷是否是8-bpp位圖(這里為了方便,只處理8-bpp位圖的離散余弦變換)
//DEL if (lpBMIH->biBitCount != 8)
//DEL {
//DEL // 提示用戶
//DEL MessageBox("目前只支持256色位圖的離散余弦變換!", "系統提示" ,
//DEL MB_ICONINFORMATION | MB_OK);
//DEL
//DEL // 返回
//DEL return;
//DEL }
//DEL
//DEL ::DIBDct(pDib);
//DEL
//DEL // 設置臟標記
//DEL pDoc->SetModifiedFlag(TRUE);
//DEL
//DEL // 更新視圖
//DEL pDoc->UpdateAllViews(NULL);
//DEL
//DEL // 恢復光標
//DEL EndWaitCursor();
//DEL
//DEL }
//DEL void CImageProcessingView::OnFreqHotelling()
//DEL {
//DEL // 圖象霍特林變換
//DEL
//DEL // 更改光標形狀
//DEL BeginWaitCursor();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -