コード例 #1
0
    def test_background_substraction_precomputed(self):
        """
        Test clean up before polar conversion
        """
        data = self.data
        C, T, Z, Y, X = data[0].shape
        data[0].shape = Y, X
        clean_data = angleres.ARBackgroundSubtract(data[0])
        result = angleres.AngleResolved2Polar(clean_data, 201)

        desired_output = hdf5.read_data("substracted_background_image.h5")
        C, T, Z, Y, X = desired_output[0].shape
        desired_output[0].shape = Y, X

        numpy.testing.assert_allclose(result, desired_output[0], rtol=1e-04)
コード例 #2
0
    def test_background_substraction_float_input(self):
        """
        Tests for input of DataArray with float ndarray.
        """
        data = self.data
        data[0] = data[0].astype(numpy.float)
        C, T, Z, Y, X = data[0].shape
        data[0].shape = Y, X
        clean_data = angleres.ARBackgroundSubtract(data[0])
        result = angleres.AngleResolved2Polar(clean_data, 201)

        desired_output = hdf5.read_data("substracted_background_image.h5")
        C, T, Z, Y, X = desired_output[0].shape
        desired_output[0].shape = Y, X

        numpy.testing.assert_allclose(result, desired_output[0], rtol=1e-04)
コード例 #3
0
    def test_background_substraction_int8_input(self):
        """
        Tests for input of DataArray with int8 ndarray.
        """
        data = self.data
        # scipy.misc.bytescale(data)
        data[0] = data[0].astype(numpy.int64)
        data[0] = numpy.right_shift(data[0], 8)
        data[0] = data[0].astype(numpy.int8)
        C, T, Z, Y, X = data[0].shape
        data[0].shape = Y, X
        clean_data = angleres.ARBackgroundSubtract(data[0])
        result = angleres.AngleResolved2Polar(clean_data, 201)

        desired_output = angleres.AngleResolved2Polar(data[0].astype(float),
                                                      201)

        numpy.testing.assert_allclose(result, desired_output, rtol=1)
コード例 #4
0
ファイル: _static.py プロジェクト: ihebdelmic/odemis
    def _project2Polar(self, pos):
        """
        Return the polar projection of the image at the given position.
        pos (float, float, string or None): position (must be part of the ._pos)
        returns DataArray: the polar projection
        """
        # Note: Need a copy of the link to the dict. If self._polar is reset while
        # still running this method, the dict might get new entries again, though it should be empty.
        polar = self._polar
        if pos in polar:
            polard = polar[pos]
        else:
            # Compute the polar representation
            data = self._pos[pos]
            try:
                # Get bg image, if existing. It must match the polarization (defaulting to MD_POL_NONE).
                bg_image = self._getBackground(
                    data.metadata.get(MD_POL_MODE, MD_POL_NONE))

                if bg_image is None:
                    # Simple version: remove the background value
                    data_bg_corr = angleres.ARBackgroundSubtract(data)
                else:
                    data_bg_corr = img.Subtract(data,
                                                bg_image)  # metadata from data

                if numpy.prod(data_bg_corr.shape) > (1280 * 1080):
                    # AR conversion fails with very large images due to too much
                    # memory consumed (> 2Gb). So, rescale + use a "degraded" type that
                    # uses less memory. As the display size is small (compared
                    # to the size of the input image, it shouldn't actually
                    # affect much the output.
                    logging.info(
                        "AR image is very large %s, will convert to "
                        "azimuthal projection in reduced precision.",
                        data_bg_corr.shape)
                    y, x = data_bg_corr.shape
                    if y > x:
                        small_shape = 1024, int(round(1024 * x / y))
                    else:
                        small_shape = int(round(1024 * y / x)), 1024
                    # resize
                    data_bg_corr = img.rescale_hq(data_bg_corr, small_shape)

                # 2 x size of original image (on smallest axis) and at most
                # the size of a full-screen canvas
                size = min(min(data_bg_corr.shape) * 2, 1134)

                # TODO: First compute quickly a low resolution and then
                # compute a high resolution version.
                # TODO: could use the size of the canvas that will display
                # the image to save some computation time.

                # Warning: allocates lot of memory, which will not be free'd until
                # the current thread is terminated.

                polard = angleres.AngleResolved2Polar(data_bg_corr,
                                                      size,
                                                      hole=False)

                # TODO: don't hold too many of them in cache (eg, max 3 * 1134**2)
                polar[pos] = polard
            except Exception:
                logging.exception("Failed to convert to azimuthal projection")
                return data  # display it raw as fallback

        return polard