#include \
#include \#include
IplImage* image[2] = { 0, 0 }, *image0 = 0, *image1 = 0; CvSize size;
int w0, h0,i;
int threshold1, threshold2; int l,level = 4;
int sthreshold1, sthreshold2; int l_comp;
int block_size = 1000; float parameter; double threshold;
double rezult, min_rezult;
CvFilter filter = CV_GAUSSIAN_5x5; CvConnectedComp *cur_comp, min_comp; CvSeq *comp;
CvMemStorage *storage;
CvPoint pt1, pt2;
void ON_SEGMENT(int a) {
cvPyrSegmentation(image0, image1, storage, &comp, level, threshold1+1, threshold2+1); /*l_comp = comp->total;
i = 0;
min_comp.value = cvScalarAll(0); while(i cur_comp = (CvConnectedComp*)cvGetSeqElem ( comp, i ); if(fabs(255- min_comp.value.val[0])> fabs(255- cur_comp->value.val[0]) && fabs(min_comp.value.val[1])> fabs(cur_comp->value.val[1]) && fabs(min_comp.value.val[2])> fabs(cur_comp->value.val[2]) ) min_comp = *cur_comp; i++; }*/ cvShowImage(\} int main( int argc, char** argv ) { char* filename = argc == 2 ? argv[1] : (char*)\ if( (image[0] = cvLoadImage( filename, 1)) == 0 ) return -1; cvNamedWindow(\ cvShowImage(\ cvNamedWindow(\ storage = cvCreateMemStorage ( block_size ); image[0]->width &= -(1< threshold1 =255; threshold2 =30; ON_SEGMENT(1); sthreshold1 = cvCreateTrackbar(\&threshold1, 255, ON_SEGMENT); sthreshold2 = cvCreateTrackbar(\&threshold2, 255, ON_SEGMENT); cvShowImage(\ cvWaitKey(0); cvDestroyWindow(\ cvDestroyWindow(\ cvReleaseMemStorage(&storage ); cvReleaseImage(&image[0]); cvReleaseImage(&image0); cvReleaseImage(&image1); return 0; } 图像的亮度变换 郁闷,以前用过MatLab,很长时间没用了,都不知道怎么使了,据说做这个效果很不错。 效果图: 源代码: #include \ #include \/* src and dst are grayscale, 8-bit images; Default input value: [low, high] = [0,1]; X-Direction [bottom, top] = [0,1]; Y-Direction gamma ; if adjust successfully, return 0, otherwise, return non-zero. */ int ImageAdjust(IplImage* src, IplImage* dst, double low, double high, // X方向:low and high are the intensities of src double bottom, double top, // Y方向:mapped to bottom and top of dst double gamma ) { if( low<0 && low>1 && high <0 && high>1&& bottom<0 && bottom>1 && top<0 && top>1 && low>high) return -1; double low2 = low*255; double high2 = high*255; double bottom2 = bottom*255; double top2 = top*255; double err_in = high2 - low2; double err_out = top2 - bottom2; int x,y; double val; // intensity transform for( y = 0; y < src->height; y++) { for (x = 0; x < src->width; x++) { val = ((uchar*)(src->imageData + src->widthStep*y))[x]; val = pow((val - low2)/err_in, gamma) * err_out + bottom2; if(val>255) val=255; if(val<0) val=0; // Make sure src is in the range [low,high] ((uchar*)(dst->imageData + dst->widthStep*y))[x] = (uchar) val; } } return 0; } int main( int argc, char** argv ) { IplImage *src = 0, *dst = 0; if( argc != 2 || (src=cvLoadImage(argv[1], 0)) == NULL) // force to gray image return -1; cvNamedWindow( \ cvNamedWindow( \ // Image adjust dst = cvCloneImage(src); // 输入参数 [0,0.5] 和 [0.5,1], gamma=1 if( ImageAdjust( src, dst, 0, 0.5, 0.5, 1, 1)!=0) return -1; cvShowImage( \ cvShowImage( \ cvWaitKey(0); cvDestroyWindow(\ cvDestroyWindow(\ cvReleaseImage( &src ); cvReleaseImage( &dst );