程序:
效果:增加图像亮度
代码:
#include "cv.h" #include "cxcore.h" #include "highgui.h" #include <iostream> void Max(IplImage* hsv) { for(int rows=0;rows<hsv->height;rows++) { float *data=(float *)(hsv->imageData+rows*hsv->widthStep); for(int cols=0;cols<hsv->width;cols++) { //*(data+cols*hsv->nChannels+1)=255; //改变S *(data+cols*hsv->nChannels+2)+=30; //改变V } } } int IplImageChange(int argc,char** argv) { IplImage* BGRSrc=cvLoadImage("e:\\picture\\4.jpg"); cvNamedWindow("BGRSrc"); cvShowImage("BGRSrc",BGRSrc); IplImage* BGR32=cvCreateImage(cvGetSize(BGRSrc),32,BGRSrc->nChannels); cvZero(BGR32); cvConvertScale(BGRSrc,BGR32);//把源图像转换成32位浮点型 IplImage* HSV=cvCreateImage(cvGetSize(BGRSrc),32,BGRSrc->nChannels); cvZero(HSV); cvCvtColor(BGR32,HSV,CV_BGR2HSV);//BGR转换为HSV cvNamedWindow("HSV"); cvShowImage("HSV",HSV); Max(HSV); //改变HSV cvNamedWindow("HSVMax"); cvShowImage("HSVMax",HSV); cvZero(BGR32); cvCvtColor(HSV,BGR32,CV_HSV2BGR); //HSV转换为BGR32位 cvNamedWindow("BGR32Dst"); cvShowImage("BGR32Dst",BGR32); IplImage* BGRDst=cvCreateImage(cvGetSize(BGRSrc),8,BGRSrc->nChannels); cvZero(BGRDst); cvConvertScale(BGR32,BGRDst); //BGR32位转换为BGR8位 cvNamedWindow("BGRDst"); cvShowImage("BGRDst",BGRDst); cvWaitKey(0); cvDestroyWindow("BGRSrc"); cvDestroyWindow("HSV"); cvDestroyWindow("HSVMax"); cvDestroyWindow("BGR32Dst"); cvDestroyWindow("BGRDst"); cvReleaseImage(&BGRSrc); cvReleaseImage(&BGR32); cvReleaseImage(&HSV); cvReleaseImage(&BGRDst); return 0; }
改变HSV的H和V部分(比如可以增加图像亮度)
时间: 2024-12-18 10:41:00