Beispiel #1
0
    def get_interpolator(self, image, threshold):
        im = imread(image)

        if threshold is not None:
            im[im < threshold] = 0.0
        im_sparse = sparse.coo_matrix(im)

        # Interpolation function
        return interpolate.Rbf(
            im_sparse.col, im_sparse.row, im_sparse.data, function="gaussian"
        )
Beispiel #2
0
    def get_interpolator(self, image, threshold):
        im = imread(image)

        if threshold is not None:
            im[im < threshold] = 0.0
        im_sparse = sparse.coo_matrix(im)

        # Interpolation function
        return interpolate.NearestNDInterpolator(
            (im_sparse.col, im_sparse.row), im_sparse.data
        )
Beispiel #3
0
def construct_image_points(path, origin):
    image = imread(str(path))
    # image = image.astype(np.uint8)
    # Rescale
    scale = image.max()
    image = image * (256 / scale)

    params = SimpleCircleGrid.create_default_params()
    circle_grid = SimpleCircleGrid(params)
    centers = circle_grid.detect_grid(image, origin, nx=7, ny=7, ds=50)

    return centers
Beispiel #4
0
    def view(self, path, title=None, hide_crosshair=True):
        """
        ImageView, a high-level widget for displaying and analyzing 2D and 3D
        data. ImageView provides:

          1. A zoomable region (ViewBox) for displaying the image
          2. A combination histogram and gradient editor (HistogramLUTItem)
             for controlling the visual appearance of the image
          3. A timeline for selecting the currently displayed frame (for 3D
             data only).
          4. Tools for very basic analysis of image data (see ROI and Norm
             buttons)

        """
        imv = pg.ImageView()
        win = self._win(title)
        self._add_gfx_item(win, imv)

        if not isinstance(path, str):
            data = []
            for p in path:
                logger.info(f"Viewing {p}")
                data.append(imread(p).transpose())

            data = np.array(data)
            imv.setImage(data, xvals=np.linspace(0, len(path), data.shape[0]))
        elif Path(path).is_dir():
            raise ValueError("Expected files not directory.")
        else:
            logger.info(f"Viewing {path}")
            try:
                data = imread(path).transpose()
            except AttributeError:
                raise ValueError(f"Is {path} an image?")
            imv.setImage(data)

        vb = imv.imageItem.getViewBox()
        self._add_crosshair(win, imv, vb, hide_lines=hide_crosshair)
    def compute_kx(self, serie):
        if len(serie) == 0:
            logger.warning("0 ref image. Use of default k_x = 70.75.")
            return 70.75

        names = serie.get_name_arrays()
        ref = np.zeros((self.ymax - self.ymin, self.xmax - self.xmin))
        ii = 0

        for name in names:
            array = imread(str(Path(self.path_ref) / name))
            frame = array[self.ymin:self.ymax,
                          self.xmin:self.xmax].astype(float)
            frame = self.frame_normalize(frame)
            ref = ref + frame
            ii += 1
        ref = ref / ii
        return self.wave_vector(ref, self.ymin, self.ymax, self.xmin,
                                self.xmax, self.sur)
Beispiel #6
0
    def test_calibrate(self):
        """Tests construct_object_points and CalibCV methods."""
        path_input = pathbase / "cam0" / "0mm_cam0.tif"
        with stdout_redirected():
            calib = CalibCV("fluidimage_test_calib_cv.h5")

        result_cache = self.calib_cache.params

        origin = (250, 250)  # Hardcoded origin
        imgpoints = [construct_image_points(path_input, origin)]
        objpoints = [construct_object_points(7, 7, 0.0, 3.0)]
        zs = [0]
        im_shape = imread(str(path_input)).shape[::-1]
        ret, mtx, dist, rvecs, tvecs = calib.calibrate(
            imgpoints, objpoints, zs, im_shape, origin, debug=True
        )

        assert_array_equal(mtx, result_cache.cam_mtx)
        assert_almost_equal(rvecs[0], result_cache.rotation[2])
        assert_almost_equal(tvecs[0], result_cache.translate[2])
 def imread(self, path):
     array = imread(path)
     return (array, path)
Beispiel #8
0
 def imread(self, path):
     """Read an image"""
     array = imread(path)
     return (array, path)
Beispiel #9
0
 def _imread(path):
     image = imread(path)
     return image, Path(path).name
Beispiel #10
0
    def __init__(self, params, logging_level="info", nb_max_workers=None):

        self.params = params

        self.serie = SerieOfArraysFromFiles(
            params.images.path, params.images.str_slice
        )

        path_dir = Path(self.serie.path_dir)
        path_dir_result, self.how_saving = prepare_path_dir_result(
            path_dir, params.saving.path, params.saving.postfix, params.saving.how
        )

        self.path_dir_result = path_dir_result
        self.path_dir_src = Path(path_dir)

        if not isinstance(params.reference, int):
            reference = Path(params.reference).expanduser()
        else:
            reference = params.reference

        if isinstance(reference, int):
            names = self.serie.get_name_arrays()
            names = sorted(names)
            path_reference = path_dir / names[reference]

        else:
            reference = Path(reference)
            if reference.is_file():
                path_reference = reference
            else:
                path_reference = path_dir_result / reference
                if not path_reference.is_file():
                    raise ValueError(
                        "Bad value of params.reference:" + path_reference
                    )

        self.name_reference = path_reference.name
        self.path_reference = path_reference
        self.image_reference = imread(path_reference)

        super().__init__(
            path_dir_result=path_dir_result,
            logging_level=logging_level,
            nb_max_workers=nb_max_workers,
        )

        queue_paths = self.add_queue("paths")
        queue_arrays = queue_arrays1 = self.add_queue("arrays")
        queue_bos = self.add_queue("bos")

        if params.preproc.im2im is not None:
            queue_arrays1 = self.add_queue("arrays1")

        self.add_work(
            "fill paths",
            func_or_cls=self.fill_queue_paths,
            output_queue=queue_paths,
            kind=("global", "one shot"),
        )

        def _imread(path):
            image = imread(path)
            return image, Path(path).name

        self.add_work(
            "read array",
            func_or_cls=_imread,
            input_queue=queue_paths,
            output_queue=queue_arrays,
            kind="io",
        )

        if params.preproc.im2im is not None:
            im2im_func = image2image.TopologyImage2Image.init_im2im(
                self, params.preproc
            )

            self.add_work(
                "image2image",
                func_or_cls=im2im_func,
                input_queue=queue_arrays,
                output_queue=queue_arrays1,
            )

        self.add_work(
            "compute bos",
            func_or_cls=self.calcul,
            params_cls=params,
            input_queue=queue_arrays,
            output_queue=queue_bos,
        )

        self.add_work(
            "save bos",
            func_or_cls=self.save_bos_object,
            input_queue=queue_bos,
            kind="io",
        )