📄 wvltdoc.cpp
字号:
cur = y * biAlign + x;
pData[biHeight - 1 - y][x] =lpData[cur];
}
}
//释放设备占用的显示缓存
//m_pBitmap = NULL;
//打开另外一幅用于融合的图像文件
MessageBoxA(NULL,_T("请在WvltDip\\Fusion目录中打开另外一幅图像,进行加权图像融合"),_T("Message"),MB_ICONEXCLAMATION|MB_OK);
while(!abs((int)strcmp(m_strFileFusion, cstrFileName)))
{
CFileDialog dlg( TRUE,NULL,NULL,
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
_T("Bitmap (*.BMP)|*.BMP|"));
if( dlg.DoModal()==IDOK )
cstrFileName = dlg.GetPathName();
//如果文件重名,提示重新打开文件
if(!abs((int)strcmp(m_strFileFusion, cstrFileName)))
MessageBoxA(NULL,_T("文件"+m_strFileFusion+"已打开,请打开该目录中另外一个文件"),_T("Message"),MB_ICONEXCLAMATION|MB_OK);
else
MessageBoxA(NULL,_T("用于图像融合的文件是:\n"+m_strFileFusion+"\n"+cstrFileName),_T("Message"),MB_ICONEXCLAMATION|MB_OK);
}
CWvltApp* App =(CWvltApp*) AfxGetApp();
CFrameWnd* pNewFrame1 = App->m_pImageTemplate1->CreateNewFrame(this, NULL);
App->m_pImageTemplate1->InitialUpdateFrame(pNewFrame1, this);
// Tile the two MDI children windows within the MDI frame window.
ASSERT_KINDOF(CMDIChildWnd, pNewFrame1);
CMDIFrameWnd* pMDIFrameWnd1 = ((CMDIChildWnd*)pNewFrame1)->GetMDIFrame();
ASSERT(pMDIFrameWnd1 != NULL);
pMDIFrameWnd1->MDICascade();
//读取位图数据,载入显示缓存中
ReadBitmap(cstrFileName, m_pTransfered1);
ReadBitmap(cstrFileName, m_pTransfered);
//显示新打开的图像
UpdateAllViews(NULL);
//读取另外一幅图像的数据
lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pTransfered+14);
lpBitmapFileHeader = (LPBITMAPFILEHEADER)m_pTransfered;
unsigned char *lpImgData = m_pTransfered + lpBitmapFileHeader->bfOffBits;
//从设备的显示缓存中获取原始图像的数据
for(y = 0; y < biHeight; y ++)
{
for (x = 0; x < biWidth; x++)
{
cur = y * biAlign + x;
pDataFusion[biHeight - 1 - y][x] =lpImgData[cur];
}
}
//清空显示缓存,并重新分配显示缓存
m_pTransfered = NULL;
m_pTransfered=(unsigned char*) malloc (bmSize);
if(m_pTransfered==NULL)
return;
//创建用于图像融合的Diproc类
//CDiproc *pDIP;
// pDIP->DIP_ImageFusion(pData, pDataFusion, biHeight, biWidth);
// 进行空域融合处理
for(y = 0; y < biHeight; y ++)
{
for (x = 0; x < biWidth; x++)
{
if(pDataFusion[biHeight - 1 - y][x]>pData[biHeight - 1 - y][x])
pDataFusion[biHeight - 1 - y][x]=pData[biHeight - 1 - y][x];
}
}
//将图像数据放入显示缓存中
for(y=0; y<(int)biHeight; y++)
{
for(x=0; x<(int)biWidth; x++)
{
//cur= y*biAlign+3*x; //current pixel
cur= y*biAlign+x;
m_pTransfered[cur] = (unsigned char)pDataFusion[biHeight - 1- y][x];
}
}
//显示图像复原的结果
UpdateAllViews(NULL);
//删除临时的数据内存空间
// delete pData;
// delete pDataFusion;
}
void CWvltDoc::OnFangchaFusion()
{
// TODO: Add your command handler code here
// TODO: Add your command handler code here
//读取数字图像的文件头,获取图像的属性参数
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 biAlign = (biWidth)/4 *4;
unsigned long bmSize = biHeight * biAlign;
//定义图像的内存数据空间指针
short **pData, **pDataFusion;
CString cstrFileName = m_strFileFusion;
//图像矩阵的坐标与像素数据
int x, y, cur;
// int tempR, tempG, tempB;
//分配图像的数据空间
pData = new short * [biHeight];
pDataFusion = new short * [biHeight];
for(int i = 0; i < biWidth; i ++)
{
pDataFusion[i] = new short [biWidth];
pData[i] = new short [biWidth];
}
//从设备的显示缓存中获取原始图像的数据
for(y = 0; y < (int) biHeight; y ++)
{
for(x = 0; x < (int) biWidth; x ++)
{
cur = y * biAlign + x;
pData[biHeight - 1 - y][x] =lpData[cur];
}
}
//释放设备占用的显示缓存
//m_pBitmap = NULL;
//打开另外一幅用于融合的图像文件
MessageBoxA(NULL,_T("请在WvltDip\\Fusion目录中打开另外一幅图像,进行加权图像融合"),_T("Message"),MB_ICONEXCLAMATION|MB_OK);
while(!abs((int)strcmp(m_strFileFusion, cstrFileName)))
{
CFileDialog dlg( TRUE,NULL,NULL,
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
_T("Bitmap (*.BMP)|*.BMP|"));
if( dlg.DoModal()==IDOK )
cstrFileName = dlg.GetPathName();
//如果文件重名,提示重新打开文件
if(!abs((int)strcmp(m_strFileFusion, cstrFileName)))
MessageBoxA(NULL,_T("文件"+m_strFileFusion+"已打开,请打开该目录中另外一个文件"),_T("Message"),MB_ICONEXCLAMATION|MB_OK);
else
MessageBoxA(NULL,_T("用于图像融合的文件是:\n"+m_strFileFusion+"\n"+cstrFileName),_T("Message"),MB_ICONEXCLAMATION|MB_OK);
}
CWvltApp* App =(CWvltApp*) AfxGetApp();
CFrameWnd* pNewFrame1 = App->m_pImageTemplate1->CreateNewFrame(this, NULL);
App->m_pImageTemplate1->InitialUpdateFrame(pNewFrame1, this);
// Tile the two MDI children windows within the MDI frame window.
ASSERT_KINDOF(CMDIChildWnd, pNewFrame1);
CMDIFrameWnd* pMDIFrameWnd1 = ((CMDIChildWnd*)pNewFrame1)->GetMDIFrame();
ASSERT(pMDIFrameWnd1 != NULL);
pMDIFrameWnd1->MDICascade();
//读取位图数据,载入显示缓存中
ReadBitmap(cstrFileName, m_pTransfered1);
ReadBitmap(cstrFileName, m_pTransfered);
//显示新打开的图像
UpdateAllViews(NULL);
//读取另外一幅图像的数据
lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pTransfered+14);
lpBitmapFileHeader = (LPBITMAPFILEHEADER)m_pTransfered;
unsigned char *lpImgData = m_pTransfered + lpBitmapFileHeader->bfOffBits;
//从设备的显示缓存中获取原始图像的数据
for(y = 0; y < biHeight; y ++)
{
for (x = 0; x < biWidth; x++)
{
cur = y * biAlign + x;
pDataFusion[biHeight - 1 - y][x] =lpImgData[cur];
}
}
//清空显示缓存,并重新分配显示缓存
m_pTransfered = NULL;
m_pTransfered=(unsigned char*) malloc (bmSize);
if(m_pTransfered==NULL)
return;
//创建用于图像融合的Diproc类
//CDiproc *pDIP;
// pDIP->DIP_ImageFusion(pData, pDataFusion, biHeight, biWidth);
// 进行空域融合处理
/*for(y = 0; y < biHeight; y ++)
{
for (x = 0; x < biWidth; x++)
{
if(pDataFusion[biHeight - 1 - y][x]>pData[biHeight - 1 - y][x])
pDataFusion[biHeight - 1 - y][x]=pData[biHeight - 1 - y][x];
}
}*/
unsigned long WndSum0, WndSum1;
unsigned long SUM0, SUM1;
for(y = 0; y < biHeight; y ++)
{
for(x =0; x < biWidth; x ++)
{
//初始化窗口中像素的和
WndSum0 = 0; WndSum1 = 0;
SUM0=0; SUM1=0;
//计算窗口中像素的和
for(int i = -2; i <= 2; i++)
{
for(int j = -2; j <= 2; j++)
{
if( (y+i) < 0 || (x+j) < 0 || (y+i) >= biHeight || (x+j) >= biWidth)
{
WndSum0 += 0;
WndSum1 += 0;
}
else
{
WndSum0 += pData[biHeight - 1 - y-i][x+j]*pData[biHeight - 1 - y-i][x+j];
WndSum1 += pDataFusion[biHeight - 1 - y-i][x+j]*pDataFusion[biHeight - 1 - y-i][x+j];
}
}
}
WndSum0=WndSum0/25;
WndSum1=WndSum1/25;
/*for(i = -2; i <= 2;i++)
{
for(int j = -2; j <= 2; j++)
{
if( (y+i) < 0 || (x+j) < 0 || (y+i) >=biHeight || (x+j) >= biWidth)
{
SUM0 += 0;
SUM1 += 0;
}
else
{
SUM0 += (pData[biHeight - 1 - y-i][x+j]-WndSum0)*(pData[biHeight - 1 - y-i][x+j]-WndSum0);
SUM1 += (pDataFusion[biHeight - 1 - y-i][x+j]-WndSum1)*(pDataFusion[biHeight - 1 - y-i][x+j]-WndSum1);
}
}
}
if(SUM0>SUM1)
pDataFusion[biHeight - 1 - y][x]=pData[biHeight - 1 - y][x];
// pDataFusion[y][x]=pData[y][x];*/
if(WndSum0>WndSum1)
pDataFusion[biHeight - 1 - y][x]=pData[biHeight - 1 - y][x];
//pDataFusion[y][x]=pData[y][x];
}
}
//将图像数据放入显示缓存中
for(y=0; y<(int)biHeight; y++)
{
for(x=0; x<(int)biWidth; x++)
{
//cur= y*biAlign+3*x; //current pixel
cur= y*biAlign+x;
m_pTransfered[cur] = (unsigned char)pDataFusion[biHeight - 1- y][x];
}
}
//显示图像复原的结果
UpdateAllViews(NULL);
//删除临时的数据内存空间
//delete pData;
//delete pDataFusion;
}
void CWvltDoc::OnPijuQd()
{
// TODO: Add your command handler code here
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 biAlign = (biWidth)/4 *4;
unsigned long bmSize = biHeight * biAlign;
//定义图像的内存数据空间指针
short **pData, **pDataFusion;
CString cstrFileName = m_strFileFusion;
//图像矩阵的坐标与像素数据
int x, y, cur;
//int tempR, tempG, tempB;
//分配图像的数据空间
pData = new short * [biHeight];
pDataFusion = new short * [biHeight];
for(int i = 0; i < biWidth; i ++)
{
pDataFusion[i] = new short [biWidth];
pData[i] = new short [biWidth];
}
//从设备的显示缓存中获取原始图像的数据
for(y = 0; y < (int) biHeight; y ++)
{
for(x = 0; x < (int) biWidth; x ++)
{
//cur = y * biAlign + 3 * x;
//tempB = lpData[cur];
//tempG = lpData[cur + 1];
//tempR = lpData[cur + 2];
//pData[biHeight - 1 - y][x] = 0.3 * tempR + 0.59 * tempG + 0.11 * tempB;
cur = y * biAlign + x;
pData[biHeight - 1 - y][x] =lpData[cur];
}
}
//释放设备占用的显示缓存
//m_pBitmap = NULL;
//打开另外一幅用于融合的图像文件
MessageBoxA(NULL,_T("请在WvltDip\\Fusion目录中打开另外一幅图像,进行图像融合"),_T("Message"),MB_ICONEXCLAMATION|MB_OK);
while(!abs((int)strcmp(m_strFileFusion, cstrFileName)))
{
CFileDialog dlg( TRUE,NULL,NULL,
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
_T("Bitmap (*.BMP)|*.BMP|"));
if( dlg.DoModal()==IDOK )
cstrFileName = dlg.GetPathName();
//如果文件重名,提示重新打开文件
if(!abs((int)strcmp(m_strFileFusion, cstrFileName)))
MessageBoxA(NULL,_T("文件"+m_strFileFusion+"已打开,请打开该目录中另外一个文件"),_T("Message"),MB_ICONEXCLAMATION|MB_OK);
else
{
MessageBoxA(NULL,_T("用于图像融合的文件是:\n"+m_strFileFusion+"\n"+cstrFileName),_T("Message"),MB_ICONEXCLAMATION|MB_OK);
}
}
//读取位图数据,载入显示缓存中
CWvltApp* App =(CWvltApp*) AfxGetApp();
CFrameWnd* pNewFrame1 = App->m_pImageTemplate1->CreateNewFrame(this, NULL);
App->m_pImageTemplate1->InitialUpdateFrame(pNewFrame1, this);
// Tile the two MDI children windows within the MDI frame window.
ASSERT_KINDOF(CMDIChildWnd, pNewFrame1);
CMDIFrameWnd* pMDIFrameWnd1 = ((CMDIChildWnd*)pNewFrame1)->GetMDIFrame();
ASSERT(pMDIFrameWnd1 != NULL);
pMDIFrameWnd1->MDICascade();
//读取位图数据,载入显示缓存中
ReadBitmap(cstrFileName, m_pTransfered1);
ReadBitmap(cstrFileName, m_pTransfered);
//显示新打开的图像
UpdateAllViews(NULL);
//读取另外一幅图像的数据
lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pTransfered+14);
lpBitmapFileHeader = (LPBITMAPFILEHEADER)m_pTransfered;
unsigned char *lpImgData = m_pTransfered + lpBitmapFileHeader->bfOffBits;
//从设备的显示缓存中获取原始图像的数据
for(y = 0; y < biHeight; y ++)
{
for (x = 0; x < biWidth; x++)
{
//cur = y * biAlign + 3 * x;
//tempB = lpImgData[cur];
//tempG = lpImgData[cur + 1];
//tempR = lpImgData[cur + 2];
//pDataFusion[biHeight - 1 - y][x] = 0.3 * tempR + 0.59 * tempG + 0.11 * tempB;
cur = y * biAlign + x;
pDataFusion[biHeight - 1 - y][x] =lpImgData[cur];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -