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

📄 图像增强技术.txt

📁 数字图像处理技术源代码
💻 TXT
字号:
//参数说明:
//hDIB 图像数据句柄
//n 对比增强的强度值
//函数说明:该函数实现图像对比度增强的功能
HDIB DIB::ContrastEnhance(HANDLE hDIB,int n)
{	
	//用来保存数据
	HDIB hNewDIB;
	LPBITMAPINFOHEADER lpbi;
	//源数据区和新数据去指针
	LPBYTE lpSDIBBits,lpDDIBBits;
	int width,height,wBytesPerLine;
	if(!hDIB)
		return NULL;
	//得到每行图像的字节数目
	wBytesPerLine = this->BytePerLine(hDIB);
	//锁定数据区
	lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB);
	width = lpbi->biWidth;
	height = lpbi->biHeight;
	lpSDIBBits = (LPBYTE)lpbi;
	//分配内存
	hNewDIB = GlobalAlloc(GHND,lpbi->biSize+lpbi->biSizeImage);
	if(!hNewDIB)
		return  NULL;
	lpDDIBBits = (LPBYTE)GlobalLock(hNewDIB);
	memcpy(lpDDIBBits,lpSDIBBits,lpbi->biSize);
	//使得两个指针指向数据区开始位置
	lpSDIBBits = lpSDIBBits + lpbi->biSize;
	lpDDIBBits = lpDDIBBits + lpbi->biSize;
	BYTE rgb;
	long lOffset;
	for(int i=0;i<height;i++)
		for(int j=0;j<width;j++)
		{	
			//得到点在数据区中的偏移
			lOffset = this->PixelOffset(i,j,wBytesPerLine);
			//得到数据
			rgb = *(lpSDIBBits+lOffset);
			//对比度增强
			this->IncreaseContrast(&rgb,n);
			//保存数据
			*(lpDDIBBits+lOffset++) = rgb;
			*(lpDDIBBits+lOffset++) = rgb;
			*(lpDDIBBits+lOffset  ) = rgb;
		}
		GlobalUnlock(hDIB);
		GlobalUnlock(hNewDIB);
		return hNewDIB;
}

void DIB::IncreaseContrast(BYTE *pByte,int n)
{	
	//根据参数n来调节对比度,n越大,对比越强烈
	int Low = n;
	int High = 255-n;
	float Grad = ((float)(High-Low))/255;
	//数据很小,设置为0
	if(*pByte<=Low)
		*pByte = 0;
	//中间数据,进行对比增强处理
	else if ((Low<*pByte)&&(*pByte<High))
		*pByte = (BYTE)((*pByte-Low)/Grad);
	//数据很大,设置为255
	else
		*pByte = 255;
}

⌨️ 快捷键说明

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