Search code examples
imageopencvcomputer-visionsegment

Image Segmentation


So I am trying to write some code that lets me segment the fuses you see in the picture below. I have come up with two approaches:

1) Based on color. I threshold using OpenCV's inRange function. This approach works well for all fuses except the brown fuse. The brown fuse it too similar in colour with the fusebox itself and therefore it's very hard to segment it out.

2) I considered thresholding the image heavily so that I can detect the white points/terminals on the fuses themselves using OpenCV SimpleBlobDetector. I then filter out the blobs by their distances to each other. As I know the size of the fuses, I can filter out the invalid fuses. This approach works well for all fuses but the white one as it appears in even the most thresholded images.

I was hoping I could get a pointer on how to segment such an image. Would background subtraction work?

enter image description here


Solution

  • My experience with segmentation is that a single approach frequently does not work for difficult segmentation. I if one algorithm works for all but brown and the other all but white, the union of the two should yield a complete result. I know it is nice to have one elegant algorithm, but many of my best results have had to resort to the hybrid of multiple techniques.

    I'd consider separating the channels into rgb and hue, saturation, and value and looking at each channel separately. Sometimes browns that look very similar in color are have significantly different saturation or color channel values. Adding and subtracting different channels can also sometimes enhance contrast. This is simple but in many cases produces a fast and simple output that can be used for thresholding, watershed (see below), or perhaps background subtraction.

    I think you might also want to try the watershed algorithm. Many examples and explainations are available. Watershed requires that you provide a mask that contains the background (the fusebox and table) and a piece of each of the foreground objects (fuses). As I understand it, you already can detect the contacts on the fuses so that piece is done.

    Another approach is to just accept you can't see brown fuses. If you can detect empty slots and every other color, you may be able to know by deduction where the brown ones are.

    It's had to know what will work beforehand without some experimentation, but this should give you some ideas of how to improve what you have.