def get_preview(self, analysis: IAnalysisJobAnalysis): """ This should return the Widget that is shown in the Inspector when the analysis is selected """ w = QWidget() w.setLayout(QVBoxLayout(w)) w.layout().addWidget( QLabel( "Color CIE-Lab:".rjust(20) + str(analysis.get_adata()['color_lab']), w)) w.layout().addWidget( QLabel( "Color BGR:".rjust(20) + str(analysis.get_adata()['color_bgr']), w)) w.layout().addWidget( QLabel( "Saturation Luebbe:".rjust(20) + str(analysis.get_adata()['saturation_l']), w)) w.layout().addWidget( QLabel( "Saturation FilmCo:".rjust(20) + str(analysis.get_adata()['saturation_p']), w)) view = EGraphicsView(w) view.set_image( numpy_to_pixmap( np.array(([[analysis.get_adata()['color_bgr']] * 100] * 25)).astype(np.uint8))) w.layout().addWidget(view) return w
def get_visualization(self, analysis, result_path, data_path, project, main_window): """ This function should show the complete Visualization """ widget = EGraphicsView(None, auto_frame=True, has_context_menu=True) n = 20 colormap = get_colormap(n) data = analysis.get_adata() img = np.zeros(shape=data.shape + (3, ), dtype=np.float32) for i in range(n): img[data == i] = colormap[i][:3] img = (img * 255).astype(np.uint8) img = cv2.cvtColor(img, cv2.COLOR_RGBA2BGR) if isinstance(analysis.target_container, Screenshot): scr = analysis.target_container.get_img_movie_orig_size() scr = cv2.resize(scr, img.shape[:2][::-1], interpolation=cv2.INTER_CUBIC).astype(np.float32) img = ((scr * 0.7) + (img * 0.3)).astype(np.uint8) widget.set_image(numpy_to_pixmap(img)) return [ VisualizationTab(widget=widget, name="Semantic Segmentation Mask", use_filter=False, controls=None) ]
def __init__(self, parent, cache_file="data/hilbert.npz", naming_fields=None): EGraphicsView.__init__(self, parent, auto_frame=False) IVIANVisualization.__init__(self, naming_fields) self.naming_fields['plot_name'] = "color_histogram" self.has_context_menu = True # self.view = EGraphicsView(self, auto_frame=False) self.setLayout(QVBoxLayout(self)) # self.layout().addWidget(self.view) self.items = [] # self.plt = pg.PlotItem() # self.view.addItem(self.plt) self.qimage = None if not os.path.isfile(cache_file): self.table, self.colors = create_hilbert_transform(16) np.savez(cache_file, table=self.table, colors=self.colors) else: d = np.load(cache_file) self.table = (d['table'][0], d['table'][1], d['table'][2]) self.colors = d['colors'] self.raw_data = None self.plot_floor = True self.plot_zeros = False self.normalize = True self.draw_grid = False self.plot_log = True
def __init__(self, parent, naming_fields = None): QWidget.__init__(self, parent) IVIANVisualization.__init__(self, naming_fields) self.naming_fields['plot_name'] = "keyword_graph_plot" self.view = EGraphicsView(self) self.view.setScene(QGraphicsScene(self)) self.view.onScaleEvent.connect(self.on_scale) self.view.setBackgroundBrush(QColor(30, 30, 30)) self.setLayout(QHBoxLayout(self)) self.layout().addWidget(self.view) self.node_matrix = None self.node_labels = None self.context_objects = None self.text_size = 8 self.node_threshold = 10 self.edge_threshold = 10 self.selection_graph_depth = 2 self.nodes = [] self.edges = [] self.labels = [] self.node_weights = [] self.node_words_model = QStandardItemModel() self.current_labels = [] self.controls = None self.current_selection = None
def get_visualization(self, analysis, result_path, data_path, project, main_window): """ This function should show the complete Visualization """ w = QWidget() w.setLayout(QVBoxLayout(w)) w.layout().addWidget( QLabel( "Color CIE-Lab:".rjust(20) + str(analysis.get_adata()['color_lab']), w)) w.layout().addWidget( QLabel( "Color BGR:".rjust(20) + str(analysis.get_adata()['color_bgr']), w)) w.layout().addWidget( QLabel( "Saturation Luebbe:".rjust(20) + str(analysis.get_adata()['saturation_l']), w)) w.layout().addWidget( QLabel( "Saturation FilmCo:".rjust(20) + str(analysis.get_adata()['saturation_p']), w)) view = EGraphicsView(w) view.set_image( numpy_to_pixmap( np.array(([[analysis.get_adata()['color_bgr']] * 100] * 25)).astype(np.uint8))) w.layout().addWidget(view) return [ VisualizationTab(widget=w, name="Color-Features", use_filter=False, controls=None) ]
def get_preview(self, analysis: IAnalysisJobAnalysis): """ This should return the Widget that is shown in the Inspector when the analysis is selected """ widget = EGraphicsView(None, auto_frame=True) n = 20 colormap = get_colormap(n) data = analysis.get_adata() img = np.zeros(shape=data.shape + (3, ), dtype=np.float32) for i in range(n): img[data == i] = colormap[i][:3] img = (img * 255).astype(np.uint8) img = cv2.cvtColor(img, cv2.COLOR_RGBA2BGR) if isinstance(analysis.target_container, Screenshot): scr = analysis.target_container.get_img_movie_orig_size() scr = cv2.resize(scr, img.shape[:2][::-1], interpolation=cv2.INTER_CUBIC).astype(np.float32) img = ((scr * 0.7) + (img * 0.3)).astype(np.uint8) widget.set_image(numpy_to_pixmap(img)) return widget
def get_preview(self, analysis: IAnalysisJobAnalysis): """ This should return the Widget that is shown in the Inspector when the analysis is selected """ view = EGraphicsView(None) pixmap = numpy_to_pixmap(analysis.get_adata()) view.set_image(pixmap) return view
def get_visualization(self, analysis, result_path, data_path, project, main_window): """ This function should show the complete Visualization """ view = EGraphicsView(None) pixmap = numpy_to_pixmap(analysis.get_adata()) view.set_image(pixmap) return [VisualizationTab(widget=view, name="Z-Projection", use_filter=False, controls=None)]
def __init__(self, parent, naming_fields=None): EGraphicsView.__init__(self, parent) IVIANVisualization.__init__(self, naming_fields) self.naming_fields['plot_name'] = "palette_barcode_plot" self.times = None self.palette = None self.depth = 0 self.image = None self.show_grid = False self.sorting = "Cluster" self.setAttribute(Qt.WA_OpaquePaintEvent) self.resolution = 1
def __init__(self, parent, max=1.0, allow_hover=True, naming_fields=None): EGraphicsView.__init__(self, parent, auto_frame=False) IVIANVisualization.__init__(self, naming_fields) self.naming_fields['plot_name'] = "matrix_plot" self.dot_size = 1.0 self.total_width = 1000 self.max = max self.items = [] self.setScene(QGraphicsScene(self)) self.use_gray = True self.hover_frame = None self.allow_hover = allow_hover self.matrix = None
def get_visualization(self, analysis, result_path, data_path, project, main_window): """ This function should show the complete Visualization """ widget = EGraphicsView(None, auto_frame=True) widget.set_image( numpy_to_pixmap( self.barcode_to_image(analysis.get_adata()['barcode']))) return [ VisualizationTab(widget=widget, name="Barcode", use_filter=False, controls=None) ]
def get_visualization(self, analysis, result_path, data_path, project, main_window): """ This function should show the complete Visualization """ return [ VisualizationTab(widget=EGraphicsView(None), name="Barcode", use_filter=False, controls=None) ]
def get_preview(self, analysis: IAnalysisJobAnalysis): """ This should return the Widget that is shown in the Inspector when the analysis is selected """ view = PaletteView(None) view.depth = 10 image = QImage(QSize(1024, 256), QImage.Format_RGBA8888) view.palette_layer = analysis.get_adata()['tree'] view.draw_palette(image) pixmap = QPixmap().fromImage(image) view = EGraphicsView(None) view.set_image(pixmap) return view
class VocabularyGraph(QWidget, IVIANVisualization): onSelectionChanged = pyqtSignal(object) def __init__(self, parent, naming_fields = None): QWidget.__init__(self, parent) IVIANVisualization.__init__(self, naming_fields) self.naming_fields['plot_name'] = "keyword_graph_plot" self.view = EGraphicsView(self) self.view.setScene(QGraphicsScene(self)) self.view.onScaleEvent.connect(self.on_scale) self.view.setBackgroundBrush(QColor(30, 30, 30)) self.setLayout(QHBoxLayout(self)) self.layout().addWidget(self.view) self.node_matrix = None self.node_labels = None self.context_objects = None self.text_size = 8 self.node_threshold = 10 self.edge_threshold = 10 self.selection_graph_depth = 2 self.nodes = [] self.edges = [] self.labels = [] self.node_weights = [] self.node_words_model = QStandardItemModel() self.current_labels = [] self.controls = None self.current_selection = None def on_selection(self, obj): for n in self.nodes: n.set_selected(False) for n in self.edges: n.set_selected(False) self.current_selection = obj if obj is not None: self.view.setRenderHint(QPainter.Antialiasing, True) obj.set_selected(True) self.onSelectionChanged.emit(obj) h_nodes = [] h_edges = [] obj.get_graph(h_edges, h_nodes, depth=self.selection_graph_depth) self.highlight(h_nodes, h_edges) else: self.view.setRenderHint(QPainter.Antialiasing, False) def highlight(self, nodes, edges): for n in self.nodes: if n not in nodes: n.set_highlighted(False) else: n.set_highlighted(True) for e in self.edges: if e not in edges: e.set_highlighted(False) else: e.set_highlighted(True) def on_filter(self, indices): matrix = self.node_matrix[:, indices] matrix = matrix[indices, :] self.create_graph(matrix, np.array(self.node_labels)[indices].tolist()) def clear_view(self): for n in self.nodes: self.view.scene().removeItem(n) for e in self.edges: self.view.scene().removeItem(e) for lbl in self.labels: self.view.scene().removeItem(lbl) self.nodes = [] self.edges = [] self.labels = [] def create_graph(self, node_matrix, labels = None, context_objects = None, dot_size = 20, edge_threshold = 1): self.clear_view() self.node_matrix = node_matrix self.node_labels = labels self.context_objects = context_objects if labels is None: labels = [""] * node_matrix.shape[0] if context_objects is None: context_objects = [None] * node_matrix.shape[0] g = nx.Graph() m = node_matrix edges = [] edges_n_occurences = [] m_max = np.amax(m) node_sums = np.sum(m, axis=1).astype(np.float32) node_sums = np.divide(node_sums, np.amax(node_sums)) node_max = np.amax(node_sums) node_sums = np.multiply(node_sums, dot_size) # Filter the Input by the Node Threshold print("Filtering Nodes") node_names = labels node_infos = [] valid_node_indices = [] valid_node_mapping = [] for x in range(m.shape[0]): if np.sum(m[x]) >= self.node_threshold: valid_node_indices.append(x) valid_node_mapping.append(len(node_infos)) node_info = [len(node_infos) - 1, labels[x], context_objects[x], [], x, node_sums[x]] node_infos.append(node_info) for info in node_infos: mx = info[4] # the index of this node in the node-matrix ndx = info[0] # the index of this node in the final filtered list for my in range(m.shape[1]): if m[mx, my] >= self.edge_threshold: if my in valid_node_indices: ny = valid_node_mapping[valid_node_indices.index(my)] info[3].append([ndx, ny, m[mx, my]]) print("Creating Graph Layout") for x in range(len(node_infos)): g.add_node(x) for info in node_infos: for eg in info[3]: edges_n_occurences.append([eg[2]]) g.add_edge(eg[0], eg[1], attr_dict=dict(weight = eg[2] / m_max)) edges.append([eg[0], eg[1]]) print("N-Edges:", len(edges), "N-Nodes:", len(g.nodes)) lt = nx.spring_layout(g) scale = 100000 pen = QPen(QColor(201, 29, 32, 250)) pen.setWidth(5) pen.setColor(COL_EDGE_DES) dot_center = dot_size / 2 print("Drawing Edges") for i, e in enumerate(edges): if i % 100 == 0: a = lt[e[0]] b = lt[e[1]] # s1 = node_sums[e[0]] # s2 = node_sums[e[1]] s1 = node_infos[e[0]][5] s2 = node_infos[e[1]][5] item = GraphEdge(None, self, pen, e[0], e[1], n_occurence=edges_n_occurences[i]) self.edges.append(item) self.view.scene().addItem(item) item.setLine(a[0] * scale + (dot_center * s1), a[1] * scale + (dot_center * s1), b[0] * scale + (dot_center * s2), b[1] * scale + (dot_center * s2)) pen = QPen(COL_NODE_DES) font = QFont("Consolas", self.text_size) brush = QBrush(BRUSH_NODE_DES, Qt.SolidPattern) counter = 0 print("Drawing Nodes") for key, itm in lt.items(): # s = node_sums[counter] if counter >= len(node_infos): continue s = node_infos[counter][5] n_itm = GraphNode(None, self, pen, brush) self.nodes.append(n_itm) self.view.scene().addItem(n_itm) n_itm.setRect(itm[0] * scale, itm[1] * scale, dot_size * s, dot_size * s) counter += 1 counter = 0 self.current_labels = [] if labels is not None: for key, itm in lt.items(): if counter >= len(node_infos): continue s = node_infos[counter][5] name = node_infos[counter][1] #node_names[counter] self.current_labels.append(name) lbl = self.view.scene().addText(name,font) lbl.setPos(itm[0] * scale + (dot_size * s / 2) - lbl.textWidth(), itm[1] * scale + (dot_size * s / 2)) lbl.setDefaultTextColor(QColor(200,200,200)) lbl.setFlag(QGraphicsItem.ItemIgnoresTransformations) self.labels.append(lbl) self.node_weights.append(s) self.nodes[counter].label = lbl counter += 1 ok = 0 errors = 0 print("Connecting Nodes and Edges") for e in self.edges: p_center = (e.line().p1() + e.line().p2()) / 2 lbl = self.view.scene().addText(str(e.n_occurence), font) lbl.setPos(p_center) lbl.setDefaultTextColor(QColor(200, 200, 200)) self.labels.append(lbl) e.label = lbl try: n1 = self.nodes[e.n1] n2 = self.nodes[e.n2] n1.add_edge(e) n2.add_edge(e) e.n1 = n1 e.n2 = n2 ok += 1 except: errors += 1 continue self.node_words_model.clear() if self.controls is not None: for lbl in self.current_labels: self.node_words_model.appendRow(QStandardItem(lbl)) completer = QCompleter() completer.setModel(self.node_words_model) completer.setCaseSensitivity(Qt.CaseInsensitive) completer.setFilterMode(Qt.MatchContains) completer.setCompletionMode(QCompleter.PopupCompletion) self.controls.node_query_line.setCompleter(completer) # print("Errors:", errors, " OK:", ok) def get_node_by_context(self, context_obj): for n in self.nodes: if n.context_obj is context_obj: return n def mousePressEvent(self, a0: QMouseEvent): if a0.button() == Qt.RightButton: self.on_selection(None) else: a0.ignore() def get_controls(self): self.controls = GraphControls(self) return self.controls def set_edge_threshold(self, value): self.edge_threshold = value def set_node_threshold(self, value): self.node_threshold = value def set_selection_graph_depth(self, value): self.selection_graph_depth = value def on_query_by_label(self, label): for n in self.nodes: if n.label.toPlainText() == label: self.on_selection(n) break @pyqtSlot(float) def on_scale(self, scale): pass # for lbl in self.labels: # lbl.show() # # for i in range(len(self.node_weights)): # lbla = self.labels[i] # done = False # # if lbla.isVisible() == False: # continue # # for j in range(len(self.node_weights)): # lblb = self.labels[j] # if lblb.isVisible() and lbla.collidesWithItem(lblb, Qt.IntersectsItemBoundingRect): # if self.node_weights[i] < self.node_weights[j]: # lbla.hide() # break # else: # lblb.hide() def get_param_widget(self): return self.get_controls()
def get_visualization(self, analysis, result_path, data_path, project, main_window): view = EGraphicsView(None, False, main_window) view.set_image(numpy_to_pixmap(analysis.get_adata()["mosaic"])) return [VisualizationTab("Mosaic", widget=view, use_filter=False, controls=None)]
def get_preview(self, analysis: IAnalysisJobAnalysis): """ This should return the Widget that is shown in the Inspector when the analysis is selected """ return EGraphicsView(None)
def get_preview(self, analysis): gw = EGraphicsView(None) gw.set_image(numpy_to_pixmap(analysis.get_adata()["mosaic"])) return gw