Ask Your Question
0

specify the compression ratio of JPEG 2000

asked 2018-12-26 01:18:29 -0600

Digital Design gravatar image

updated 2018-12-26 01:30:49 -0600

berak gravatar image

Hi all, I am trying to compress an RGB image with JPEG 2000 in opencv c++.

    Mat x= imread("/home/amir/Downloads/aaaa.jpg", CV_LOAD_IMAGE_COLOR);
    vector<int> compression_params;
    compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
    compression_params.push_back(1);
int n= 1;
    while (n!= 0)
    {
        cout<< "Enter the compression ratio: ";
        cin>> n;
        compression_params[1]= n;
        cout<< "well, the compression ratio= "<< int(compression_params[1])<< endl;
        bool save_JPEG = imwrite(jpeg_st, x, compression_params);
        //bool save_JPEG = imwrite(jpeg_st, x);
        if (!save_JPEG) 
        {
            cout << "Couldn't save the file" << endl;
            cout << "Press any ket to halt the program" << endl;
            getch();
            return 0;
        }

        temp= imread(jpeg_st, CV_LOAD_IMAGE_ANYCOLOR);
        namedWindow("The compressed image", WINDOW_FULLSCREEN );
        imshow("The compressed image", temp);
        waitKey(0);
        namedWindow("The host image", WINDOW_FULLSCREEN );
        imshow("The host image", temp);
        waitKey(0);
        destroyAllWindows();

        temp.convertTo(temp, CV_64FC3);
        x.convertTo(x, CV_64FC3);
        cout<< GetPSNR2d(x, temp)<< endl;
    }

This is a psuedo-code for reading the compression ratio of the JPEG2000. Then it shows compressed image and displays the PSNR of the compressed image. Surprisingly, DESPITE THE COMPRESSION RATIO (even for the compression ratio of 20), the PSNR always remains infinite and no artifact is observed in the compressed image!!! how can it be possible?????????????????????????????????????!!!!!!!!!!!!!!!!!!!!! Conversely, in Matlab the PSNR depends on the compression ratio but it seems like the opencv is simply ignoring the compression ratio. In opencv documentation ( https://docs.opencv.org/3.0-beta/modu... ) it says that: "On Linux, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for codecs supplied with an OS image. Install the relevant packages (do not forget the development files, for example, “libjpeg-dev”, in Debian and Ubuntu*) to get the codec support or turn on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake." Does anyone have experience of using JPEG2000 in opencv c++ by Linux Mint and cmake? How will you set OPENCV_BUILD_3RDPARTY_LIBS in cmake?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2018-12-26 01:29:37 -0600

berak gravatar image

updated 2018-12-26 01:35:19 -0600

but it seems like the opencv is simply ignoring the compression ratio

yes. there are no compression flags for jpeg2000, only for jpg.

building the 3rdparty libs from src won't change anything here, but the resp. cmake flags would be:

cmake -DBUILD_JASPER -DBUILD_PNG -DBUILD_TIFF -DBUILD_JPEG

, etc.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-12-26 01:18:29 -0600

Seen: 1,472 times

Last updated: Dec 26 '18