It allows to extract not only the bounding boxes, but also the region masks.
Feature computation and region merging loop is done in Python / PyTorch. The underlying graph segmentation [Felzenszwalb2004] is still OpenCV's cv2.ximgproc.segmentation.createGraphSegmentation.
This reimplementation follows the OpenCV's cv2.ximgproc.segmentation.createSelectiveSearchSegmentation. This reimplementation is slower than the original C++ (mainly due to region merging loop in Python, and PyTorch's slower computation of histogram distances), but allows for simpler experimentation.
Most of implementation should be running fine on GPU, but it is not tested yet (and the graph segmentation currently runs only on CPU anyway).
# pip install opencv-python-headless opencv-contrib-python-headless # or without -headless
# download github mirror of astronaut test image https://www.flickr.com/photos/nasacommons/16504233985/ small size: https://live.staticflickr.com/8674/16504233985_9f1060624e_w_d.jpg
# curl https://user-images.githubusercontent.com/1041752/127776719-f8abfd60-6640-48fb-8b70-a1b6f6ade5cf.jpg > ./examples/astronaut.jpg
# curl https://user-images.githubusercontent.com/1041752/138138584-6d0a07d4-5980-4da3-aace-34afa32836a1.JPEG > ./examples/n02869837_18068.JPEG
# curl https://raw.githubusercontent.com/opencv/opencv_extra/master/testdata/cv/ximgproc/model.yml.gz > ./examples/model.yml.gz
python3 demo.py --gradio
python3 demo.py -i ./examples/astronaut.jpg -o ./out/
# open test.png and test.png.gif
python3 demo.py -i ./examples/astronaut.jpg -o ./out/ --algo opencv
# open test.png
# pushd opencv_custom && make OPENCVLIBDIR=/path/to/opencv/lib/dir OPENCVINCLUDEDIR=/path/to/opencv/include/dir/opencv4 && popd
python3 demo.py -i ./examples/astronaut.jpg -o ./out/ --algo opencv_custom
# open test.png and test.png.gif
-
implement stochastic region merging option as in:
-
implement more straightforward HoG descriptor instead of gaussian derivatives with explicit rotation as in:
-
replace Python sets by Python bitsets-via-bignums to store lists of merged regions
-
implement color space treatment as in:
-
simplify graph construction as in:
-
implement local binary pattern as in:
-
switch to skimage.segmentation.felzenszwalb or FelzenSegment
-
compute color / texture histograms in uint8
-
replace with uint8 histogram computation: pytorch/pytorch#61819 pytorch/pytorch#32306 pytorch/pytorch#43867
-
replace histogram distance to be in uint8 when uint8 aggregation is available: pytorch/pytorch#55366
-
could PyTorch jit the region merging loop?
- https://github.com/AlpacaDB/selectivesearch/, https://github.com/vsakkas/selective-search
- https://github.com/belltailjp/selective_search_py
- https://github.com/saisrivatsan/selective-search
- https://github.com/ChenjieXu/selective_search
I copied some Kornia's color conversion utils: https://kornia.readthedocs.io/en/latest/color.html
@article{Uijlings13,
author = {J.R.R. Uijlings and K.E.A. van de Sande and T. Gevers and A.W.M. Smeulders},
title = {Selective Search for Object Recognition},
journal = {International Journal of Computer Vision},
year = {2013},
url = {https://ivi.fnwi.uva.nl/isis/publications/2013/UijlingsIJCV2013/UijlingsIJCV2013.pdf}
}
@article{Felzenszwalb2004,
author = {Felzenszwalb, Pedro F. and Huttenlocher, Daniel P.},
title = {Efficient Graph-Based Image Segmentation},
journal = {International Journal of Computer Vision},
year = {2004},
url = {http://people.cs.uchicago.edu/pff/papers/seg-ijcv.pdf}
}
@inproceedings{Manen2013,
author = {Manen, Santiago and Guillaumin, Matthieu and Van Gool, Luc},
title = {Prime Object Proposals with Randomized Prim's Algorithm},
booktitle = {Proceedings of the IEEE International Conference on Computer Vision (ICCV)},
year = {2013},
url = {https://openaccess.thecvf.com/content_iccv_2013/papers/Manen_Prime_Object_Proposals_2013_ICCV_paper.pdf}
}
- https://github.com/davidstutz/graph-based-image-segmentation
- https://github.com/luisgabriel/image-segmentation
- https://infoscience.epfl.ch/record/177415
- https://www.morethantechnical.com/2010/05/05/bust-out-your-own-graphcut-based-image-segmentation-with-opencv-w-code/
- https://www.morethantechnical.com/2017/10/30/revisiting-graph-cut-segmentation-with-slic-and-color-histograms-wpython/