def __init__(self, datasource, default_pen=DEFAULT_PEN, direct=False): """ datasource: A single-channel label image. default_pen: The initial pen style for each edge. """ super( SegmentationEdgesLayer, self ).__init__( [datasource], direct=direct ) # Changes to this colortable will be detected automatically in the QGraphicsItem self._pen_table = SignalingDefaultDict(parent=self, default_factory=lambda:default_pen )
app = QApplication([]) import h5py with h5py.File('/magnetic/data/multicut-testdata/2d/256/Superpixels.h5', 'r') as superpixels_f: labels_img = superpixels_f['data'][:] labels_img = labels_img[..., 0] # drop channel default_pen = QPen() default_pen.setCosmetic(True) default_pen.setCapStyle(Qt.RoundCap) default_pen.setColor(Qt.blue) default_pen.setWidth(3) # Changes to this pen table will be detected automatically in the QGraphicsItem pen_table = SignalingDefaultDict(parent=None, default_factory=lambda: default_pen) start = time.time() path_items = generate_path_items_for_labels(pen_table, labels_img, None) print "generate took {}".format(time.time() - start) # 52 ms edges_item = SegmentationEdgesItem(path_items, pen_table) def assign_random_color(id_pair, buttons): print "handling click: {}".format(id_pair) pen = pen_table[id_pair] if pen: pen = QPen(pen) else: pen = QPen() random_color = QColor(*list(np.random.randint(0, 255, (3, ))))