def do_imread(*data, **kwargs): """ Returns image file as array. """ # Check to see if the data given is either a file path or a file object if isinstance(data[0], basestring) or isinstance(data[0], file): return ImageData.fromfile(data[0]) else: raise ValueError("do_imread takes a string filename")
def _load(self): try: image = ImageData.fromfile(self._load_file) self.pd.set_data('imagedata', image._data) self.plot.title = "YO DOGG: %s" % os.path.basename(self._load_file) self.plot.request_redraw() except Exception, exc: print "YO DOGG: %s" % exc
def do_imread(*data, **kwargs): """ Returns image file as array. """ # Check to see if the data given is either a file path or a file object if isinstance(data[0], six.string_types) or isinstance(data[0], io.IOBase): return ImageData.fromfile(data[0]) else: raise ValueError("do_imread takes a string filename")
def _load(self): # Load the image with the user supplied filename image = ImageData.fromfile(self._load_file) # Update the plot data. NB we must extract _data from the image # for the time being, until ImageData is made more friendly self.pd.set_data("imagedata", image._data) # Set the title and redraw self.plot.title = os.path.basename(self._load_file) self.plot.request_redraw()
def set_pict(self): pd = self.plot_data if not pd: return try: imgd = ImageData.fromfile(self.pict)._data[::-1] except: imgd = ImageData() imgd.set_data(255*ones((2,2,3),dtype='uint8')) imgd = imgd._data pd.set_data("image",imgd)
def set_pict(self): pd = self.plot_data if not pd: return try: imgd = ImageData.fromfile(self.pict)._data[::-1] except: imgd = ImageData() imgd.set_data(255 * ones((2, 2, 3), dtype='uint8')) imgd = imgd._data pd.set_data("image", imgd)
def image_from_renderer(renderer, orientation): data = renderer.value # Set bounding box size and origin to align rendered image with array renderer.bounds = (data.get_width() + 1, data.get_height() + 1) if orientation == 'v': renderer.bounds = renderer.bounds[::-1] renderer.position = 0, 0 with temp_image_file() as filename: save_renderer_result(renderer, filename) rendered_image = ImageData.fromfile(filename).data[TRIM_RENDERED] return rendered_image
def empty_image(): """ Returns empty image plot """ from chaco.api import ImageData, GridDataSource, GridMapper, DataRange2D, ImagePlot image_source = ImageData.fromfile(config.IMG_NOCOMPLEX_PATH) w, h = image_source.get_width(), image_source.get_height() index = GridDataSource(np.arange(w), np.arange(h)) index_mapper = GridMapper( range=DataRange2D(low=(0, 0), high=(w - 1, h - 1))) image_plot = ImagePlot(index=index, value=image_source, index_mapper=index_mapper, origin='top left') return image_plot
def __init__(self, **kw): super(WorldMapPlot, self).__init__(**kw) self._download_map_image() image = ImageData.fromfile(self.image_path) # For now, the locations are hardcoded, though this can be changed # eassily to take command line args, read from a file, or by other # means austin_loc = (30.16, -97.44) locations_x = numpy.array([austin_loc[1]]) locations_y = numpy.array([austin_loc[0]]) # transform each of the locations to the image data space, including # moving the origin from bottom left to top left locations_x = (locations_x + 180) * image.data.shape[1] / 360 locations_y = (locations_y * -1 + 90) * image.data.shape[0] / 180 # Create the plott data, adding the image and the locations plot_data = ArrayPlotData() plot_data.set_data("imagedata", image._data) plot_data.set_data("locations_x", locations_x) plot_data.set_data("locations_y", locations_y) # Create the plot with the origin as top left, which matches # how the image data is aligned self.plot = Plot(plot_data, default_origin="top left") self.plot.img_plot('imagedata') # Plot the locations as a scatter plot to be overlayed on top # of the map loc_plot = self.plot.plot(('locations_x', 'locations_y'), type='scatter', size=3, color='yellow', marker='dot')[0] loc_plot.x_mapper.range.high = image.data.shape[1] loc_plot.x_mapper.range.low = 0 loc_plot.y_mapper.range.high = image.data.shape[0] loc_plot.y_mapper.range.low = -0 # set up any tools, in this case just the zoom tool zoom = ZoomTool(component=self.plot, tool_mode="box", always_on=False) self.plot.overlays.append(zoom)
def empty_image(): """ Returns empty image plot """ from chaco.api import ImageData, GridDataSource, GridMapper, DataRange2D, ImagePlot image_source = ImageData.fromfile(config.IMG_NOCOMPLEX_PATH) w, h = image_source.get_width(), image_source.get_height() index = GridDataSource(np.arange(w), np.arange(h)) index_mapper = GridMapper(range=DataRange2D(low=(0, 0), high=(w-1, h-1))) image_plot = ImagePlot( index=index, value=image_source, index_mapper=index_mapper, origin='top left' ) return image_plot
def __init__(self, **kw): super(WorldMapPlot, self).__init__(**kw) self._download_map_image() image = ImageData.fromfile(self.image_path) # For now, the locations are hardcoded, though this can be changed # eassily to take command line args, read from a file, or by other # means austin_loc = (30.16, -97.44) locations_x = numpy.array([austin_loc[1]]) locations_y = numpy.array([austin_loc[0]]) # transform each of the locations to the image data space, including # moving the origin from bottom left to top left locations_x = (locations_x + 180) * image.data.shape[1]/360 locations_y = (locations_y*-1 + 90) * image.data.shape[0]/180 # Create the plott data, adding the image and the locations plot_data = ArrayPlotData() plot_data.set_data("imagedata", image._data) plot_data.set_data("locations_x", locations_x) plot_data.set_data("locations_y", locations_y) # Create the plot with the origin as top left, which matches # how the image data is aligned self.plot = Plot(plot_data, default_origin="top left") self.plot.img_plot('imagedata') # Plot the locations as a scatter plot to be overlayed on top # of the map loc_plot = self.plot.plot(('locations_x', 'locations_y'), type='scatter', size=3, color='yellow', marker='dot')[0] loc_plot.x_mapper.range.high = image.data.shape[1] loc_plot.x_mapper.range.low = 0 loc_plot.y_mapper.range.high = image.data.shape[0] loc_plot.y_mapper.range.low = -0 # set up any tools, in this case just the zoom tool zoom = ZoomTool(component=self.plot, tool_mode="box", always_on=False) self.plot.overlays.append(zoom)
def test_fromfile_png_rgba(self): # basic smoke test - assume that kiva.image does the right thing path = os.path.join(data_dir, 'PngSuite', 'basi6a08.png') data_source = ImageData.fromfile(path) self.assertEqual(data_source.value_depth, 4)
def _filename_changed(self, new): image = ImageData.fromfile(new) self.plot_image(image._data)
def __init__(self): self.plotData = ArrayPlotData() self.backImg = Plot(self.plotData, default_origin="top left") self.backImg.x_axis = None self.backImg.y_axis = None self.backImg.padding = (3, 3, 3, 3) image = ImageData.fromfile("world.png") self.plotData.set_data("imagedata", image._data) self.backImg.img_plot("imagedata") self.image = True self.imageVisible = True # self._refresh_fired() # TMP x = [] y = [] c = [] feed = parse( "http://geofon.gfz-potsdam.de/eqinfo/list.php?datemin=&datemax=&latmin=&latmax=&lonmin=&lonmax=&magmin=5.&nmax=100&fmt=rss" ) self.entries = feed["entries"] clen = len(self.entries) for i, entry in enumerate(self.entries): edate, etime, elat, elon, edep, eunit, estatus = entry["summary"].split() x.append(((float(elon) + 180) / 360) * 5400.0) y.append(2700 - ((float(elat) + 90) / 180) * 2700.0) c.append(clen - i) self.plotData.set_data("X", x) self.plotData.set_data("Y", y) self.plotData.set_data("C", c) self.backImg.plot( ("X", "Y", "C"), type="cmap_scatter", color_mapper=jet, marker="circle", index_sort="ascending", color="orange", marker_size=10, bgcolor="white", name="earthquakes", ) my_plot = self.backImg.plots["earthquakes"][0] my_plot.tools.append(ScatterInspector(my_plot, selection_mode="toggle", persistent_hover=False)) my_plot.overlays.append( ScatterInspectorOverlay( my_plot, hover_color="transparent", hover_marker_size=10, hover_outline_color="purple", hover_line_width=2, selection_marker_size=8, selection_color="lawngreen", ) ) zoom = ZoomTool(component=my_plot, tool_mode="box", always_on=False) my_plot.overlays.append(zoom) pan = PanTool(my_plot) my_plot.tools.append(pan) self.index_datasource = my_plot.index self.index_datasource.on_trait_change(self._metadata_handler, "metadata_changed") self.map = Basemap()