Example #1
0
    def test_segm_supervised(self):
        img = d_spl.load_sample_image(d_spl.IMAGE_DROSOPHILA_OVARY_2D)[:, :, 0]
        img = imresize(img, (256, 256))
        annot = d_spl.load_sample_image(d_spl.ANNOT_DROSOPHILA_OVARY_2D)
        annot = imresize(annot, (256, 256), interp='nearest')
        img2 = d_spl.load_sample_image(d_spl.IMAGE_DROSOPHILA_OVARY_2D)[:, :,
                                                                        0]
        img2 = imresize(img2, (256, 256))

        path_dir = os.path.join(PATH_OUTPUT, 'test_segm_supervised_gc')
        if not os.path.exists(path_dir):
            os.mkdir(path_dir)

        sp_size = 10
        tp_edge = ['model', 'const']
        list_regul = [0, 1, 10]
        dict_imgs = dict()
        name = 'fig-img%i_regul-%.2f_edge-%s.png'

        classif, _, _, _ = pipelines.train_classif_color2d_slic_features(
            [img], [annot], sp_size, dict_features=FEATURES_TEXTURE)

        _ = pipelines.segment_color2d_slic_features_classif_graphcut(
            img,
            classif,
            sp_size=sp_size,
            gc_regul=0.,
            dict_features=FEATURES_TEXTURE,
            dict_debug_imgs=dict_imgs)
        show_segm_debugs_2d(dict_imgs, path_dir, name % (1, 0, '_debug'))

        for edge in tp_edge:
            dict_imgs = dict()
            for regul in list_regul:
                seg = pipelines.segment_color2d_slic_features_classif_graphcut(
                    img,
                    classif,
                    sp_size=sp_size,
                    gc_regul=regul,
                    gc_edge_type=edge,
                    dict_features=FEATURES_TEXTURE)
                show_segm_results_2d(img, seg, path_dir,
                                     name % (1, regul, edge))

                seg = pipelines.segment_color2d_slic_features_classif_graphcut(
                    img2,
                    classif,
                    sp_size=sp_size,
                    gc_regul=regul,
                    gc_edge_type=edge,
                    dict_features=FEATURES_TEXTURE,
                    dict_debug_imgs=dict_imgs)
                show_segm_results_2d(img2, seg, path_dir,
                                     name % (2, regul, edge))
                show_segm_debugs_2d(dict_imgs, path_dir,
                                    name % (2, regul, edge))
                dict_imgs = None
Example #2
0
 def test_segm_gmm_gc_stars(self):
     img = d_spl.load_sample_image(d_spl.IMAGE_STAR_2)
     logging.debug('dimension: {}'.format(img.shape))
     params = dict(nb_classes=3,
                   sp_regul=0.2,
                   sp_size=25,
                   dict_features={'color': ['mean', 'std']})
     run_segm2d_gmm_gc(img, 'test_segm_gmm_gc_stars', dict_params=params)
Example #3
0
 def test_segm_gmm_gc_disc(self):
     img = d_spl.load_sample_image(d_spl.IMAGE_DROSOPHILA_DISC)
     img = imresize(img, (512, 512))
     params = dict(sp_regul=0.2, sp_size=15, pca_coef=0.98)
     run_segm2d_gmm_gc(img,
                       'test_segm_gmm_gc_disc',
                       types_edge=['model_l2'],
                       list_regul=[0, 1, 5],
                       dict_params=params)
Example #4
0
 def test_segm_gmm_gc_histo(self):
     img = d_spl.load_sample_image(d_spl.IMAGE_HISTOL_FLAGSHIP)
     img = imresize(img, (512, 512))
     params = dict(sp_regul=0.15, sp_size=15, pca_coef=0.98)
     run_segm2d_gmm_gc(img,
                       'test_segm_gmm_gc_histology',
                       types_edge=['model'],
                       list_regul=[0, 1, 5],
                       dict_params=params)
Example #5
0
    def test_segm_gmm_gc_langer(self):
        img = d_spl.load_sample_image(d_spl.IMAGE_LANGER_ISLET)
        img = imresize(img, (512, 512))
        params = dict(clr_space='hsv', sp_regul=0.15, sp_size=5)

        run_segm2d_gmm_gc(img,
                          'test_segm_gmm_gc_langer',
                          types_edge=['model_lT'],
                          list_regul=[0, 1],
                          dict_params=params)
Example #6
0
 def test_segm_gmm_gc_ovary_2d(self):
     img = d_spl.load_sample_image(d_spl.IMAGE_DROSOPHILA_OVARY_2D)[:, :, 0]
     img = imresize(img, (512, 512))
     # img = np.rollaxis(np.tile(img[:, :, 0], (3, 1, 1)), 0, 3)
     params = dict(nb_classes=4,
                   pca_coef=0.95,
                   sp_regul=0.3,
                   sp_size=10,
                   dict_features=seg_fts.FEATURES_SET_TEXTURE_SHORT)
     run_segm2d_gmm_gc(img,
                       'test_segm_gmm_gc_ovary_2d',
                       list_regul=[0, 2, 10],
                       dict_params=params)
Example #7
0
 def test_segm_gmm_gc_stars(self):
     img = d_spl.load_sample_image(d_spl.IMAGE_STAR_2)
     logging.debug('dimension: {}'.format(img.shape))
     params = {
         'nb_classes': 3,
         'pca_coef': 0.98,
         'sp_regul': 0.2,
         'sp_size': 25,
         'dict_features': {
             'color': ['mean', 'std']
         }
     }
     run_segm2d_gmm_gc(img, 'test_segm_gmm_gc_stars', dict_params=params)
Example #8
0
    def test_count_transitions_segment(self):
        img = d_spl.load_sample_image(d_spl.IMAGE_DROSOPHILA_OVARY_2D)[:, :, 0]

        annot = d_spl.load_sample_image(d_spl.ANNOT_DROSOPHILA_OVARY_2D)
        annot = annot.astype(int)

        slic = seg_spx.segment_slic_img2d(img, sp_size=15, rltv_compact=0.2)
        label_hist = seg_lb.histogram_regions_labels_norm(slic, annot)
        labels = np.argmax(label_hist, axis=1)
        trans = seg_gc.count_label_transitions_connected_segments({'a': slic},
                                                                  {'a': labels})
        path_csv = os.path.join(PATH_OUTPUT, 'labels_transitions.csv')
        pd.DataFrame(trans).to_csv(path_csv)
        gc_regul = seg_gc.compute_pairwise_cost_from_transitions(trans, 10.)

        np.random.seed(0)
        features = np.tile(labels, (5, 1)).T.astype(float)
        features += np.random.random(features.shape) - 0.5

        gmm = seg_gc.estim_class_model_gmm(features, 4)
        proba = gmm.predict_proba(features)

        seg_gc.segment_graph_cut_general(slic, proba, gc_regul)
Example #9
0
 def test_segm_gmm_gc_ovary_2d(self):
     img = d_spl.load_sample_image(d_spl.IMAGE_DROSOPHILA_OVARY_2D)[:, :, 0]
     img = imresize(img, (512, 512))
     # img = np.rollaxis(np.tile(img[:, :, 0], (3, 1, 1)), 0, 3)
     params = {
         'nb_classes': 4,
         'pca_coef': 0.95,
         'sp_regul': 0.3,
         'sp_size': 10,
         'dict_features': seg_fts.FEATURES_SET_TEXTURE
     }
     run_segm2d_gmm_gc(img,
                       'test_segm_gmm_gc_ovary_2d',
                       list_regul=[0, 2, 10],
                       dict_params=params)
    def test_show_image_features_clr2d(self):
        img = d_spl.load_sample_image(d_spl.IMAGE_LENNA)
        img = transform.resize(img, (128, 128))
        slic = seg_spx.segment_slic_img2d(img, sp_size=10, rltv_compact=0.2)

        features, names = seg_fts.compute_selected_features_color2d(
            img, slic, seg_fts.FEATURES_SET_ALL)

        path_dir = os.path.join(PATH_OUTPUT, 'test_image_rgb2d_features')
        if not os.path.exists(path_dir):
            os.mkdir(path_dir)

        for i in range(features.shape[1]):
            fts = features[:, i]
            im_fts = fts[slic]
            plt.imsave(os.path.join(path_dir, names[i] + '.png'), im_fts)
Example #11
0
 def test_segm_gmm_gc_objects(self):
     img = d_spl.load_sample_image(d_spl.IMAGE_OBJECTS)
     img = imresize(img, (256, 256))
     logging.debug('dimension: {}'.format(img.shape))
     params = {
         'nb_classes': 4,
         'sp_size': 20,
         'sp_regul': 0.2,
         'dict_features': {
             'color': ['mean']
         }
     }
     run_segm2d_gmm_gc(img,
                       'test_segm_gmm_gc_objects',
                       list_regul=[0, 1, 5, 10],
                       dict_params=params)
Example #12
0
    def test_segm_gmm_gc_objects(self):
        img = d_spl.load_sample_image(d_spl.IMAGE_OBJECTS)
        img = imresize(img, (256, 256))
        logging.debug('dimension: {}'.format(img.shape))

        dict_imgs = dict()
        path_dir = os.path.join(PATH_OUTPUT, 'test_segm_gmm_gc_objects')
        if not os.path.isdir(path_dir):
            os.mkdir(path_dir)
        seg = pipelines.pipe_color2d_slic_features_gmm_graphcut(
            img,
            nb_classes=4,
            sp_size=20,
            sp_regul=0.2,
            dict_features={'color': ['mean']},
            gc_regul=1.,
            gc_edge_type='model',
            dict_debug_imgs=dict_imgs)

        show_segm_debugs_2d(dict_imgs, path_dir,
                            'fig_regul-%.2f_edge-%s_debug.png' % (1., 'model'))
        show_segm_results_2d(img, seg, path_dir,
                             'fig_regul-%.2f_edge-%s.png' % (1., 'model'))
 def setUp(self):
     self.seg2d = d_spl.sample_segment_vertical_2d()
     self.seg3d = d_spl.sample_segment_vertical_3d()
     self.img = d_spl.load_sample_image(d_spl.IMAGE_LENNA)