⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pro2view.cpp

📁 用VC++写的关于数字图像处理的程序源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		}
	}

	for(i=0;i<256;i++)
	{
		m_Chart.m_nStat[i]=0;
	}

	for(m=0;m<nHeight;m++)
	{
		for(n=0;n<nWidth;n++)
		{
			lpSrc=(unsigned char*)pDbImage+m*nWidth+n;					
			m_Chart.m_nStat[*(lpSrc)]=m_Chart.m_nStat[*(lpSrc)]+1;
		}
	}

	}

	delete pDbImage;

	return TRUE;
}

//************************************Smooth
void CPro2View::OnSmooth() 
{
	// TODO: Add your command handler code here

	pFile=new CFile(m_sFile,CFile::modeReadWrite|CFile::typeBinary);
	
	Dib.Read(pFile);
	Dib.MakePalette();

	double model[9]={1.0,2.0,1.0,2.0,4.0,2.0,1.0,2.0,1.0};
	double coef;
	coef=1.0/16.0;

	GeneralTemplate(&Dib,3,3,1,1,model,coef);

//	m_Chart.DoModal();

	pFile->Close();
	Invalidate();
	
}

BOOL CPro2View::GeneralTemplate(CDib* pDib,int nTempWidth,int nTempHeight,int nTempCenX,int nTempCenY,double* pdbTemp,double dbCoef)
{
	int i,j;
	int nWidth=pDib->m_lpBMIH->biWidth;
	int nHeight=pDib->m_lpBMIH->biHeight;

	switch(pDib->m_lpBMIH->biBitCount)
	{
	case 24:
		m_nRGBBit=3;
		break;
	case 32:
		m_nRGBBit=4;
		break;
	default:
		m_nRGBBit=3;
	}

	CSize sizeImageSave=pDib->GetDibSaveDim();

	unsigned char* pDbTemp;
	unsigned char* pDbImage;
	BYTE *pBits;
	int nRGB=0;

	pDbImage=new unsigned char[nWidth*nHeight];

	if(!pDbImage) return FALSE;

	//get data of the source DIB
	for(nRGB=0;nRGB<3;nRGB++)
	{

	for(j=0;j<nHeight;j++)
	{
		pDbTemp=pDbImage+j*nWidth;
		pBits=pDib->m_lpImage+(nHeight-j-1)*sizeImageSave.cx+nRGB;
		for(i=0;i<nWidth;i++)
		{
		//yes, the below is to get one color value among B,G,R.
			pDbTemp[i]=(unsigned char)(*(pBits+i*m_nRGBBit));
		}
	}

	unsigned char* lpSrc;
	unsigned char* lpDst;
	double dbResult;

	for(i=nTempCenY;i<nHeight-nTempHeight+nTempCenY+1;i++)
	{
		for(j=nTempCenX;j<nWidth-nTempWidth+nTempCenX+1;j++)
		{
			lpDst=(unsigned char*)pDbImage+i*nWidth+j;

			dbResult=0;

			for(int k=0;k<nTempHeight;k++)
			{
				for(int l=0;l<nTempWidth;l++)
				{
					lpSrc=(unsigned char*)pDbImage+(i-nTempCenY+k)*nWidth+(j-nTempCenX+l);
					dbResult+=(*lpSrc)*pdbTemp[k*nTempWidth+l];
				}
			}

			dbResult*=dbCoef;

			dbResult=(double)fabs(dbResult);

			if(dbResult>255)
				*lpDst=255;
			else
				*lpDst=(unsigned char)(dbResult+0.5);
		}
	}


	for(j=0;j<nHeight;j++)
	{
		pDbTemp=pDbImage+j*nWidth;
		pBits=pDib->m_lpImage+(nHeight-j-1)*sizeImageSave.cx+nRGB;
		for(i=0;i<nWidth;i++)
		{
			*(pBits+i*m_nRGBBit)=pDbTemp[i];
		}
	}

	}

	delete pDbImage;

	return TRUE;
	
}


//************************************Mixfilter
void CPro2View::OnMixfilter() 
{
	// TODO: Add your command handler code here

	pFile=new CFile(m_sFile,CFile::modeReadWrite|CFile::typeBinary);
	
	Dib.Read(pFile);
	Dib.MakePalette();

	Filter(&Dib);

	pFile->Close();
	Invalidate();
}

BOOL CPro2View::Filter(CDib* pDib)
{
	CPro2Doc* pDoc=GetDocument();

	int i,j;
	int m,n;

	double nRadius=100.0;
	int nGet=0;
	double H=0.0;

	int nWidth=pDib->m_lpBMIH->biWidth;
	int nHeight=pDib->m_lpBMIH->biHeight;

	switch(pDib->m_lpBMIH->biBitCount)
	{
	case 24:
		m_nRGBBit=3;
		break;
	case 32:
		m_nRGBBit=4;
		break;
	default:
		m_nRGBBit=3;
	}

	CSize sizeImageSave=pDib->GetDibSaveDim();

	double *pDbTemp;
	BYTE *pBits;
	int nRGB=0;

	if(!m_pDbImage)	{
			m_pDbImage=new double[nWidth*nHeight];
			if(!m_pDbImage) return FALSE;

	}

	//get data of the source DIB
	for(nRGB=0;nRGB<3;nRGB++)
	{

	for(j=0;j<nHeight;j++)
	{
		pDbTemp=m_pDbImage+j*nWidth;
		pBits=pDib->m_lpImage+(nHeight-j-1)*sizeImageSave.cx+nRGB;
		for(i=0;i<nWidth;i++)
		{
		//yes, the below is to get one color value among B,G,R.
			pDbTemp[i]=(double)(*(pBits+i*m_nRGBBit));
		}
	}

	//*****************************
	//
	for(m=0;m<nHeight;m++)
	{
		pDbTemp=m_pDbImage+m*nWidth;
		for(n=0;n<nWidth;n++)
		{
			if(pDbTemp[n]==0)
				continue;

			pDbTemp[n]=log(pDbTemp[n]);
		}
	}

	//FFT
	double dTmpOne;
	double dTmpTwo;

	int nTransWidth;
	int nTransHeight;

	dTmpOne=log(nWidth)/log(2);
	dTmpTwo=ceil(dTmpOne);
	dTmpTwo=pow(2,dTmpTwo);
	nTransWidth=(int)dTmpTwo;

	dTmpOne=log(nHeight)/log(2);
	dTmpTwo=ceil(dTmpOne);
	dTmpTwo=pow(2,dTmpTwo);
	nTransHeight=(int)dTmpTwo;

	complex<double>* pCTData;
	complex<double>* pCFData;

	pCTData=new complex<double>[nTransWidth*nTransHeight];
	pCFData=new complex<double>[nTransWidth*nTransHeight];

	for(m=0;m<nTransHeight;m++)
	{
		for(n=0;n<nTransWidth;n++)
		{
			pCTData[m*nTransWidth+n]=complex<double>(0,0);
		}
	}

	for(m=0;m<nHeight;m++)
	{
		pDbTemp=m_pDbImage+m*nWidth;
		for(n=0;n<nWidth;n++)
		{
			pCTData[m*nTransWidth+n]=complex<double>(pDbTemp[n],0);
		}
	}

	//FFT
	pDoc->FFT_2D(pCTData,nWidth,nHeight,pCFData);

	//apply the Butterworth filter.
	for(m=0;m<nTransHeight;m++)
	{
		for(n=0;n<nTransWidth;n++)
		{
			nGet=m*m+n*n;
			H=(double)nGet/(nGet+nRadius*nRadius);
			pCFData[m*nTransWidth+n]=
				complex<double>(H*pCFData[m*nTransWidth+n].real(),H*pCFData[m*nTransWidth+n].imag());
		}
	}

	//IFFT
	pDoc->IFFT_2D(pCFData,nWidth,nHeight,pCTData);

	double dTemp;

	for(m=0;m<nHeight;m++)
	{
		pDbTemp=m_pDbImage+m*nWidth;
		for(n=0;n<nWidth;n++)
		{
			dTemp=pCTData[m*nTransWidth+n].real()*pCTData[m*nTransWidth+n].real()
				 +pCTData[m*nTransWidth+n].imag()*pCTData[m*nTransWidth+n].imag();

			dTemp=exp(dTemp);

			dTemp=sqrt(dTemp)/600;

			dTemp=min(dTemp,255);
			
			pDbTemp[n]=dTemp;
		}
	}

	for(j=0;j<nHeight;j++)
	{
		pDbTemp=m_pDbImage+j*nWidth;
		pBits=pDib->m_lpImage+(nHeight-j-1)*sizeImageSave.cx+nRGB;
		for(i=0;i<nWidth;i++)
		{
			*(pBits+i*m_nRGBBit)=FloatToByte(pDbTemp[i]);
		}
	}

	}

	return TRUE;
}

//************************************Definition
void CPro2View::OnDefinition() 
{
	// TODO: Add your command handler code here

	pFile=new CFile(m_sFile,CFile::modeReadWrite|CFile::typeBinary);
	
	Dib.Read(pFile);
	Dib.MakePalette();

	DefinFun1(&Dib);

	m_Defin.DoModal();

	pFile->Close();
	Invalidate();
	
}

BOOL CPro2View::DefinFun1(CDib* pDib)
{
	int i,j;
	int nWidth=pDib->m_lpBMIH->biWidth;
	int nHeight=pDib->m_lpBMIH->biHeight;

	switch(pDib->m_lpBMIH->biBitCount)
	{
	case 24:
		m_nRGBBit=3;
		break;
	case 32:
		m_nRGBBit=4;
		break;
	default:
		m_nRGBBit=3;
	}

	CSize sizeImageSave=pDib->GetDibSaveDim();

	double* pDbTemp;
	double* pDbImage;
	BYTE *pBits;
	int nRGB=0;

	pDbImage=new double[nWidth*nHeight];

	if(!pDbImage) return FALSE;

	//get data of the source DIB

	for(j=0;j<nHeight;j++)
	{
		pDbTemp=pDbImage+j*nWidth;
		pBits=pDib->m_lpImage+(nHeight-j-1)*sizeImageSave.cx;
		for(i=0;i<nWidth;i++)
		{
			nRGB=0;

			for(nRGB=0;nRGB<3;nRGB++)
			{
				if(nRGB==0)//blue
					pDbTemp[i]=(double)0.11*(*(pBits+i*m_nRGBBit+nRGB));

				if(nRGB==1)//green
					pDbTemp[i]+=(double)0.59*(*(pBits+i*m_nRGBBit+nRGB));
	
				if(nRGB==2)//red
					pDbTemp[i]+=(double)0.30*(*(pBits+i*m_nRGBBit+nRGB));
			}
		}
	}

	double* lpSrc;
	double* lpDst;
	double dbResult=0;
	double dTemp;
	double dCen;

	//calculate the definition value.
	for(i=1;i<nHeight-1;i++)
	{
		for(j=1;j<nWidth-1;j++)
		{
			lpDst=(double*)pDbImage+i*nWidth+j;

			dCen=*lpDst;

			lpSrc=(double*)pDbImage+(i-1)*nWidth+(j);
			dTemp=(double)fabs(dCen-(*lpSrc));
			dbResult+=dTemp;

			lpSrc=(double*)pDbImage+(i)*nWidth+(j-1);
			dTemp=(double)fabs(dCen-(*lpSrc));
			dbResult+=dTemp;

			lpSrc=(double*)pDbImage+(i+1)*nWidth+(j);
			dTemp=(double)fabs(dCen-(*lpSrc));
			dbResult+=dTemp;

			lpSrc=(double*)pDbImage+(i)*nWidth+(j+1);
			dTemp=(double)fabs(dCen-(*lpSrc));
			dbResult+=dTemp;

		}
	}

	m_Defin.m_Value=dbResult/100;

	delete pDbImage;

	return TRUE;
}


void CPro2View::OnPicfile() 
{
	// TODO: Add your command handler code here
	CDialogIm dialog;
	dialog.DoModal();
	m_sFile=dialog.m_sFileName;

	m_bOne=TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -