Skip to content

Adding possibility to select the compression type for the OpenEXR format#19295

Closed
hallonterror wants to merge 3 commits intoopencv:masterfrom
hallonterror:master
Closed

Adding possibility to select the compression type for the OpenEXR format#19295
hallonterror wants to merge 3 commits intoopencv:masterfrom
hallonterror:master

Conversation

@hallonterror
Copy link
Copy Markdown

@hallonterror hallonterror commented Jan 8, 2021

There are compression modes other than the default that are more suited for certain data. Mainly grainy/noisy data.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • [-] There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

…mat. There are compression modes other than the default that are more suited for certain data. Mainly grainy/noisy data.
@asmorkalov asmorkalov changed the title Adding possibility to select the compression type for the OpenEXR for… Adding possibility to select the compression type for the OpenEXR format Jan 11, 2021
@asmorkalov
Copy link
Copy Markdown
Contributor

asmorkalov commented Jan 11, 2021

@hallonterror Thanks for the useful option. Couple of proposals for the solution:

  • OpenCV team stores test data in extra repository: https://github.com/opencv/opencv_extra/. You can add your test image there, or, better re-use one of the images, if it's applicable. So you do not need #ifndef in test code. If you decided to add new image to opencv_extra please submit PR there and add opencv_extra=<your branch_name> to the PR rescription body to apply it on BuildBot automatically.
  • The test just checks that the image is loaded correctly, but not option itself. As soon as compression option introduces significant size change I propose to add size check as simple heuristic. Please do not forget to add comment there to cover the heuristic purpose.

@asmorkalov asmorkalov self-requested a review January 11, 2021 12:51
CV_IMWRITE_PNG_STRATEGY_FIXED =4,
CV_IMWRITE_PXM_BINARY =32,
CV_IMWRITE_EXR_TYPE = 48,
CV_IMWRITE_EXR_COMPRESSION = 49,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legacy C files should not be touched anymore.
Please remove this change.

header.compression() = DWAB_COMPRESSION;
break;
default:
throw std::runtime_error("IMWRITE_EXR_COMPRESSION is invalid or not supported");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CV_Error(Error::StsBadArg, ...)

Copy link
Copy Markdown
Author

@hallonterror hallonterror Jan 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be done although the CV_IMWRITE_EXR_TYPE throws? See line 592.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Reverting change to legacy/constants_c.h.
@hallonterror
Copy link
Copy Markdown
Author

@hallonterror Thanks for the useful option. Couple of proposals for the solution:

  • OpenCV team stores test data in extra repository: https://github.com/opencv/opencv_extra/. You can add your test image there, or, better re-use one of the images, if it's applicable. So you do not need #ifndef in test code. If you decided to add new image to opencv_extra please submit PR there and add opencv_extra=<your branch_name> to the PR rescription body to apply it on BuildBot automatically.
  • The test just checks that the image is loaded correctly, but not option itself. As soon as compression option introduces significant size change I propose to add size check as simple heuristic. Please do not forget to add comment there to cover the heuristic purpose.

I know of the test data in opencv_extra. I think it should be sufficient to use one of the already existing image files (like it is in the added unit test (modules/imgcodecs/test/test_exr.impl.hpp), even though it wont show a compression advantage on those files.

For the second point you are absolutely right. I did verify that the parameter had effect exactly this way, by checking that the file size was not the same as the previously existing unit test without the flag set. It's of course reasonable to add this as a check in the test suite. I will look into that!

Adding size check that ensures that the selection of PIZ compression has an effect on file size.
For this particular file it gets larger. For other suitable image content the file should be smaller.
ASSERT_EQ(CV_32FC1,img.type());

ASSERT_TRUE(cv::imwrite(filenameOutput, img));
ASSERT_EQ(getFileSize(filenameOutput), 396);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comment why you check file size here. It's important for test, but not obvious for other contributors.

ASSERT_EQ(CV_32FC1, img.type());

ASSERT_TRUE(cv::imwrite(filenameOutput, img, params));
ASSERT_EQ(getFileSize(filenameOutput), 849);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same for file size here.

header.compression() = DWAB_COMPRESSION;
break;
default:
throw std::runtime_error("IMWRITE_EXR_COMPRESSION is invalid or not supported");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

@asmorkalov
Copy link
Copy Markdown
Contributor

asmorkalov commented Jan 25, 2021

@hallonterror Please take a look on CI status. BuildBot reports build issue:

/build/precommit_linux64/opencv/modules/imgcodecs/src/grfmt_exr.cpp: In member function 'virtual bool cv::ExrEncoder::write(const cv::Mat&, const std::vector<int>&)':
/build/precommit_linux64/opencv/modules/imgcodecs/src/grfmt_exr.cpp:595:27: error: 'CV_IMWRITE_EXR_COMPRESSION' was not declared in this scope
         if ( params[i] == CV_IMWRITE_EXR_COMPRESSION )

@asmorkalov
Copy link
Copy Markdown
Contributor

@hallonterror Friendly reminder.

@asmorkalov
Copy link
Copy Markdown
Contributor

@hallonterror Do you have a chance to finish the patch?

@asmorkalov
Copy link
Copy Markdown
Contributor

@hallonterror Friendly reminder.

@asmorkalov asmorkalov mentioned this pull request Feb 16, 2021
6 tasks
@asmorkalov
Copy link
Copy Markdown
Contributor

@hallonterror Unfortunatelly I cannot push changes to you PR branch as you do it in master. I cherry picked the commits and created new PR with code review fixes: #19540

@asmorkalov asmorkalov closed this Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants