I have a noisy image with several bright spots that I need to identify and analyze. I’ve tried using simple thresholding techniques, but the noise level is too high, and it’s difficult to isolate the spots accurately.
Here is an example of my image with the spots I want to identify:
[![noisy background with bright spots][1]][1]
I am using OpenCV with C++ and would appreciate guidance on the best approach to identify these spots. Specifically, I need help with:
- Preprocessing the image to reduce noise and increase the visibility of the spots.
- Identifying and isolating the bright spots.
- Outline the identified spots.
This is what I have tried so far:
#include <opencv2/opencv.hpp>
int main() {
cv::Mat image = cv::imread("image.png", cv::IMREAD_GRAYSCALE);
if (image.empty()) {
return -1;
}
// Thresholding to create a binary image
cv::Mat binaryImage;
cv::threshold(image, binaryImage, 200, 255, cv::THRESH_BINARY);
// Finding contours
std::vector<std::vector<cv::Point>> contours;
cv::findContours(binaryImage, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
// Drawing contours
cv::Mat outputImage = cv::Mat::zeros(image.size(), CV_8UC3);
for (size_t i = 0; i < contours.size(); i++) {
cv::drawContours(outputImage, contours, (int)i, cv::Scalar(0, 0, 255), 2);
}
cv::imwrite("output.png", outputImage);
return 0;
}
[1]: https://i.sstatic.net/3Kw9Q1sl.jpg