예제 #1
0
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")
예제 #2
0
    def _load(self):
        try:
            # Load the image with the user supplied filename
            image = ImageData.fromfile(self._load_file)

            # Update the plot data. NB we must extract _date 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()
        except:
            # If loading fails, simply do nothing
            pass
예제 #3
0
    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)
예제 #4
0
 def _filename_changed(self, new):
     image = ImageData.fromfile(new)
     self.plot_image(image._data)
예제 #5
0
 def _file_changed(self, new):
     image = ImageData.fromfile(new)
     self.update_image(image.data)