Ejemplo n.º 1
0
    def update(self, changed, thread):
        wavelet = self.wavelet.get()

        if wavelet.get_name() in ["triangle", "triangle2", 'b1', "b3"]:
            dec = wtutils.uiwt
        else:
            dec = wtutils.uwt

        n = 1000
        nscales = min(wavelet.get_max_level(np.zeros(n)), 6)
        w = np.logspace(0, 8, 100, base=2)

        intensities = np.zeros([nscales, len(w)])
        widths = np.zeros([nscales, len(w)])
        for i, width in enumerate(w):
            s = signalutils.gaussian(n, width=width)
            # s = s / s.sum()
            # s = signalutils.square(n, width)
            # s = signalutils.lorentzian(n, width)
            # s = np.sin((2 * np.pi) * np.arange(n) / (width))
            scales = wtutils.wavedec(s, wavelet, nscales, dec=dec, boundary="zero")
            for j, scale in enumerate(scales[:-1]):
                # intensities[j, i] = (scale ** 2).sum() / s.sum()
                intensities[j, i] = scale.max()
                # intensities[j, i] = np.abs(scale).sum()

        return w, intensities, widths
Ejemplo n.º 2
0
 def update(self, changed, thread):
     return wtutils.wavedec(self.x,
                            self.wavelet.get(),
                            self.scale.get(),
                            dec=self.dec.get(),
                            boundary=self.ext.get(),
                            thread=thread)
Ejemplo n.º 3
0
    def decompose(self, wavelet_fct=None, img=None, bg=None, min_scale=None, max_scale=None):
        if wavelet_fct is None:
            wavelet_fct = self.config.get("wd_wavelet")
        if img is None:
            img = self.img
        if bg is None:
            bg = self.bg
        if min_scale is None:
            min_scale = self.config.get("min_scale")
        if max_scale is None:
            max_scale = self.config.get("max_scale")
        wt_dec = self.config.get("dec")
        if max_scale is None:
            max_scale = wavelets.get_wavelet(wavelet_fct).get_max_level(img.data)

        scales = wtutils.wavedec(img.data, wavelet_fct, max_scale, dec=wt_dec)
        self.approx = scales[-1]
        scales = scales[min_scale:-1]
        scales = [nputils.resize_like(s, img.data) for s in scales]

        scales_noise = wtutils.wave_noise_factor(bg, wavelet_fct, max_scale, wt_dec, beam=img.get_beam())
        scales_noise = scales_noise[min_scale:]

        if wavelet_fct in ['b3', 'triangle2'] :
            scales_width = [max(1.5, 3 * min(1, j) * pow(2, max(0, j - 1))) for j in range(min_scale, max_scale)]
        else:
            scales_width = [max(1, 2 * min(1, j) * pow(2, max(0, j - 1))) for j in range(min_scale, max_scale)]

        return zip(scales, scales_noise, scales_width)
Ejemplo n.º 4
0
def do_wavedec(dec, inv):
    for w in get_all_orthos_wavelets():
        for b_wt, b_pywt in get_all_boundaries():
            s = nputils.random_walk(maxn=np.random.randint(500, 2000))
            level = np.random.randint(3, 8)

            res = wtutils.wavedec(s, w, level=level, boundary=b_wt, dec=dec)

            rs = wtutils.waverec(res, w, boundary=b_wt, rec=inv)
            assert_equal(rs, s)
Ejemplo n.º 5
0
 def decompose(self, img):
     if self.dec == wtutils.uiwt:
         dec = wtutils.wavedec(img, self.wavelet, self.level,
                          self.boundary, self.dec, thread=self.thread)
         if dec is None:
             return None
         return [[k] for k in dec]
     else:
         return wtutils.wavedec2d(img, self.wavelet, self.level,
                             self.boundary, self.dec, thread=self.thread)
Ejemplo n.º 6
0
def do_wavedec(dec, inv):
    for w in get_all_orthos_wavelets():
        for b_wt, b_pywt in get_all_boundaries():
            s = nputils.random_walk(maxn=np.random.randint(500, 2000))
            level = np.random.randint(3, 8)

            res = wtutils.wavedec(s, w, level=level, boundary=b_wt, dec=dec)

            rs = wtutils.waverec(res, w, boundary=b_wt, rec=inv)
            assert_equal(rs, s)
Ejemplo n.º 7
0
    def update(self, changed, thread):
        if changed is not self.scale:
            if self.img.get() is None:
                return False
            scale_max = self.scale.get_max()
            data = self.img.get().data
            res = wtutils.wavedec(data, self.wavelet.get(), scale_max,
                                  dec=self.dec.get(), boundary=self.ext.get(), thread=thread)
            if res == None:
                return False
            self.current_wavedec = [imgutils.Image.from_image(self.img.get(), k) for k in res]

        return self.current_wavedec
Ejemplo n.º 8
0
    def decompose(self,
                  wavelet_fct=None,
                  img=None,
                  bg=None,
                  min_scale=None,
                  max_scale=None):
        if wavelet_fct is None:
            wavelet_fct = self.config.get("wd_wavelet")
        if img is None:
            img = self.img
        if bg is None:
            bg = self.bg
        if min_scale is None:
            min_scale = self.config.get("min_scale")
        if max_scale is None:
            max_scale = self.config.get("max_scale")
        wt_dec = self.config.get("dec")
        if max_scale is None:
            max_scale = wavelets.get_wavelet(wavelet_fct).get_max_level(
                img.data)

        scales = wtutils.wavedec(img.data, wavelet_fct, max_scale, dec=wt_dec)
        self.approx = scales[-1]
        scales = scales[min_scale:-1]
        scales = [nputils.resize_like(s, img.data) for s in scales]

        scales_noise = wtutils.wave_noise_factor(bg,
                                                 wavelet_fct,
                                                 max_scale,
                                                 wt_dec,
                                                 beam=img.get_beam())
        scales_noise = scales_noise[min_scale:]

        if wavelet_fct in ['b3', 'triangle2']:
            scales_width = [
                max(1.5, 3 * min(1, j) * pow(2, max(0, j - 1)))
                for j in range(min_scale, max_scale)
            ]
        else:
            scales_width = [
                max(1, 2 * min(1, j) * pow(2, max(0, j - 1)))
                for j in range(min_scale, max_scale)
            ]

        return zip(scales, scales_noise, scales_width)
Ejemplo n.º 9
0
 def decompose(self, img):
     if self.dec == wtutils.uiwt:
         dec = wtutils.wavedec(img,
                               self.wavelet,
                               self.level,
                               self.boundary,
                               self.dec,
                               thread=self.thread)
         if dec is None:
             return None
         return [[k] for k in dec]
     else:
         return wtutils.wavedec2d(img,
                                  self.wavelet,
                                  self.level,
                                  self.boundary,
                                  self.dec,
                                  thread=self.thread)
Ejemplo n.º 10
0
    def update(self, changed, thread):
        if changed is not self.scale:
            if self.img.get() is None:
                return False
            scale_max = self.scale.get_max()
            data = self.img.get().data
            res = wtutils.wavedec(data,
                                  self.wavelet.get(),
                                  scale_max,
                                  dec=self.dec.get(),
                                  boundary=self.ext.get(),
                                  thread=thread)
            if res == None:
                return False
            self.current_wavedec = [
                imgutils.Image.from_image(self.img.get(), k) for k in res
            ]

        return self.current_wavedec
Ejemplo n.º 11
0
def test_wavdec():
    for w in get_all_orthos_wavelets():
        for b_wt, b_pywt in get_all_boundaries():
            s = nputils.random_walk(maxn=np.random.randint(500, 2000))
            level = np.random.randint(3, 8)

            res = wtutils.wavedec(s, w, level=level, boundary=b_wt)
            rese = pywt.wavedec(s, w, mode=b_pywt, level=level)

            for d, de in zip(res, rese[::-1]):
                assert_equal(d, de)

            rs = wtutils.waverec(res, w, boundary=b_wt)
            rse = pywt.waverec(rese, w, mode=b_pywt)

            assert_equal(rs, rse)
            if len(s) % 2 == 0:
                assert_equal(rs, s)
            else:
                assert_equal(rs[:-1], s, atol=1e-5, rtol=1e-3)
Ejemplo n.º 12
0
def test_wavdec():
    for w in get_all_orthos_wavelets():
        for b_wt, b_pywt in get_all_boundaries():
            s = nputils.random_walk(maxn=np.random.randint(500, 2000))
            level = np.random.randint(3, 8)

            res = wtutils.wavedec(s, w, level=level, boundary=b_wt)
            rese = pywt.wavedec(s, w, mode=b_pywt, level=level)

            for d, de in zip(res, rese[::-1]):
                assert_equal(d, de)

            rs = wtutils.waverec(res, w, boundary=b_wt)
            rse = pywt.waverec(rese, w, mode=b_pywt)

            assert_equal(rs, rse)
            if len(s) % 2 == 0:
                assert_equal(rs, s)
            else:
                assert_equal(rs[:-1], s, atol=1e-5, rtol=1e-3)
Ejemplo n.º 13
0
 def update(self, changed, thread):
     return wtutils.wavedec(self.x, self.wavelet.get(), self.scale.get(),
                            dec=self.dec.get(), boundary=self.ext.get(), thread=thread)