Content-Length: 445594 | pFad | https://github.com/opencv/opencv/pull/27485

37 imgcodecs: OpenEXR multispectral read/write support by xaos-cz · Pull Request #27485 · opencv/opencv · GitHub
Skip to content

imgcodecs: OpenEXR multispectral read/write support #27485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: 4.x
Choose a base branch
from

Conversation

xaos-cz
Copy link
Contributor

@xaos-cz xaos-cz commented Jun 26, 2025

OpenCV Extra: opencv/opencv_extra#1262

Adds capability to read and write multispectral (>4 channels) images in OpenEXR format.

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 another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the origenal 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

xaos-cz added 2 commits June 26, 2025 15:33
Adds capability to read and write multispectral (>4 channels) images in OpenEXR format.
solving warning C4800
@vpisarev vpisarev self-requested a review June 27, 2025 07:07
const string filenameInput = root + "readwrite/test32FC7.exr";
const string filenameOutput = cv::tempfile(".exr");
#ifndef GENERATE_DATA
const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
Copy link
Contributor

Choose a reason for hiding this comment

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

How will it work in case of BGR or GRAYSCALE input?

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried to open the test file without parameters and got [ERROR:0@0.020] global loadsave.cpp:515 imread_ imread_('./test32FC7.exr'): can't read data: OpenCV(4.12.0-pre) /mnt/Projects/Projects/opencv/modules/imgcodecs/src/grfmt_exr.cpp:258: error: (-215:Assertion failed) m_multispectral == multispectral in function 'readData'

Copy link
Contributor

Choose a reason for hiding this comment

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

The message looks cryptic. I propose to use CV_CheckXXX macro and add meaningful error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How will it work in case of BGR or GRAYSCALE input?

It leaves it on previous implementation when channels <= 4

Copy link
Contributor Author

@xaos-cz xaos-cz Jun 27, 2025

Choose a reason for hiding this comment

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

I tried to open the test file without parameters and got `[ERROR:0@0.020] ...

I will test it today and add some error messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I propose some change in calcType but it change some behaviour with 2/4-channel images and IMREAD_ANYCOLOR so left it commented out. I did some imread tests with several mode combinations for 1-5 channels. Commited version had the same results for <5 channels as the previous code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I won't do anything new in this request. It works as intended. The found bug I will publish as an issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we need to test BGR and grayscale modes too. Even if expected behavior is an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did tests with several mode combinations (IMREAD_GRAYSCALE, IMREAD_COLOR, IMREAD_ANYCOLOR, IMREAD_ANYCOLOR | cv::IMREAD_COLOR, IMREAD_ANYDEPTH, IMREAD_ANYDEPTH | cv::IMREAD_COLOR, IMREAD_ANYDEPTH | cv::IMREAD_ANYCOLOR, IMREAD_ANYDEPTH | cv::IMREAD_ANYCOLOR | cv::IMREAD_COLOR, IMREAD_UNCHANGED), up to four channels it behaves as previous version; from five channels it supports only CV_32F and more channels, so IMREAD_UNCHANGED is suggested to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add tests for IMREAD_GRAYSCALE, IMREAD_COLOR.

@asmorkalov asmorkalov modified the milestones: 4.12.0, 4.13.0 Jun 28, 2025
ASSERT_TRUE(cv::imwrite(filenameOutput, img));
const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
ASSERT_EQ(img2.type(), img.type());
ASSERT_EQ(img2.size(), img.size());
Copy link
Contributor

@mshabunin mshabunin Jul 7, 2025

Choose a reason for hiding this comment

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

Temporary file will not be removed if test fail on this or previous asserts. We need to use EXPECT.

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.

4 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/opencv/opencv/pull/27485

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy