Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why my imshow differs from imwrite

I am using OpenCV 2.4.8 on VS2013. I have the following snippet of code:

    Mat img_sum = Mat::zeros(img_gray.size(), CV_32F);
    char file_name[FILENAME_MAX];
    for (int i = 0; i < SCALE_SIZE; i++){
        for (int j = 0; j < ORIENTATION_SIZE; j++){
            Mat srcImg;
            g_gabor[i*ORIENTATION_SIZE + j].conv_img(img_gray, srcImg, CV_GABOR_REAL);

            memset(file_name, NULL, FILENAME_MAX);
            sprintf_s(file_name, "gabor_images/%d_%d.png", i, j);
            imwrite(file_name, srcImg);
            imshow("Gabor滤波结果", srcImg);    //此时srcImg.type() == 1
            waitKey(100);
        }
    }
    imwrite("img_sum.png", img_sum);

The key issue is result of imwrite and imshow. They gave me different result.

The imshow image: imshow image

And, the imwrite image: imwrite image

I was wonderring if the reason is the image type. If so, how to convert image type to solve the problem.

like image 834
Frank Avatar asked Mar 12 '23 13:03

Frank


1 Answers

With type CV_32F, you have to multiply your image by 255 before using imwrite.

Try imwrite(file_name, 255 *srcImg);.

like image 91
Sunreef Avatar answered Mar 20 '23 06:03

Sunreef