I am working on a project on image processing. I need to segment only the required object from the image and make the background white. For this I am detecting the edges in the image and then finding contours. I then draw the contour with the maximum area and finally copy it to a white background image.
But the issue with it is that while detecting edges, the edges are broken. On observing I realized that it is showing broken edges at that point where the intensity of foreground and background is the same. It doesn't find any change, thus no edge is detected. How do I fix this?
Actually, for this I am calculating the histogram of the image, and then finding the median from the histogram, but I am unable to find this.