-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
IMWRITE_JPEG_LUMA_QUALITY parameter doesn't work as expected in 3.2.0 #21857
Copy link
Copy link
Closed
Labels
bugcategory: documentationDocumentation fix or updateDocumentation fix or updatecategory: imgcodecsconfirmedThere is stable reproducer / investigation completeThere is stable reproducer / investigation complete
Milestone
Description
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.
opencv/modules/imgcodecs/src/grfmt_jpeg.cpp
Lines 662 to 675 in 9aa6470
| 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.
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.
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugcategory: documentationDocumentation fix or updateDocumentation fix or updatecategory: imgcodecsconfirmedThere is stable reproducer / investigation completeThere is stable reproducer / investigation complete

