def _process(self, psf):  
        w = self.display.widget
        img = w.image

        img = img[w.currentIndex].copy()
        #Wiener method needs image scaled (-1,1):
        mn, mx = img.min(), img.max()
        img-=mn
        img/=(mx-mn)
         
        vals = self._bRange()
        out = []        
        for balance in vals:
            o = wiener(img, psf, balance)
            #Scale back:
            o[o<0]=0
            o*=(mx-mn)
            o+=mn
            out.append(o)
        return out, ['Balance=%s' %v for v in vals]
    def _process(self, psf):
        w = self.display.widget
        img = w.image

        img = img[w.currentIndex].copy()
        #Wiener method needs image scaled (-1,1):
        mn, mx = img.min(), img.max()
        img -= mn
        img /= (mx - mn)

        vals = self._bRange()
        out = []
        for balance in vals:
            o = wiener(img, psf, balance)
            #Scale back:
            o[o < 0] = 0
            o *= (mx - mn)
            o += mn
            out.append(o)
        return out, ['Balance=%s' % v for v in vals]
    def _correctBlur(self, image, light_spectrum, date):
        #save startup time
        from skimage.restoration.deconvolution import unsupervised_wiener, wiener

        d = self.getCoeff('psf', light_spectrum, date)
        if not d:
            print 'skip deconvolution // no PSF set'
            return image
        psf = d[2]
        mx = image.max()
        image/=mx
        
        balance = self.getCoeff('balance', light_spectrum, date)
        if balance is None:
            print 'no balance value for wiener deconvolution found // use unsupervised_wiener instead // this will take some time'
            deconvolved, _ = unsupervised_wiener(image, psf)
        else:
            deconvolved = wiener(image, psf, balance[2])
        deconvolved[deconvolved<0]=0
        deconvolved*=mx
        return deconvolved
Beispiel #4
0
    def _correctBlur(self, image, light_spectrum, date):
        #save startup time
        from skimage.restoration.deconvolution import unsupervised_wiener, wiener

        d = self.getCoeff('psf', light_spectrum, date)
        if not d:
            print 'skip deconvolution // no PSF set'
            return image
        psf = d[2]
        mx = image.max()
        image /= mx

        balance = self.getCoeff('balance', light_spectrum, date)
        if balance is None:
            print 'no balance value for wiener deconvolution found // use unsupervised_wiener instead // this will take some time'
            deconvolved, _ = unsupervised_wiener(image, psf)
        else:
            deconvolved = wiener(image, psf, balance[2])
        deconvolved[deconvolved < 0] = 0
        deconvolved *= mx
        return deconvolved
Beispiel #5
0
def inv_filter(img, S, noise=0.001):

    # If you want to call inv_filter, you have to impute first to avoid
    # spectral artifacts
    assert(np.all(img.mask == False))

    # unfortunately scipy deconvolution messes with our scale...
    F = pad2(img)

    # Do my scaling here to keep scipy happy!
    machine_scale = F.max()
    F /= machine_scale

    S = S / S.sum()  # avoids any scaling effects

    img_w, img_h, img_ch = img.shape
    out = np.zeros_like(F)
    for ch in range(img_ch):
        out[:, :, ch] = deconvolution.wiener(F[:, :, ch].data.astype(float),
                                             S, noise)

    out = machine_scale * out[:img_w, :img_h]
    # out[img.mask] = 0.
    return np.ma.masked_array(out, mask=img.mask)