amueller / gco_python

Python wrappers for GCO alpha-expansion and alpha-beta-swaps
137 stars 65 forks source link

3-class segmentation #9

Closed Borda closed 9 years ago

Borda commented 10 years ago

Hello, may have a question about you wrapper for GraphCut. I found it very nice and compare to other wrapper, this one s most useful. Btw, My name is Jiří Borovec and I am a PhD student at CTU in Prague and actually I am working on segmentation and registrations so I would like to use this method. I was testing basic image (see attachment - sample_seg_3cls.jpg) which should be simply segmented into 3 classes. I did following steps: 1) extract SLIC superpixels 2) compute colour feature per superpixel 3) estimate Gaussian Mixture Model (GMM) 4) assume each component of GMM should be single class so compute probability that each segment belong to each class ...so far up to here everything works fine... 5) construct graph and apply GraphCut but it returns only 2-class segmentation (see attachment - figure_1.png). On the other hand, when I take simply maximal a-posteriory probability from step 4) I can get what I would expect (see attachment - figure_2.png) from GraphCut... By my knowledge if I would use zero pairwise potentials the Graph Cut should give the equal results as treasholding by maximal a-posteriory probability, ok?

The part of code I am speaking about is following: logger.info('Extraction segment connectivity') vertices, edges = superpixels.makeGraph4Connect(segments) logger.debug( "Graph connectivity edges: \n" + repr( edges ) ) pairwise = -10 * np.eye(nbCls) logger.info('Run GraphCut on created graph.') edges = np.array(edges, dtype=np.int32) unaries = np.array( (100*prob) , dtype=np.int32) logger.debug( "Graph unaries potentials: \n" + repr( unaries ) ) pairwise = np.array( pairwise , dtype=np.int32) logger.debug( "Graph pairwise coefs: \n" + repr( pairwise ) ) resultGraph = cut_from_graph(edges, unaries, pairwise) logger.debug( "Resulting graph: \n" + repr( resultGraph ) ) In attachment you can find all three files, the main is graphCut.py

Thanks for any advice

sample_seg_3cls figure_1 figure_2

amueller commented 9 years ago

Sorry, it seems I missed your question. Did you figure it out?

Borda commented 9 years ago

yes, but I do not remember what it was, probably a sign issue... Btw, do you plan ti integrate it into scikit-learn? It would be nice.

amueller commented 9 years ago

No, as the input types are different (graphs vs (n_samples, n_features) nd-arrays). I'm planning to make the use and integration better, though.

Borda commented 9 years ago

I mean my fault with a sign not yours...

amueller commented 9 years ago

Ok, thanks :) My comment was with respect to the integration with scikit-learn. Signs are pretty pesky, I spent some time on them...