class TestSuperpixels(unittest.TestCase): img = d_spl.load_sample_image(d_spl.IMAGE_LENNA) seg2d = d_spl.sample_segment_vertical_2d() seg3d = d_spl.sample_segment_vertical_3d() def test_segm_connect(self): logging.debug(self.seg2d) vertices, edges = seg_spx.make_graph_segm_connect_grid2d_conn4(self.seg2d) logging.debug('vertices: {} -> edges: {}'.format(vertices, edges)) logging.debug(self.seg3d) vertices, edges = seg_spx.make_graph_segm_connect_grid3d_conn6(self.seg3d) logging.debug('vertices: {} -> edges: {}'.format(vertices, edges)) def test_general(self): slic = seg_spx.segment_slic_img2d(self.img, sp_size=15, rltv_compact=0.2) logging.debug(np.max(slic)) vertices, edges = seg_spx.make_graph_segm_connect_grid2d_conn4(slic) logging.debug(repr(vertices)) logging.debug(len(edges)) logging.debug(repr(edges)) fig, axarr = plt.subplots(ncols=2) axarr[0].imshow(self.img) axarr[1].imshow(slic, cmap=plt.cm.jet) fig.savefig(os.path.join(PATH_OUTPUT, 'temp_superpixels.png')) if logging.getLogger().getEffectiveLevel() == logging.DEBUG: plt.show() plt.close(fig)
class TestLabels(unittest.TestCase): segm = sample_segment_vertical_2d() def test_label_contours(self): seg = self.segm logging.debug('matrix seg_pipe \n%r', seg) labs = list(np.unique(seg)) path_dir = os.path.join(PATH_OUTPUT, 'temp_labels') if not os.path.exists(path_dir): os.mkdir(path_dir) for lb in labs: fig, axarr = plt.subplots(nrows=2) cnt = 1 - binary_image_from_coords(contour_coords(seg, lb), seg.shape) axarr[0].imshow(cnt, interpolation='nearest', cmap=plt.cm.Greys) dist = compute_distance_map(seg, lb) im = axarr[1].imshow(dist, cmap=plt.cm.jet) plt.colorbar(im, ax=axarr[1]) fig.tight_layout() fig.savefig(os.path.join(path_dir, 'contours_%i.png' % lb)) if logging.getLogger().getEffectiveLevel() == logging.DEBUG: plt.show() plt.close(fig)