4
votes

I am creating a project, where I have to remove the background from the image and detect the object.

I am using canny edge detection for detecting edges and than finding contours and than draw contours on a masked image, but after canny edge detection, I am getting broken edges ,how to fix that.

For Canny edge detection, for Threshold parameter, I have tried using thresholding with otsu's method for higher and lower threshold, but it doesn't seem to give appropriate result. Further, I have tried finding the mean of pixel values, and finding

double high_threshold = 1.33 * d;
double low_threshold = 0.66 * d;

it is also not giving accurate result. what else I can do

Mat rgba = new Mat();
Utils.bitmapToMat(bitmap, rgba);
Mat edges = new Mat(rgba.size(), CvType.CV_8UC1);Imgproc.cvtColor(rgba, edges, Imgproc.COLOR_RGB2GRAY, 4);
Imgproc.GaussianBlur(edges, edges, new Size(3,3), 2); Mat thresh=new Mat();
double upper_threshold = Imgproc.threshold(edges,thresh,0,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C| Imgproc.THRESH_OTSU);
double lower_threshold = 0.1*upper_threshold;Imgproc.Canny(edges,edges,upper_threshold,lower_threshold,3,false);Mat mDilatedMat = new Mat();

Mat Meroded = new Mat();
double erosion_size=5;
double dilation_size=4;
Mat e=  Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new  Size(2*erosion_size + 1, 2*erosion_size+1));
Mat f=  Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new  Size(2*dilation_size + 1, 2*dilation_size+1));
Imgproc.dilate(edges, mDilatedMat,e);
Imgproc.erode(mDilatedMat, Meroded,f);
1
check if this helps - Nikhil
actually i m having issue in edge detection,and basically i have to detect edges of random images,so shape won't be a solution. actually i am converting the image into grayscale and there is issue of intensity maybe.. - shreya
Have you tried other edge detectors? Like LoG - Amitay Nachmani
@AmitayNachmani is it a good option to divide a larger image into blocks of 9 or 12 and then perform edge detection on each block - shreya
I think not. You will get discontinuities between the blocks and inside the blocks there will not be any change in the edges. - Amitay Nachmani

1 Answers

0
votes

You can improve your image extracted by sobel , canny or a different algorithm by applying edge linking algorithm. Many edge linking algorithms are avaliable to use such as hough transform, ant colony algorithm etc.