📄 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 + -