Adaptive automatic enhancing image for detecting objects. Following cpp opencv code:
void AutoEnhanceAdaptivePreprocessing(const cv::Mat& inputImage, cv::Mat& outputImage)
{// Step 1: Convert to grayscale (if not already)
cv::Mat grayImage;
if (inputImage.channels() == 3)
cv::cvtColor(inputImage, grayImage, cv::COLOR_BGR2GRAY);else
grayImage = inputImage.clone();
//adaptive histogram equalization
// Step 2: Apply CLAHE for adaptive histogram equalization
cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(2.0, cv::Size(8, 8)); // ClipLimit=2.0, TileGridSize=8x8
cv::Mat claheImage;
clahe->apply(grayImage, claheImage);
// Step 3: Denoising using GaussianBlur
cv::Mat denoisedImage;
cv::GaussianBlur(claheImage, denoisedImage, cv::Size(5, 5), 0);
// Step 4: Enhance contrast and brightness
double alpha = 1.5; // Contrast control (1.0-3.0)
int beta = 20; // Brightness control (0-100)
cv::Mat contrastEnhancedImage = denoisedImage.clone();
denoisedImage.convertTo(contrastEnhancedImage, -1, alpha, beta);
cv::cvtColor(contrastEnhancedImage, outputImage, cv::COLOR_GRAY2RGB);
}
No comments:
Post a Comment