Segmenting pills from the background I just recently started out with Image processing and taken up a course related to it in Grad school. But I already have a project to do without too much information about the subject, however I've made some steady progress. I am trying to segment the pills from their respective backgrounds. For images with contrasting backgrounds, I've been able to segment the pills using Otsu's method. With regards to images with similar backgrounds, Otsu's method doesn't quite work. I've been reading quite a few papers with regards to segmenting, but most of the papers that I've read use a manual thresholding value depending upon the kind of image. Is it possible to detect the correct thresholding value and automatically threshold an image and use techniques such as seed-growing or clustering to segment the image ? 

The color space I've been using is Lab*, so I'd appreciate it if you could recommend the appropriate color space that I should be using too. 

The images in question:

original 1



result 1



original 2



result 2



original 3



result 3
If you want to use the thresholding approach, you should use an adaptive thresholding method if there are big lighting variations like in the 3rd example image (dsp question here).

Also, you should experiment with colorspaces, it's easy: the script to decompose the image into different colorspaces should be no more than a few lines long, and a lot of image viewers have that option available. The best one should be easy to determine just visually. If you want to read up on colorspaces, there's anothrt good dsp question here.

Finally, you might want to try a diffrent approach. One idea would be to do a not-perfect segmentation, then an edge detection, and finally using something like Hough transform for circles which also works fine on (incomplete) circle arches. (this idea is ofcourse only applicable to round pills)