Better background isolation.
At the moment we are using rather simple technique to find shreds on a coloured background, which is coded here: https://github.com/dchaplinsky/unshred/blob/master/unshred/sheet.py#L165
It seems to be well commented, but if you need any info — feel free to contact me for clarifications.
This technique has pros:
- Simple
- Very quick
- Produces good enough result. and cons:
- It requires some manual work to make it work with new background colour (when you need to find diapason of HSV colours that will be threaten as a background). So it's not very robust (however, we have relatively small amount of different backgrounds, say, dozen or so).
- in some cases it has problems when shred is not glued properly and has shadow or two shreds are glued too close to each other. I'll append some examples below.
I've tried different techniques, including:
- Flood fill with different settings (however I did that in RGB space, so probably Lab or HSV will have better results). Results were unstable and slow.
- Grabcut using diapason technique above as a seed. I've also tried to apply different kinds of erode/dilate/smooth stuff to seed mask. Results were unstable and VERY slow.
Probably we can benefit from some kind of adaptive thresholding from here

Here is grabcut solution.
If that will help: there are fairly easy way to determine overlapping shreds like in example above: https://github.com/dchaplinsky/unshred/blob/master/unshred/features/geometry.py#L21
In general I think we might benefit from some heuristics based on geometry. Say, for example, if our shred is likely to be not isolated properly we might apply more aggressive algorithm on it.
Can we use this to help separating shreds that are glued together? http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_imgproc/py_watershed/py_watershed.html#watershed