def create_window(): gridparam = make.gridparam(background="black", minor_enabled=(False, False), major_style=(".", "gray", 1)) win = ImageDialog(edit=False, toolbar=True, wintitle="Region of interest (ROI) test", options=dict(gridparam=gridparam)) for toolklass in (RectangleTool, EllipseTool, FreeFormTool, PlaceAxesTool): win.add_tool(toolklass) return win
def create_plot(self, options, row=0, column=0, rowspan=1, columnspan=1): ImageDialog.create_plot(self, options, row, column, rowspan, columnspan) ra_panel = ObliqueCrossSection(self) splitter = self.plot_widget.xcsw_splitter splitter.addWidget(ra_panel) splitter.setStretchFactor(splitter.count() - 1, 1) splitter.setSizes(list(splitter.sizes()) + [2]) self.add_panel(ra_panel)
def create_window(): win = ImageDialog(edit=False, toolbar=True, wintitle="Cross sections test", options=dict(show_xsection=True, show_ysection=True, show_itemlist=True)) win.resize(800, 600) return win
def create_window(): gridparam = make.gridparam(background="black", minor_enabled=(False, False), major_style=(".", "gray", 1)) win = ImageDialog(edit=False, toolbar=True, wintitle="All image and plot tools test", options=dict(gridparam=gridparam)) for toolklass in (RectangleTool, EllipseTool, SegmentTool, MultiLineTool, FreeFormTool): win.add_tool(toolklass, handle_final_shape_cb=customize_shape) return win
def create_plot(self, options): self.filter_gbox = DataSetEditGroupBox(_("Filter parameters"), FilterParam) self.filter_gbox.setEnabled(False) self.filter_gbox.SIG_APPLY_BUTTON_CLICKED.connect(self.apply_filter) self.plot_layout.addWidget(self.filter_gbox, 0, 0) self.param_gbox = DataSetShowGroupBox(_("Image parameters"), ImageParam) self.plot_layout.addWidget(self.param_gbox, 0, 1) options = dict(title=_("Image title"), zlabel=_("z-axis scale label")) ImageDialog.create_plot(self, options, 1, 0, 1, 0)
def create_window(): win = ImageDialog(edit=False, toolbar=True, wintitle="All image and plot tools test") for toolklass in (LabelTool, HRangeTool, VCursorTool, HCursorTool, XCursorTool, SegmentTool, RectangleTool, ObliqueRectangleTool, CircleTool, EllipseTool, MultiLineTool, FreeFormTool, PlaceAxesTool, AnnotatedRectangleTool, AnnotatedObliqueRectangleTool, AnnotatedCircleTool, AnnotatedEllipseTool, AnnotatedSegmentTool, AnnotatedPointTool): win.add_tool(toolklass) return win
def __init__(self, parent, wintitle=None, options=None, resize_to=None): if wintitle is None: wintitle = _("Rotate & Crop") ImageDialog.__init__(self, wintitle=wintitle, edit=True, toolbar=False, options=options, parent=parent) if resize_to is not None: width, height = resize_to self.resize(width, height) self.accepted.connect(self.accept_changes) self.rejected.connect(self.reject_changes)
def imshow(data, title=None, hold=False): dlg = ImageDialog(wintitle=title) dlg.get_plot().add_item(make.image(data)) if hold: dlg.show() else: dlg.exec_()
def xyimagebug(offset): from plotpy.plot import ImageDialog from plotpy.builder import make import numpy import plotpy app = plotpy.qapplication() data = numpy.random.rand(100, 100) x = numpy.arange(100)+offset y = numpy.arange(100) image = make.xyimage(x, y, data=data) win = ImageDialog() plot = win.get_plot() plot.add_item(image) plot.select_item(image) #this helps in seeing where the image should be win.exec_()
def get_segment(item): """Show image and return selected segment coordinates""" win = ImageDialog(_("Select a segment then press OK to accept"), edit=True) default = win.add_tool(SelectTool) win.set_default_tool(default) segtool = win.add_tool(AnnotatedSegmentTool, title="Test", switch_to_default_tool=True) segtool.activate() plot = win.get_plot() plot.add_item(item) plot.set_active_item(item) win.show() if win.exec_(): shape = segtool.get_last_final_shape() return shape.get_rect()
def mandel(): win = ImageDialog(edit=True, toolbar=True, wintitle="Mandelbrot", options=dict(yreverse=False)) mandel = MandelItem(-1.5, .5, -1., 1.) win.add_tool(FullScale, mandel) plot = win.get_plot() plot.set_aspect_ratio(lock=False) plot.add_item(mandel) plot.set_full_scale(mandel) win.show() win.exec_()
def create_dialog(self): self.dlg = dlg = ImageDialog(\ edit=False, toolbar=True, wintitle="Load/save test", options=dict(title="Title", xlabel="xlabel", ylabel="ylabel")) dlg.add_separator_tool() dlg.add_tool(LoadItemsTool) dlg.add_tool(SaveItemsTool) dlg.add_tool(ImageMaskTool)
def imshow(items, title=""): gridparam = make.gridparam(background="black", minor_enabled=(False, False), major_style=(".", "gray", 1)) win = ImageDialog(edit=False, toolbar=True, wintitle=title, options=dict(gridparam=gridparam)) nc = int(np.sqrt(len(items)) + 1.0) maxy = 0 y = 0 x = 0 w = None plot = win.get_plot() print("-" * 80) for i, item in enumerate(items): h = item.boundingRect().height() if i % nc == 0: x = 0 y += maxy maxy = h else: x += w maxy = max(maxy, h) w = item.boundingRect().width() item.set_transform(x, y, 0.0) print("Adding item #%d..." % i, end=' ') plot.add_item(item) print("Done") win.show() win.exec_()
def test(): win = ImageDialog(edit=True, toolbar=True, wintitle="Sample multi-polygon item") plot = win.get_plot() plot.set_aspect_ratio(lock=True) plot.set_antialiasing(False) plot.set_axis_direction('left', False) plot.set_axis_title("bottom", "Lon") plot.set_axis_title("left", "Lat") points = [] offsets = zeros((NCIRC, 2), int32) colors = zeros((NCIRC, 2), uint32) npts = 0 for k in range(NCIRC): pts = create_circle() offsets[k, 0] = k offsets[k, 1] = npts npts += pts.shape[0] points.append(pts) colors[k, 0] = COLORS[k % len(COLORS)][0] colors[k, 1] = COLORS[(3 * k) % len(COLORS)][1] points = concatenate(points) print(NCIRC, "Polygons") print(points.shape[0], "Points") crv = PolygonMapItem() crv.set_data(points, offsets, colors) plot.add_item(crv, z=0) win.show() win.exec_()
def imshow(filename): win = ImageDialog(edit=False, toolbar=True, wintitle="RGB image item test") item = make.rgbimage(filename=filename, xdata=[-1, 1], ydata=[-1, 1]) plot = win.get_plot() plot.add_item(item) win.show() win.exec_()
def imshow( items ): win = ImageDialog(edit=False, toolbar=True, options={"yreverse": False}, wintitle="Pcolor test") plot = win.get_plot() for item in items: plot.add_item(item) win.show() win.exec_()
def imshow(data): win = ImageDialog(edit=False, toolbar=True, wintitle="ImageDialog test", options=dict(xlabel='Concentration', xunit='ppm')) item = make.image(data) plot = win.get_plot() plot.add_item(item) win.show() win.exec_()
def test(): win = ImageDialog(edit=True, toolbar=True, wintitle="Sample multi-polygon item") plot = win.get_plot() plot.set_aspect_ratio(lock=True) plot.set_antialiasing(False) plot.set_axis_direction('left', False) plot.set_axis_title("bottom", "Lon") plot.set_axis_title("left", "Lat") points = [] offsets = zeros( (NCIRC, 2), int32) colors = zeros( (NCIRC, 2), uint32) npts = 0 for k in range(NCIRC): pts = create_circle() offsets[k, 0] = k offsets[k, 1] = npts npts += pts.shape[0] points.append(pts) colors[k, 0] = COLORS[k%len(COLORS)][0] colors[k, 1] = COLORS[(3*k)%len(COLORS)][1] points = concatenate(points) print(NCIRC, "Polygons") print(points.shape[0], "Points") crv = PolygonMapItem() crv.set_data(points, offsets, colors) plot.add_item(crv, z=0) win.show() win.exec_()
def imshow( data ): win = ImageDialog(edit=False, toolbar=True, wintitle="ImageDialog test", options=dict(xlabel='Concentration', xunit='ppm')) item = make.image(data) plot = win.get_plot() plot.add_item(item) win.show() win.exec_()
def hist2d_func(X, Y, Z): win = ImageDialog(edit=True, toolbar=True, wintitle="2-D Histogram X0=(0,1), X1=(-1,-1)") hist2d = make.histogram2D(X, Y, 200, 200, Z=Z, computation=2) curve = make.curve(X[::50], Y[::50], linestyle='', marker='+', title=_("Markers")) plot = win.get_plot() plot.set_aspect_ratio(lock=False) plot.set_antialiasing(False) plot.add_item(hist2d) plot.add_item(curve) plot.set_item_visible(curve, False) win.get_itemlist_panel().show() win.show() win.exec_()
def imshow(x, y, data): win = ImageDialog(edit=False, toolbar=True, wintitle="Image with custom X/Y axes scales", options=dict(xlabel="x (a.u.)", ylabel="y (a.u.)", yreverse=False)) item = make.xyimage(x, y, data) plot = win.get_plot() plot.add_item(item) win.show() win.exec_()
def imshow( x, y, data ): win = ImageDialog(edit=False, toolbar=True, wintitle="Image with custom X/Y axes scales", options=dict(xlabel="x (a.u.)", ylabel="y (a.u.)", yreverse=False)) item = make.xyimage(x, y, data) plot = win.get_plot() plot.add_item(item) win.show() win.exec_()
def test(): filename = osp.join(osp.dirname(__file__), "mr-brain.dcm") image = make.image(filename=filename, title="DICOM img", colormap='gray') win = ImageDialog(edit=False, toolbar=True, wintitle="DICOM I/O test", options=dict(show_contrast=True)) plot = win.get_plot() plot.add_item(image) plot.select_item(image) contrast = win.get_contrast_panel() contrast.histogram.eliminate_outliers(54.) win.resize(600, 700) return win
def test(): """Test""" # -- Create QApplication import plotpy _app = plotpy.qapplication() # -- filename = osp.join(osp.dirname(__file__), "brain.png") image = make.image(filename=filename, title="Original", colormap='gray') win = ImageDialog(edit=False, toolbar=True, wintitle="Contrast test", options=dict(show_contrast=True)) plot = win.get_plot() plot.add_item(image) win.resize(600, 600) win.show() try: plot.save_widget('contrast.png') except IOError: # Skipping this part of the test # because user has no write permission on current directory pass win.exec_()
def imshow(x, y, data, filter_area, yreverse=True): win = ImageDialog(edit=False, toolbar=True, wintitle="Image filter demo", options=dict(xlabel="x (cm)", ylabel="y (cm)", yreverse=yreverse)) image = make.xyimage(x, y, data) plot = win.get_plot() plot.add_item(image) xmin, xmax, ymin, ymax = filter_area flt = make.imagefilter(xmin, xmax, ymin, ymax, image, filter=lambda x, y, data: gaussian_filter(data, 5)) plot.add_item(flt, z=1) plot.replot() win.show() win.exec_()
SHOW = True # Show test in GUI-based test launcher import os, os.path as osp, pickle from plotpy.plot import ImageDialog from plotpy.tools import ImageMaskTool from plotpy.builder import make SHOW = True # Show test in GUI-based test launcher FNAME = "image_masked.pickle" if __name__ == "__main__": import plotpy _app = plotpy.qapplication() win = ImageDialog(toolbar=True, wintitle="Masked image item test") win.add_tool(ImageMaskTool) if os.access(FNAME, os.R_OK): print("Restoring mask...", end=' ') iofile = open(FNAME, "rb") image = pickle.load(iofile) iofile.close() print("OK") else: fname = osp.join(osp.abspath(osp.dirname(__file__)), "brain.png") image = make.maskedimage(filename=fname, colormap='gray', show_mask=True, xdata=[0, 20], ydata=[0, 25]) win.get_plot().add_item(image)
SHOW = True # Show test in GUI-based test launcher import os, os.path as osp, pickle from plotpy.plot import ImageDialog from plotpy.tools import ImageMaskTool from plotpy.builder import make SHOW = True # Show test in GUI-based test launcher FNAME = "image_masked.pickle" if __name__ == "__main__": import plotpy _app = plotpy.qapplication() win = ImageDialog(toolbar=True, wintitle="Masked image item test") win.add_tool(ImageMaskTool) if os.access(FNAME, os.R_OK): print("Restoring mask...", end=' ') iofile = open(FNAME, "rb") image = pickle.load(iofile) iofile.close() print("OK") else: fname = osp.join(osp.abspath(osp.dirname(__file__)), "brain.png") image = make.maskedimage(filename=fname, colormap='gray', show_mask=True, xdata=[0, 20], ydata=[0, 25]) win.get_plot().add_item(image) win.show() win.exec_() iofile = open(FNAME, "wb")
def register_image_tools(self): ImageDialog.register_image_tools(self) for tool in (ObliqueCrossSectionTool, OCSPanelTool, ImageMaskTool): self.add_tool(tool)