Image.cpp
上传用户:gzboli
上传日期:2013-04-10
资源大小:471k
文件大小:2k
- // Image.cpp: implementation of the CImage class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "QuickImage.h"
- #include "Image.h"
- #include <math.h>
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CImage::CImage()
- {
- *m_szPathName=' ';
- m_iWidth=m_iHeight=0;
- }
- CImage::~CImage()
- {
- }
- BOOL CImage::ReadFromFile(const LPCTSTR lpszFile)
- {
- return TRUE;
- }
- HDIB CImage::Show()
- {
- return NULL;
- }
- void CImage::Properties(int *Histogram, double &dMean, double &dStdDev, double &dShang,
- const LPSTR lpBits, int iPixels, int iColors)
- {
- ASSERT(NULL != lpBits);
- ASSERT(NULL != Histogram);
- int iValue;
- dMean = dStdDev = dShang = 0.0;
- for(int i = 0; i< 256; i++)
- {
- Histogram[i] = 0;
- }
- if(iColors < 257)
- {
- BYTE *pBits = (BYTE*)lpBits;
- for(i =0; i< iPixels; i++, pBits++)
- {
- Histogram[*pBits] ++;
- }
-
- for(i = 0; i < 256; i++)
- {
- iValue = Histogram[i];
- dMean += iValue * i;
- if(iValue != 0)
- {
- dStdDev = (double)iValue / iPixels;
- dShang -= dStdDev * log10(dStdDev) / log10(2.0);
- }
- }
- dMean /= (double)iPixels;
-
- pBits = (BYTE*)lpBits;
- dStdDev = 0;
- double d;
- for(i = 0; i < iPixels; i++, pBits++)
- {
- d = double(*pBits) - dMean;
- dStdDev += (d * d);
- }
- dStdDev = sqrt(dStdDev / iPixels);
- }
- else
- {
- //int iGray;
- }
- }
- const HDIB CImage::HistoEqualize(const HDIB hDIB)
- {
- ASSERT(NULL != hDIB);
- LPSTR lpDIB = (LPSTR)GlobalLock(hDIB);
- if(NULL == lpDIB)
- {
- return NULL;
- }
- int iWidth = ::DIBWidth(lpDIB);
- int iPixel = iWidth * abs(::DIBHeight(lpDIB));
- int iColors = ::DIBNumColors(lpDIB);
- int Histogram[256];
- double dMean, dStdDev, dShag;
- LPSTR lpBits = ::FindDIBBits(lpDIB);
- double dGray = 255.0 / (double)iPixel;
- int i;
- HDIB hRet = NULL;
- if(iColors < 257)
- {
- Properties(Histogram, dMean, dStdDev, dShag, lpBits, iPixel, iColors);
- for(i = 1 ; i < 256; i++)
- {
- Histogram[i] += Histogram[i-1];
- }
- BYTE *pByte = (BYTE*)lpBits;
- for(i = 0; i < iPixel; i++, pByte++)
- {
- *pByte = BYTE(dGray * Histogram[*pByte]);
- }
- hRet = ::GenBmp(iWidth, ::DIBHeight(lpDIB), 8, (BYTE*)lpBits);
- }
- else
- {
- }
- GlobalUnlock(hDIB);
- return hRet;
- }