Skip to content

IMWRITE_JPEG_LUMA_QUALITY parameter doesn't work as expected in 3.2.0 #21857

@canberkgurel

Description

@canberkgurel
System information (version)
  • OpenCV => 3.2.0
  • Operating System / Platform => Ubuntu 18.04
  • Compiler => CMake VERSION 2.8.3 (Compiled with catkin build)
Detailed description

According to the documentation, the IMWRITE_JPEG_LUMA_QUALITY parameter is supported.

IMWRITE_JPEG_LUMA_QUALITY Separate luma quality level, 0 - 100, default is 0 - don’t use.

But I realized that when I set it to default 0 (don’t use), it still has an impact on the image. This is unexpected, if it’s set to 0, it shouldn’t have any impact on the image compression.

Steps to reproduce
    cv::Mat image;
    // read image
    // process image

    std::vector<int> img_compression_params;
    img_compression_params.push_back(cv::ImwriteFlags::IMWRITE_JPEG_QUALITY);
    img_compression_params.push_back(95); // quality is between 0 and 100 (the higher is the better). Default value is 95. 
    img_compression_params.push_back(cv::ImwriteFlags::IMWRITE_JPEG_PROGRESSIVE);
    img_compression_params.push_back(0); // Enable JPEG features, 0 or 1, default is False.
    img_compression_params.push_back(cv::ImwriteFlags::IMWRITE_JPEG_OPTIMIZE);
    img_compression_params.push_back(0); // Enable JPEG features, 0 or 1, default is False. 
    img_compression_params.push_back(cv::ImwriteFlags::IMWRITE_JPEG_RST_INTERVAL);
    img_compression_params.push_back(0); // JPEG restart interval, 0 - 65535, default is 0 - no restart. 
    img_compression_params.push_back(cv::ImwriteFlags::IMWRITE_JPEG_LUMA_QUALITY);
    img_compression_params.push_back(0); // Separate luma quality level, 0 - 100, default is 0 - don't use. 
    img_compression_params.push_back(cv::ImwriteFlags::IMWRITE_JPEG_CHROMA_QUALITY);
    img_compression_params.push_back(0); // Separate chroma quality level, 0 - 100, default is 0 - don't use. 

   // save processed image with specified compression parameters
   imwrite("compressed.jpg", image, img_compression_params);

This is where I think the parameter is used in the source code.

if( params[i] == IMWRITE_JPEG_LUMA_QUALITY )
{
if (params[i+1] >= 0)
{
luma_quality = MIN(MAX(params[i+1], 0), 100);
quality = luma_quality;
if (chroma_quality < 0)
{
chroma_quality = luma_quality;
}
}
}

This is the post I created on Stack Overflow and OpenCV forum.

This is what is written to the disk.

C7YUK

If I remove:

img_compression_params.push_back(cv::ImwriteFlags::IMWRITE_JPEG_LUMA_QUALITY);
img_compression_params.push_back(0); // Separate luma quality level, 0 - 100, default is 0 - don't use. 

This is what's written to the disk.

hAm0g

So, clearly IMWRITE_JPEG_LUMA_QUALITY=0 don't use is incorrect.

Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions