Borda / pyImSegm

Image segmentation - general superpixel segmentation & center detection & region growing
https://borda.github.io/pyImSegm
BSD 3-Clause "New" or "Revised" License
373 stars 73 forks source link

low impact of GC pairwise regul. #11

Open Borda opened 6 years ago

Borda commented 6 years ago

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

Borda commented 6 years ago

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

Borda commented 6 years ago

"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 commented 5 years ago

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

Borda commented 4 years ago

probably can be solved by #21