The Raw2RGB project is a pipeline designed to process raw Bayer images (.tiff
format) captured from Emergent HB-50000 cameras. The images used for development and testing were taken from multiple Emergent HB-50000 cameras, making this tool optimized for multi-camera setups, where each camera has its own directory for storing captured images. Instead of processing a single file, the program efficiently processes entire folders of images, making it ideal for setups where multiple cameras capture data simultaneously. While optimized for Emergent HB-50000 cameras, this tool can potentially work with raw Bayer images generated by other camera systems.
The default Bayer mode for Emergent HB-50000 cameras is 48 (CV_BayerRG2RGB_EA), but the tool allows you to choose other Bayer modes supported by OpenCV. These modes can be passed as an argument when running the tool. You can find details about available Bayer modes and their respective codes on the OpenCV documentation site.
With an Intel Core i9-10940X CPU @ 3.30GHz, the pipeline processes images at a rate of approximately 0.3 seconds per image, ensuring high performance and scalability for large datasets.
-
Loading and Inspecting Images:
- Loads raw Bayer
.tiff
files. - Prints details about images, such as depth, channel count, and specific pixel values.
- Loads raw Bayer
-
Dead Pixel Correction:
- Identifies and corrects dead pixels using SIMD optimization for performance.
-
Vignetting Correction:
- Estimates vignetting coefficients using entropy minimization.
- Applies vignetting correction using the estimated vignette parameters.
- Supports exporting and loading of vignette correction maps.
-
Gamma Correction:
- Applies gamma correction to images for adjusting brightness and contrast.
-
Demosaicing:
- Converts raw Bayer images into RGB images based on Bayer patterns using OpenCV's demosaicing functions.
-
Batch Processing:
- Automatically scans a directory for
.tiff
files, processes them, and saves the results in.png
format to an output folder.
- Automatically scans a directory for
-
Performance Optimization:
- Uses AVX-512, AVX, and SSE instructions for SIMD-enhanced performance during pixel corrections and image processing.
- Employs parallel processing with OpenMP for multi-threaded performance across large image datasets.
-
OpenCV 4.x or above
-
C++17 standard or higher
-
Supported SIMD Features:
- AVX-512, AVX, or SSE (depending on hardware)
-
OpenMP (for parallelization)
-
CMake (Minimum version 3.10)
-
A compatible C++ compiler supporting C++17:
- GCC 7+ / Clang 5+ / MSVC 2017+
-
Ensure
libopencv-dev
is installed on the system or linked manually.
- Clone the repository:
git clone <repository_url>
cd Raw2RGB
- Run CMake to generate the build files:
mkdir build
cd build
cmake ..
- Build the project:
cmake --build .
- Execute the binary (details provided in the Usage section).
Run the executable with the following parameters:
Raw2RGB <input_directory> <output_directory> <demosaicMode> <gamma> <vignette_path>
<input_directory>
— Folder containing input.tiff
files.<output_directory>
— Folder to store the processed.png
files.<demosaicMode>
— OpenCV demosaicing mode (e.g.,CV_BayerRG2RGB
).<gamma>
— Gamma correction factor (e.g.,2.2
).<vignette_path>
— Optional vignette correction.dat
file. If not present, the correction is skipped.
Example:
Raw2RGB ./raw_images ./processed_images CV_BayerRG2RGB 2.2 vignette_map.dat
Function: loadImage(const std::string &imagePath)
Loads the raw Bayer image from the specified file.
cv::Mat image = loadImage("image.tiff");
Function: saveImage(const std::string &imagePath, const cv::Mat &image)
Saves an image to the specified path.
saveImage("output.png", image);
Function: correctDeadPixels(cv::Mat& rawImage, float brightFactor, float darkFactor)
Corrects defective pixel regions in raw Bayer images.
correctDeadPixels(image, 1.5, 0.75);
Function: applyVignetteCorrection(const cv::Mat& rawBayer, const VignetteModel& model)
Applies vignette correction using a pre-computed correction map.
VignetteModel model = estimateVignetting(image, "vignette.dat", "RG", 3);
image = applyVignetteCorrection(image, model);
Function: processImages(const std::vector<Image> &images, const int demosaicMode, const double gamma, const std::string &vignettePath)
Processes multiple images by loading the input files, applying corrections, and saving the results.
std::vector<Image> images = getRawFiles("input_folder", "output_folder");
processImages(images, CV_BayerRG2RGB, 2.2, "vignette.dat");
Function: estimateVignetting(const cv::Mat& rawBayer, const std::string &outPath, const std::string& bayerPattern, int polyDegree)
Calculates vignette correction coefficients by minimizing entropy on a Bayer-patterned image.
Function: calculateEntropy(const float a, const float b, const float c, const cv::Mat& img)
Helps determine optimal vignette correction coefficients by calculating image entropy.
.
├── include/
│ ├── image_process.h # Header for processing functions
├── src/
│ ├── main.cpp # Entry point
│ ├── image_process.cpp # Image processing implementation
├── CMakeLists.txt # Build configuration
└── README.md # Documentation
- SIMD optimizations may not work on hardware without AVX, SSE, or similar instruction sets.
- Add support for additional raw formats (e.g.,
.raw
,.dng
). - Implement undistort process with Metashape .xml data.
This project is licensed under the MIT license. See LICENSE for more details.
A special thanks to Peter Flaherty and Flaherty Pictures for their support and generosity in open-sourcing this project. Their commitment to open-source development makes this work accessible to the community.