-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Add BMP 16-bit grayscale support in imwrite and imread #18718
Copy link
Copy link
Closed
Labels
Hackathonhttps://opencv.org/opencv-hackathon-starts-next-week/https://opencv.org/opencv-hackathon-starts-next-week/category: documentationDocumentation fix or updateDocumentation fix or updatecategory: imgcodecspriority: low
Milestone
Description
System information (version)
- OpenCV => 4.5
- Operating System / Platform => any
- Compiler => any
Detailed description
ImgCodecs support reading and writing of Bitmaps (*.bmp) with imread and imwrite. BMP format has a wide variety of supported image types, like 8-bit RGB or others. The current implementation supports many of them (modules/imgcodecs/src/grfmt_bmp.cpp
), but unfortunately it does not support 16-bit grayscale format.
16-Bit grayscale format is only supported by other formats like PNG as the documentation says.
As BMP writing is fast, as there is no further image processing involved, I would like to see support for 16-bit grayscale Bitmaps.
Currently all 16-bit grayscale images are converted to 8-bit, which is not correct. (at least a warning "not supported" should appear).
Summary:
- imwrite .bmp 16-bit grayscale missing
- imread .bmp 16-bit grayscale missing
Thanks for helping
Steps to reproduce
#include <iostream>
#include <opencv2/imgcodecs.hpp>
int main(int argc, char *argv[])
{
cv::Mat imOut = cv::Mat::ones(cv::Size(1024, 768), CV_16UC1);
cv::imwrite("test.bmp", imOut);
std::cout << imOut.depth() << std::endl; // 2 = CV_16U
// saved image test.bmp has only 8-bit instead of 16-bit
cv::Mat imIn = cv::imread("test.bmp", cv::IMREAD_ANYDEPTH);
std::cout << imIn.depth() << std::endl; // 0 = CV_8U --> this is should be also 2 (CV_16U)
return 0;
}
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues,
answers.opencv.org, Stack Overflow, etc and have not found solution - I updated to 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
Hackathonhttps://opencv.org/opencv-hackathon-starts-next-week/https://opencv.org/opencv-hackathon-starts-next-week/category: documentationDocumentation fix or updateDocumentation fix or updatecategory: imgcodecspriority: low