pyImSegm icon indicating copy to clipboard operation
pyImSegm copied to clipboard

low impact of GC pairwise regul.

Open Borda opened this issue 7 years ago • 4 comments

Description

Investigate an issue with nearly zero impact of the pairwise term in GraphCut segmentation on small elements with high confidence belonging to one class. Even these peaces are composed only a few superpixels, and the regularisation is set on maximum, they do not disappear...

image

import os
from skimage import segmentation, io
import matplotlib.pylab as plt

import imsegm.utils.data_io as tl_io
import imsegm.pipelines as seg_pipe

name = 'Lh05-04'
PATH_IMAGES = os.path.join(tl_io.update_path('data_images'), 'langerhans_islets')
img = io.imread(os.path.join(PATH_IMAGES, 'image', name + '.jpg'))
annot = io.imread(os.path.join(PATH_IMAGES, 'annot', name + '.png'))
# plt.imshow(img), plt.contour(annot, colors='b')

img_red = img[:, :, 0]
SLIC_SIZE = 25
SLIC_REGUL = 0.2
DICT_FEATURES = {'color': ['mean', 'median']}

model_seg, list_slic, _, _ = seg_pipe.train_classif_color2d_slic_features([img_red], [annot], DICT_FEATURES, sp_size=SLIC_SIZE, sp_regul=SLIC_REGUL)

plt.figure()
plt.imshow(segmentation.mark_boundaries(img[800:900, 1100:1300], list_slic[0][800:900, 1100:1300], color=(1, 1, 1)))

segm_gc, seg_soft = seg_pipe.segment_color2d_slic_features_model_graphcut(img_red, model_seg, DICT_FEATURES, sp_size=SLIC_SIZE, sp_regul=SLIC_REGUL, gc_edge_type='ones', gc_regul=5000000.)

plt.figure()
plt.imshow(segm_gc), plt.contour(annot, colors='g'), plt.title('segmenatation')

plt.figure(figsize=(10, 3))
plt.subplot(1, 2, 1), plt.imshow(seg_soft[800:900, 1100:1300, 0]), plt.title('class 0'), plt.colorbar()
plt.subplot(1, 2, 2), plt.imshow(seg_soft[800:900, 1100:1300, 1]), plt.title('class 1'), plt.colorbar()

image image

Way to reproduce

  • [x] Code example
  • [x] Relevant images
  • [x] packages version (gco-wrapper==3.0.3)

Borda avatar Jul 12 '18 20:07 Borda

Probably investigate some numerical instability in GraphCut, compute the global energy with and without assimilated the small region (bottom right).

Borda avatar Aug 08 '18 15:08 Borda

"Have you looked at opengm? I'm pretty sure they have their own implementation. Opencv does, too..." https://github.com/amueller/gco_python/issues/18

Borda avatar Oct 08 '18 10:10 Borda

Have look at https://networkx.github.io

Borda avatar Apr 09 '19 09:04 Borda

probably can be solved by #21

Borda avatar Oct 12 '20 17:10 Borda