Posts

Showing posts with the label superpixels

Superpixels for Python - pretty SLIC

Image
Yesterday I wanted to try out a "new" superpixel algorithm that seemed quite successful: SLIC superpixels . This is actually a very simple algorithm, basically doing KMeans in the color+(x,y) space. I'm a bit bummed that they named that, since I already tried the same approach a couple of years ago and didn't think it was very useful. Well, apparently it is. The authors have a nice website with some examples. Unfortunately the linux binary didn't run on my box and building on linux seemed somewhat non-trivial. So I did what I always do: wrote some Python wrappers. You can find them on github [update] I did an implementation for scikit-image which is now quite mature thanks to some other contributors. I would recommend using that instead if you want SLIC in python.[/update]. The whole thing is pretty small, easy to build and easy to use. Also damn fast (less than a second per image). There are two variations, one where you can specify the number of superpi...

Region connectivity graphs in Python [edit: minor bug]

Image
[edit] Nowadays you can find  much better implementations of this over at scikit-image. [/edit] Recently I started playing with CRFs on superpixels for image segmentation. While doing this I noticed that Python has very little methods for morphological operations on images. For example I did not find any functions to exctract connected components inside images. For CRFs one obviously needs the superpixel neighbourhood graph to work on and I didn't find any ready made function to obtain it. After some pondering, I came up with something. Since I didn't find anything else online I thought I'd share it. def make_graph(grid): # get unique labels vertices = np.unique(grid) # map unique labels to [1,...,num_labels] reverse_dict = dict(zip(vertices,np.arange(len(vertices)))) grid = np.array([reverse_dict[x] for x in grid.flat]).reshape(grid.shape) # create edges down = np.c_[grid[:-1, :].ravel(), grid[1:, :].ravel()] right = np.c_[grid...