Ejemplo n.º 1
0
    def _updateHistogram(self, data=None):
        """
        data (DataArray): the raw data to use, default to .raw[0]
        """
        # Compute histogram and compact version
        if data is None:
            if isinstance(self.raw, tuple):
                data = self._getMergedRawImage(self._das.maxzoom)
            elif not self.raw or not isinstance(self.raw, list):
                return

        data = self.raw[0] if data is None else data

        # Depth can change at each image (depends on hardware settings)
        self._updateDRange(data)

        # Initially, _drange might be None, in which case it will be guessed
        hist, edges = img.histogram(data, irange=self._drange)
        if hist.size > 256:
            chist = img.compactHistogram(hist, 256)
        else:
            chist = hist
        self.histogram._full_hist = hist
        self.histogram._edges = edges
        # Read-only VA, so we need to go around...
        self.histogram._value = chist
        self.histogram.notify(chist)
Ejemplo n.º 2
0
    def test_compact(self):
        """
        test the compactHistogram()
        """
        depth = 4096  # limited depth
        size = (1024, 965)
        grey_img = numpy.zeros(size, dtype="uint16") + 1500
        grey_img[0, 0] = 0
        grey_img[0, 1] = depth - 1
        hist, edges = img.histogram(grey_img, (0, depth - 1))
        # make it compact
        chist = img.compactHistogram(hist, 256)
        self.assertEqual(len(chist), 256)
        self.assertEqual(numpy.sum(chist), numpy.prod(size))

        # make it really compact
        vchist = img.compactHistogram(hist, 1)
        self.assertEqual(vchist[0], numpy.prod(size))

        # keep it the same length
        nchist = img.compactHistogram(hist, depth)
        numpy.testing.assert_array_equal(hist, nchist)
Ejemplo n.º 3
0
    def test_compact(self):
        """
        test the compactHistogram()
        """
        depth = 4096 # limited depth
        size = (1024, 965)
        grey_img = numpy.zeros(size, dtype="uint16") + 1500
        grey_img[0, 0] = 0
        grey_img[0, 1] = depth - 1
        hist, edges = img.histogram(grey_img, (0, depth - 1))
        # make it compact
        chist = img.compactHistogram(hist, 256)
        self.assertEqual(len(chist), 256)
        self.assertEqual(numpy.sum(chist), numpy.prod(size))

        # make it really compact
        vchist = img.compactHistogram(hist, 1)
        self.assertEqual(vchist[0], numpy.prod(size))

        # keep it the same length
        nchist = img.compactHistogram(hist, depth)
        numpy.testing.assert_array_equal(hist, nchist)
Ejemplo n.º 4
0
    def _updateHistogram(self, data=None):
        """
        data (DataArray): the raw data to use, default to .raw[0] - background
          (if present).
        If will also update the intensityRange if auto_bc is enabled.
        """
        # Compute histogram and compact version
        if data is None:
            if not self.raw:
                logging.debug("Not computing histogram as .raw is empty")
                return

            data = self.raw[0]
            if isinstance(data, model.DataArrayShadow):
                # Pyramidal => use the smallest version
                data = self._getMergedRawImage(data, data.maxzoom)

            # We only do background subtraction when automatically selecting raw
            bkg = self.background.value
            if bkg is not None:
                try:
                    data = img.Subtract(data, bkg)
                except Exception as ex:
                    logging.info(
                        "Failed to subtract background when computing histogram: %s",
                        ex)

        # Depth can change at each image (depends on hardware settings)
        self._updateDRange(data)

        # Initially, _drange might be None, in which case it will be guessed
        hist, edges = img.histogram(data, irange=self._drange)
        if hist.size > 256:
            chist = img.compactHistogram(hist, 256)
        else:
            chist = hist
        self.histogram._full_hist = hist
        self.histogram._edges = edges
        # First update the value, before the intensityRange subscribers are called...
        self.histogram._value = chist

        if self.auto_bc.value:
            self._recomputeIntensityRange()

        # Notify last, so intensityRange is correct when subscribers get the new histogram
        self.histogram.notify(chist)
Ejemplo n.º 5
0
    def _updateHistogram(self, data=None):
        """
        data (DataArray): the raw data to use, default to .raw[0] - background
          (if present).
        If will also update the intensityRange if auto_bc is enabled.
        """
        # Compute histogram and compact version
        if data is None:
            if not self.raw:
                logging.debug("Not computing histogram as .raw is empty")
                return

            data = self.raw[0]
            if isinstance(data, model.DataArrayShadow):
                # Pyramidal => use the smallest version
                data = self._getMergedRawImage(data, data.maxzoom)

            # We only do background subtraction when automatically selecting raw
            bkg = self.background.value
            if bkg is not None:
                try:
                    data = img.Subtract(data, bkg)
                except Exception as ex:
                    logging.info("Failed to subtract background when computing histogram: %s", ex)

        # Depth can change at each image (depends on hardware settings)
        self._updateDRange(data)

        # Initially, _drange might be None, in which case it will be guessed
        hist, edges = img.histogram(data, irange=self._drange)
        if hist.size > 256:
            chist = img.compactHistogram(hist, 256)
        else:
            chist = hist
        self.histogram._full_hist = hist
        self.histogram._edges = edges
        # First update the value, before the intensityRange subscribers are called...
        self.histogram._value = chist

        if self.auto_bc.value:
            self._recomputeIntensityRange()

        # Notify last, so intensityRange is correct when subscribers get the new histogram
        self.histogram.notify(chist)
Ejemplo n.º 6
0
    def _updateHistogram(self, data=None):
        """
        data (DataArray): the raw data to use, default to .raw[0]
        """
        # Compute histogram and compact version
        if not self.raw and data is None:
            return

        data = self.raw[0] if data is None else data
        # Initially, _drange might be None, in which case it will be guessed
        hist, edges = img.histogram(data, irange=self._drange)
        if hist.size > 256:
            chist = img.compactHistogram(hist, 256)
        else:
            chist = hist
        self.histogram._full_hist = hist
        self.histogram._edges = edges
        # Read-only VA, so we need to go around...
        self.histogram._value = chist
        self.histogram.notify(chist)
Ejemplo n.º 7
0
    def _updateHistogram(self, data=None):
        """
        data (DataArray): the raw data to use, default to .raw[0]
        """
        # Compute histogram and compact version
        if not self.raw and data is None:
            return

        data = self.raw[0] if data is None else data
        # Initially, _drange might be None, in which case it will be guessed
        hist, edges = img.histogram(data, irange=self._drange)
        if hist.size > 256:
            chist = img.compactHistogram(hist, 256)
        else:
            chist = hist
        self.histogram._full_hist = hist
        self.histogram._edges = edges
        # Read-only VA, so we need to go around...
        self.histogram._value = chist
        self.histogram.notify(chist)