Esempio n. 1
0
    def compare(self, indices=(0, 1), suffix=None, hist=False):
        if not suffix:
            suffix = "." + self.params.saving.postfix
        pathbase = self.params.series.path + "/"

        names = self.series.get_name_all_arrays()
        im0 = imread(pathbase + names[indices[0]])
        im1 = imread(pathbase + names[indices[1]])
        im0p = imread(pathbase[:-1] + suffix + "/" + names[indices[0]])
        im1p = imread(pathbase[:-1] + suffix + "/" + names[indices[1]])
        return DisplayPreProc(im0, im1, im0p, im1p, hist=hist)
Esempio n. 2
0
    def __init__(
            self,
            point0,
            point1,
            distance,
            aspect_ratio_pixel=1.0,
            shape_image=None,
            path_image=None,
            point_origin=(0, 0),
            orig_phys=(0.0, 0.0),
    ):

        self.point0 = np.array(point0)
        self.point1 = np.array(point1)
        self.distance = distance

        delta_point = self.point1 - self.point0

        self.aspect_ratio_pixel = aspect_ratio_pixel

        self.xphys1pixel = distance / np.sqrt(delta_point[0]**2 +
                                              (aspect_ratio_pixel *
                                               delta_point[1])**2)
        self.yphys1pixel = aspect_ratio_pixel * self.xphys1pixel

        if shape_image is None:
            arr = imread(path_image)
            shape_image = arr.shape
        self.shape_image = shape_image

        self.ix_origin = point_origin[1]
        self.iy_origin = point_origin[0]

        self.xphys_origin = orig_phys[1]
        self.yphys_origin = orig_phys[0]
Esempio n. 3
0
    def setUpClass(cls):
        path_in = path_image_samples / cls.name / "Images"

        cls._work_dir = Path("test_topo_preproc_" + cls.name) / "Images"
        cls._work_dir.mkdir(parents=True, exist_ok=True)

        paths = path_in.glob("*")

        for path in paths:
            name = path.name
            im = imread(path)
            im = im[::6, ::6]
            imsave(str(cls._work_dir / name), im, as_int=True)
Esempio n. 4
0
    def setUpClass(cls):
        path_in = str(path_image_samples / cls.name / "Images")

        cls._work_dir = os.path.join(
            "test_fluidimage_topo_preproc_" + cls.name, "Images")
        if not os.path.exists(cls._work_dir):
            os.makedirs(cls._work_dir)

        paths = glob(path_in + "/*")

        for path in paths:
            name = os.path.split(path)[-1]
            im = imread(path)
            im = im[::6, ::6]
            imsave(os.path.join(cls._work_dir, name), im, as_int=True)
Esempio n. 5
0
 def loadim(self, ifile, im=None):
     _print_debug("loadim", ifile, im)
     if im is None:
         im = imread(self.path_files[ifile])
         _print_debug(self.path_files[ifile])
         _print_debug(im)
     self.mappable = self.ax.imshow(
         im,
         interpolation="nearest",
         cmap=self.cmap,
         origin="upper",
         extent=[0, im.shape[1], im.shape[0], 0],
         vmin=self.clim[0],
         vmax=self.clim[1],
     )
     self.maps[ifile] = self.mappable
Esempio n. 6
0
def load(k):
    log("load")
    return (k, imread(k))
Esempio n. 7
0
    for i0, i1 in center_indices:
        ni1 = np.zeros_like(di_range)
        ni2 = np.zeros_like(di_range)
        for i, di in enumerate(di_range):
            di2 = di // 2
            slice0 = slice(i0 - di2, i0 + di2)
            slice1 = slice(i1 - di2, i1 + di2)
            ni1[i] = particle_count(img1[slice0, slice1])
            ni2[i] = particle_count(img2[slice0, slice1])

        fio = ni2.astype(float) / ni1
        ax.plot(di_range, fio, label="centre: {},{}".format(i0, i1))
        ax.legend()

    plt.show()


if __name__ == "__main__":
    import sys
    from fluiddyn.io.image import imread

    img1 = imread(sys.argv[1])
    img2 = imread(sys.argv[2])

    argv = map(int, sys.argv[3:])
    center_indices = list(zip(argv[0::2], argv[1::2]))
    print(sys.argv)
    print(center_indices)
    particle_density(img1, center_indices)
    particle_motion_factor(img1, img2, center_indices)
Esempio n. 8
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()
Esempio n. 9
0
 def set_autoclim(self, event):
     _print_debug("set_autoclim")
     im = imread(self.path_files[self.ifile])
     self.clim = [im.min(), 0.99 * im.max()]
     self._update_clim()