实验八 #include <cv.h> #include <highgui.h> //图像视频输出/输入头文件 int main() { IplImage * test; IplImage * test_1; test = cvLoadImage("6013202130.bmp",0);//图片路径是 ConsoleApplication4 文件夹里,同时实验要求转为灰度图片 test_1 = cvCreateImage(cvSize((test->width), (test->height)), IPL_DEPTH_8U, 1); //创建图像,给指针赋值 CvScalar s; for (int i = 0; i < test->height; i++) { for (int j = 0; j < test->width; j++) { s = cvGet2D(test, i, j); s.val[0] = 32 * log10(s.val[0]) / log10(2.0); cvSet2D(test_1, i, j, s); } } cvNamedWindow("原图—6013202130", CV_WINDOW_AUTOSIZE); cvShowImage("原图—6013202130", test); cvNamedWindow("对数变换—6013202130", CV_WINDOW_AUTOSIZE); cvShowImage("对数变换—6013202130", test_1); cvWaitKey(0);//等待按键 cvDestroyWindow("原图—6013202130"); cvDestroyWindow("对数变换—6013202130"); cvReleaseImage(&test);//释放内存。 cvReleaseImage(&test_1); return 0; }