Brightchannel

You might also like

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

#include <opencv2/opencv.

hpp>

using namespace cv;

Mat enhanceImage(const Mat& inputImage, int windowSize, double enhanceFactor) {

// Convert the input image to grayscale

Mat grayImage;

cvtColor(inputImage, grayImage, COLOR_BGR2GRAY);

// Calculate the bright channel using a maximum filter

Mat brightChannel;

dilate(grayImage, brightChannel, Mat(), Point(-1, -1), windowSize, MORPH_RECT);

// Enhance the bright channel

addWeighted(grayImage, 1.0 + enhanceFactor, brightChannel, -enhanceFactor, 0, brightChannel);

// Create a color image with enhanced bright channel

Mat enhancedImage;

cvtColor(brightChannel, enhancedImage, COLOR_GRAY2BGR);

return enhancedImage;

int main() {

// Load an image from file


Mat inputImage = imread("path/to/your/image.jpg");

if (inputImage.empty()) {

std::cerr << "Error: Could not read the image." << std::endl;

return -1;

// Set parameters for enhancement

int windowSize = 15; // Adjust this according to your preference

double enhanceFactor = 0.2; // Adjust this according to your preference

// Enhance the image

Mat enhancedImage = enhanceImage(inputImage, windowSize, enhanceFactor);

// Display the original and enhanced images

imshow("Original Image", inputImage);

imshow("Enhanced Image", enhancedImage);

waitKey(0);

return 0;

You might also like