Exemplo n.º 1
0
    def update(self, changed, thread):
        wavelet = self.wavelet.get()
        if wavelets.TriangeWaveletFamily().is_from(wavelet) or wavelets.BSplineWaveletFamily().is_from(wavelet):
            dec = wtutils.uiwt
            rec = wtutils.uiwt_inv
        else:
            dec = wtutils.uwt
            rec = wtutils.uwt_inv

        denoise = Denoise(wavelet, self.scale.get(), self.boundary, dec, rec, mode=self.mode.get(), thread=thread)
        img = self.img.get()

        if changed in [self.img, self.noise_level] or self.noisy is None:
            self.noisy = img.data + nputils.gaussian_noise(img.data.shape, 0, self.noise_level.get())

        estimated_noise_sigma = nputils.k_sigma_noise_estimation(self.noisy)
        print "Estimated noise:", estimated_noise_sigma

        denoised = denoise.do(self.noisy, estimated_noise_sigma, threashold_factor=self.threashold_factor.get())
        # denoised = nputils.smooth(self.noisy, 9, mode="same", boundary="symm")

        if not thread.is_alive() or denoised == None:
            return False

        return (img, imgutils.Image.from_image(img, self.noisy), imgutils.Image.from_image(img, denoised))
Exemplo n.º 2
0
 def get_bg(self, img):
     """Return either the noise level or a background map.
     """
     if self.config.data.bg_use_ksigma_method:
         return nputils.k_sigma_noise_estimation(img.data)
     if self.config.data.bg_coords is not None:
         x1, y1, x2, y2 = self.config.data.bg_coords
         prj = self.get_projection(img)
         xy_p1, xy_p2 = np.round(prj.s2p([(x1, y1), (x2, y2)])).astype(int)
         ex = [0, img.data.shape[1]]
         ey = [0, img.data.shape[0]]
         xlim1, xlim2 = sorted([nputils.clamp(xy_p1[0], *ex), nputils.clamp(xy_p2[0], *ex)])
         ylim1, ylim2 = sorted([nputils.clamp(xy_p1[1], *ey), nputils.clamp(xy_p2[1], *ey)])
         return img.data[ylim1:ylim2, xlim1:xlim2].copy()
     elif self.config.data.bg_fct is not None:
         return self.config.data.bg_fct(self, img)
     raise Exception("Bg extraction method need to be set")
Exemplo n.º 3
0
 def get_bg(self, img):
     """Return either the noise level or a background map.
     """
     if self.config.data.bg_use_ksigma_method:
         return nputils.k_sigma_noise_estimation(img.data)
     if self.config.data.bg_coords is not None:
         x1, y1, x2, y2 = self.config.data.bg_coords
         prj = self.get_projection(img)
         xy_p1, xy_p2 = np.round(prj.s2p([(x1, y1), (x2, y2)])).astype(int)
         ex = [0, img.data.shape[1]]
         ey = [0, img.data.shape[0]]
         xlim1, xlim2 = sorted(
             [nputils.clamp(xy_p1[0], *ex),
              nputils.clamp(xy_p2[0], *ex)])
         ylim1, ylim2 = sorted(
             [nputils.clamp(xy_p1[1], *ey),
              nputils.clamp(xy_p2[1], *ey)])
         return img.data[ylim1:ylim2, xlim1:xlim2].copy()
     elif self.config.data.bg_fct is not None:
         return self.config.data.bg_fct(self, img)
     raise Exception("Bg extraction method need to be set")
Exemplo n.º 4
0
    def do(self, img, noise_sigma=None, noise=None, threashold_factor=4):
        print "Denoising..."
        if noise is None and noise_sigma is None:
            noise_sigma = nputils.k_sigma_noise_estimation(img)

        res = self.decompose(img)

        if res is None:
            return None

        for (i, frame) in enumerate(itertools.chain(*res[:-1])):
            noise_factor = self.get_noise_factor(i, noise_sigma, noise)
            if noise_factor == None:
                return None
            threashold = threashold_factor * noise_factor
            mask = (abs(frame) < threashold)
            frame[mask] = 0
            if self.mode == "soft":
                frame[~mask] = frame[~mask] - threashold

        denoised = self.recompose(res, img)
        print "Done"
        return denoised
Exemplo n.º 5
0
    def do(self, img, noise_sigma=None, noise=None, threashold_factor=4):
        print "Denoising..."
        if noise is None and noise_sigma is None:
            noise_sigma = nputils.k_sigma_noise_estimation(img)

        res = self.decompose(img)

        if res is None:
            return None

        for (i, frame) in enumerate(itertools.chain(*res[:-1])):
            noise_factor = self.get_noise_factor(i, noise_sigma, noise)
            if noise_factor is None:
                return None
            threashold = threashold_factor * noise_factor
            mask = (abs(frame) < threashold)
            frame[mask] = 0
            if self.mode == "soft":
                frame[~mask] = frame[~mask] - threashold

        denoised = self.recompose(res, img)
        print "Done"
        return denoised
Exemplo n.º 6
0
    def update(self, changed, thread):
        wavelet = self.wavelet.get()
        if wavelets.TriangeWaveletFamily().is_from(
                wavelet) or wavelets.BSplineWaveletFamily().is_from(wavelet):
            dec = wtutils.uiwt
            rec = wtutils.uiwt_inv
        else:
            dec = wtutils.uwt
            rec = wtutils.uwt_inv

        denoise = Denoise(wavelet,
                          self.scale.get(),
                          self.boundary,
                          dec,
                          rec,
                          mode=self.mode.get(),
                          thread=thread)
        img = self.img.get()

        if changed in [self.img, self.noise_level] or self.noisy is None:
            self.noisy = img.data + nputils.gaussian_noise(
                img.data.shape, 0, self.noise_level.get())

        estimated_noise_sigma = nputils.k_sigma_noise_estimation(self.noisy)
        print "Estimated noise:", estimated_noise_sigma

        denoised = denoise.do(self.noisy,
                              estimated_noise_sigma,
                              threashold_factor=self.threashold_factor.get())
        # denoised = nputils.smooth(self.noisy, 9, mode="same", boundary="symm")

        if not thread.is_alive() or denoised is None:
            return False

        return (img, imgutils.Image.from_image(img, self.noisy),
                imgutils.Image.from_image(img, denoised))