Exemplo n.º 1
0
    def display(self, ind=0, hist=False):
        nb_images = 2
        name_files = self.serie_arrays.get_name_files()[ind:ind + nb_images]

        results_series = SerieOfArraysFromFiles(self.params.saving.path)
        results = {
            name: results_series.get_array_from_name(name)
            for name in name_files[ind:ind + nb_images]
        }

        return super().display(ind, hist, results)
Exemplo n.º 2
0
    def __init__(self, params=None):
        """Set path for results and loads images as SerieOfArraysFromFiles."""
        if params is None:
            params = self.__class__.create_default_params()

        self.params = params.preproc

        path = params.preproc.series.path
        if not os.path.exists(path):
            path = params.preproc.series.path = os.path.expandvars(path)

        self.serie_arrays = SerieOfArraysFromFiles(path)
        self.tools = PreprocTools(params)
        self.results = {}
Exemplo n.º 3
0
class PreprocBase(object):
    """Preprocess series of images with various tools. """

    @classmethod
    def create_default_params(cls):
        """Class method returning the default parameters."""
        params = ParamContainer(tag='params')
        params._set_child('preproc')
        params.preproc._set_child('series', attribs={'path': ''})

        PreprocTools._complete_class_with_tools(params)

        return params

    def __init__(self, params=None):
        """Set path for results and loads images as SerieOfArraysFromFiles."""
        if params is None:
            params = self.__class__.create_default_params()

        self.params = params.preproc

        path = params.preproc.series.path
        if not os.path.exists(path):
            path = params.preproc.series.path = os.path.expandvars(path)

        self.serie_arrays = SerieOfArraysFromFiles(path)
        self.tools = PreprocTools(params)
        self.results = {}

    def __call__(self):
        """Apply all enabled preprocessing tools on the series of arrays
        and saves them in self.results.

        """
        name_files = self.serie_arrays.get_name_files()
        for i, img in enumerate(self.serie_arrays.iter_arrays()):
            name = name_files[i]
            self.results[name] = self.tools(img)
Exemplo n.º 4
0
    def __init__(self, params=None):
        """Set path for results and loads images as SerieOfArraysFromFiles."""
        if params is None:
            params = self.__class__.create_default_params()

        self.params = params.preproc

        path = params.preproc.series.path
        if not os.path.exists(path):
            path = params.preproc.series.path = os.path.expandvars(path)

        self.serie_arrays = SerieOfArraysFromFiles(path)
        self.tools = PreprocTools(params)
        self.results = {}
Exemplo n.º 5
0
class PreprocBase(object):
    """Preprocess series of images with various tools. """
    @classmethod
    def create_default_params(cls):
        """Class method returning the default parameters."""
        params = ParamContainer(tag='params')
        params._set_child('preproc')
        params.preproc._set_child('series', attribs={'path': ''})

        PreprocTools._complete_class_with_tools(params)

        return params

    def __init__(self, params=None):
        """Set path for results and loads images as SerieOfArraysFromFiles."""
        if params is None:
            params = self.__class__.create_default_params()

        self.params = params.preproc

        path = params.preproc.series.path
        if not os.path.exists(path):
            path = params.preproc.series.path = os.path.expandvars(path)

        self.serie_arrays = SerieOfArraysFromFiles(path)
        self.tools = PreprocTools(params)
        self.results = {}

    def __call__(self):
        """Apply all enabled preprocessing tools on the series of arrays
        and saves them in self.results.

        """
        name_files = self.serie_arrays.get_name_files()
        for i, img in enumerate(self.serie_arrays.iter_arrays()):
            name = name_files[i]
            self.results[name] = self.tools(img)
Exemplo n.º 6
0
    def __init__(self, args):

        if str_error_import_textbox:
            raise ImportError(str_error_import_textbox)

        path_in = args.path
        if os.path.isdir(path_in):
            self.path_files = glob(os.path.join(path_in, "*"))
            self.path_files = [
                path for path in self.path_files if check_image(path)
            ]
            self.path_files.sort()
            ifile = 0
        else:
            path_file = glob(path_in)[0]
            self.path_files = glob(os.path.join(os.path.split(path_file)[0], "*"))
            self.path_files = [
                path for path in self.path_files if check_image(path)
            ]
            self.path_files.sort()
            ifile = self.path_files.index(path_file)

        if len(self.path_files) == 0:
            raise ValueError("No image files detected.")

        if len(self.path_files) == 1 and self.path_files[0].endswith(".cine"):
            serie = SerieOfArraysFromFiles(self.path_files[0])
            self.path_files = serie.get_path_arrays()

        path_dir = os.path.split(self.path_files[0])[0]
        self.nb_images = len(self.path_files)
        print("Will use {} images in the dir {}".format(self.nb_images, path_dir))

        self._buttons = {}
        self._textboxes = {}

        fig = self.fig = plt.figure()
        fig.canvas.set_window_title(
            path_dir + " (" + time_as_str()[-8:].replace("-", ":") + ")"
        )
        self.ax = fig.add_axes([0.07, 0.15, 0.7, 0.78])

        self.maps = {}
        try:
            self.cmap = plt.cm.viridis
        except AttributeError:
            self.cmap = plt.cm.jet

        self.ifile = ifile
        self._last_was_increase = False

        im = imread(self.path_files[ifile])
        self.clim = [0, 0.99 * im.max()]
        self._updating_clim = False

        self.loadim(ifile, im)
        name_file = self.get_namefile()
        self.ax.set_title(name_file)

        self._image_changing = False

        function_buttons = [None] * len(name_buttons)
        function_buttons[0] = self._decrease_ifile_n
        function_buttons[1] = self._decrease_ifile
        function_buttons[2] = self._increase_ifile
        function_buttons[3] = self._increase_ifile_n

        y = size_button / 3.0
        for i, x in enumerate(x_buttons):
            name = name_buttons[i]
            func = function_buttons[i]
            self._create_button(fig, [x, y, size_button, size_button], name, func)

        self._n = 1

        self._create_text(
            fig,
            [0.1, y, 2 * size_button, size_button],
            "n = ",
            self._submit_n,
            "1",
        )

        self._create_text(
            fig,
            [0.87, 0.92, 1.5 * size_button, size_button],
            "cmax = ",
            self._change_cmax,
            "{:.2f}".format(self.clim[1]),
        )

        self._create_text(
            fig,
            [0.87, 0.1, 1.5 * size_button, size_button],
            "cmin = ",
            self._change_cmin,
            "{:.2f}".format(self.clim[0]),
        )

        self._create_button(
            fig, [0.65, 0.945, 1.2 * size_button, 0.045], "reload", self.reloadim
        )

        self._create_button(
            fig, [0.85, y, size_button, size_button], "auto", self.set_autoclim
        )

        cax = fig.add_axes([0.83, 0.2, 0.07, 0.7])
        self.cbar = fig.colorbar(self.mappable, cax=cax)

        fig.canvas.mpl_connect("key_press_event", self.onclick)
        print("press alt+h for help")

        plt.show()