How to improve thresholding
Hello,
I have an image and I would like apply threshold operation and detect the coin in my image. Right now I'm using Otsu's method, but even with different thresholding values and smoothing types, I couldn't get any clean output.
Is there any way that I can improve this outcome?
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
namedWindow("Threshold", CV_WINDOW_AUTOSIZE);
/// Load the source image
Mat src;
src = imread("1cent.png", 1);
Mat src_gray;
cvtColor(src, src_gray, CV_RGB2GRAY);
Mat smooth;
for (int i = 1; i < 32; i = i + 2)
{
GaussianBlur(src_gray, smooth, Size(i, i), 0, 0);
}
Mat thresh;
threshold(smooth, thresh, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);
imshow("Threshold", thresh);
waitKey(0);
return 0;
}
Source image:
Threshold output: