Multiscaleretinex

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

#include <iostream>

#include <opencv2/opencv.hpp>

using namespace cv;

using namespace std;

// Function to load an image

Mat loadImage(const string& imagePath) {

Mat image = imread(imagePath, IMREAD_COLOR);

if (image.empty()) {

cerr << "Error: Couldn't load image at " << imagePath << endl;

exit(EXIT_FAILURE);

return image;

// Function to apply multi-scale retinex

Mat multiScaleRetinex(const Mat& inputImage, double sigma) {

Mat retinexImage;

vector<Mat> channels;

// Split the image into channels

split(inputImage, channels);

// Apply multi-scale retinex on each channel


for (int i = 0; i < channels.size(); ++i) {

Mat logImage;

log(channels[i] + 1, logImage);

Mat blurredImage;

GaussianBlur(logImage, blurredImage, Size(0, 0), sigma);

channels[i] = logImage - blurredImage;

// Merge the channels to get the final retinex image

merge(channels, retinexImage);

return retinexImage;

// Function to enhance the image using a sigmoid function

Mat enhanceImage(const Mat& inputImage, double alpha, double beta) {

Mat enhancedImage;

Mat sigmoidInput = alpha * (inputImage - beta);

sigmoid(sigmoidInput, enhancedImage);

return enhancedImage;

int main() {

// Load the image

Mat originalImage = loadImage("path/to/your/image.jpg");


// Apply multi-scale retinex

double sigma = 50.0;

Mat retinexImage = multiScaleRetinex(originalImage, sigma);

// Enhance the image using a sigmoid function

double alpha = 0.8;

double beta = 0.5;

Mat enhancedImage = enhanceImage(retinexImage, alpha, beta);

// Display the original, retinex, and enhanced images

imshow("Original Image", originalImage);

imshow("Multi-Scale Retinex", retinexImage);

imshow("Enhanced Image", enhancedImage);

waitKey(0);

return 0;

You might also like