Beispiel #1
0
    def psf_calc(self, psf, data_size):
        """Precalculate the OTF etc..."""
        g = resizePSF(psf, data_size)

        #keep track of our data shape
        self.height = data_size[0]
        self.width = data_size[1]
        self.depth = data_size[2]

        self.shape = data_size

        self.FTshape = [self.shape[0], self.shape[1], self.shape[2] / 2 + 1]

        self.g = g.astype('f4')
        self.g2 = 1.0 * self.g[::-1, ::-1, ::-1]

        #allocate memory
        self.H = fftw3f.create_aligned_array(self.FTshape, 'complex64')
        self.Ht = fftw3f.create_aligned_array(self.FTshape, 'complex64')
        #self.f = np.zeros(self.shape, 'f4')
        #self.res = np.zeros(self.shape, 'f4')
        #self.S = np.zeros((np.size(self.f), 3), 'f4')

        #self._F = fftw3f.create_aligned_array(self.FTshape, 'complex64')
        #self._r = fftw3f.create_aligned_array(self.shape, 'f4')
        #S0 = self.S[:,0]

        #create plans & calculate OTF and conjugate transformed OTF
        fftw3f.Plan(self.g, self.H, 'forward')()
        fftw3f.Plan(self.g2, self.Ht, 'forward')()

        self.Ht /= g.size
        self.H /= g.size
Beispiel #2
0
    def psf_calc(self, psf, data_size):
        '''Precalculate the OTF etc...'''
        g = resizePSF(psf, data_size)


        #keep track of our data shape
        self.height = data_size[0]
        self.width  = data_size[1]
        self.depth  = data_size[2]

        self.shape = data_size

        self.FTshape = [self.shape[0], self.shape[1], self.shape[2]/2 + 1]

        self.g = g.astype('f4');
        self.g2 = 1.0*self.g[::-1, ::-1, ::-1]

        #allocate memory
        self.H = fftw3f.create_aligned_array(self.FTshape, 'complex64')
        self.Ht = fftw3f.create_aligned_array(self.FTshape, 'complex64')
        #self.f = zeros(self.shape, 'f4')
        #self.res = zeros(self.shape, 'f4')
        #self.S = zeros((size(self.f), 3), 'f4')

        #self._F = fftw3f.create_aligned_array(self.FTshape, 'complex64')
        #self._r = fftw3f.create_aligned_array(self.shape, 'f4')
        #S0 = self.S[:,0]

        #create plans & calculate OTF and conjugate transformed OTF
        fftw3f.Plan(self.g, self.H, 'forward')()
        fftw3f.Plan(self.g2, self.Ht, 'forward')()

        self.Ht /= g.size;
        self.H /= g.size;
Beispiel #3
0
    def psf_calc(self, psf, data_size):
        """Precalculate the OTF etc..."""
        g = resizePSF(psf, data_size)
        #normalise
        g /= g[:, :, g.shape[2] / 2].sum()

        #keep track of our data shape
        self.height = data_size[0]
        self.width = data_size[1]
        self.depth = data_size[2]

        self.shape = data_size

        self.FTshape = list(
            self.shape[:-1]
        )  #[self.shape[0], self.shape[1], self.shape[2]/2 + 1]
        self.FTshape[-1] = self.FTshape[-1] / 2 + 1

        self.g = g.astype('f4')

        self.g2 = 1.0 * self.g[::-1, ::-1, :]

        self.H = []
        self.Ht = []

        for i in range(self.shape[-1]):

            #allocate memory
            self.H.append(
                fftw3f.create_aligned_array(self.FTshape, 'complex64'))
            self.Ht.append(
                fftw3f.create_aligned_array(self.FTshape, 'complex64'))

            #create plans & calculate OTF and conjugate transformed OTF
            fftw3f.Plan(1.0 * self.g[:, :, i], self.H[i], 'forward')()
            fftw3f.Plan(1.0 * self.g2[:, :, i], self.Ht[i], 'forward')()

            self.Ht[i] /= g[:, :, i].size
            self.H[i] /= g[:, :, i].size
Beispiel #4
0
    def psf_calc(self, psf, data_size):
        '''Precalculate the OTF etc...'''
        g = resizePSF(psf, data_size)
        #normalise
        g /= g[:,:,g.shape[2]/2].sum()


        #keep track of our data shape
        self.height = data_size[0]
        self.width  = data_size[1]
        self.depth  = data_size[2]

        self.shape = data_size

        self.FTshape = list(self.shape[:-1]) #[self.shape[0], self.shape[1], self.shape[2]/2 + 1]
        self.FTshape[-1] = self.FTshape[-1]/2 +1

        self.g = g.astype('f4');
        
        self.g2 = 1.0*self.g[::-1, ::-1, :]
            
        self.H = []
        self.Ht = []
        
        for i in range(self.shape[-1]):

            #allocate memory
            self.H.append(fftw3f.create_aligned_array(self.FTshape, 'complex64'))
            self.Ht.append(fftw3f.create_aligned_array(self.FTshape, 'complex64'))
            

            #create plans & calculate OTF and conjugate transformed OTF
            fftw3f.Plan(1.0*self.g[:,:,i], self.H[i], 'forward')()
            fftw3f.Plan(1.0*self.g2[:,:,i], self.Ht[i], 'forward')()
    
            self.Ht[i] /= g[:,:,i].size
            self.H[i] /= g[:,:,i].size
Beispiel #5
0
    def psf_calc(self, psf, data_size):
        '''Precalculate the OTF etc...'''
#        pw = (numpy.array(data_size) - psf.shape)/2.
#        pw1 = numpy.floor(pw)
#        pw2 = numpy.ceil(pw)
#
#        g = psf/psf.sum()
#
#        #work out how we're going to need to pad to get the PSF the same size as our data
#        if pw1[0] < 0:
#            if pw2[0] < 0:
#                g = g[-pw1[0]:pw2[0]]
#            else:
#                g = g[-pw1[0]:]
#
#            pw1[0] = 0
#            pw2[0] = 0
#
#        if pw1[1] < 0:
#            if pw2[1] < 0:
#                g = g[-pw1[1]:pw2[1]]
#            else:
#                g = g[-pw1[1]:]
#
#            pw1[1] = 0
#            pw2[1] = 0
#
#        if pw1[2] < 0:
#            if pw2[2] < 0:
#                g = g[-pw1[2]:pw2[2]]
#            else:
#                g = g[-pw1[2]:]
#
#            pw1[2] = 0
#            pw2[2] = 0
#
#
#        #do the padding
#        #g = pad.with_constant(g, ((pw2[0], pw1[0]), (pw2[1], pw1[1]),(pw2[2], pw1[2])), (0,))
#        g_ = fftw3f.create_aligned_array(data_size, 'float32')
#        g_[:] = 0
#        #print g.shape, g_.shape, g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:-pw1[2]].shape
#        if pw1[2] == 0:
#            g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:] = g
#        else:
#            g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:-pw1[2]] = g
#        #g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:-pw1[2]] = g
#        g = g_
        
        
        print psf.sum()
        
        g = resizePSF(psf, data_size)
        print g.sum()


        #keep track of our data shape
        self.height = data_size[0]
        self.width  = data_size[1]
        self.depth  = data_size[2]

        self.shape = data_size
        
        print('Calculating OTF') 

        FTshape = [self.shape[0], self.shape[1], self.shape[2]/2 + 1]

        self.g = g.astype('f4');
        self.g2 = 1.0*self.g[::-1, ::-1, ::-1]

        #allocate memory
        self.H = fftw3f.create_aligned_array(FTshape, 'complex64')
        self.Ht = fftw3f.create_aligned_array(FTshape, 'complex64')
        #self.f = zeros(self.shape, 'f4')
        #self.res = zeros(self.shape, 'f4')
        #self.S = zeros((size(self.f), 3), 'f4')

        self._F = fftw3f.create_aligned_array(FTshape, 'complex64')
        self._r = fftw3f.create_aligned_array(self.shape, 'f4')
        #S0 = self.S[:,0]

        #create plans & calculate OTF and conjugate transformed OTF
        fftw3f.Plan(self.g, self.H, 'forward')()
        fftw3f.Plan(self.g2, self.Ht, 'forward')()

        self.Ht /= g.size;
        self.H /= g.size;
        
        print('Creating plans for FFTs - this might take a while')

        #calculate plans for other ffts
        self._plan_r_F = fftw3f.Plan(self._r, self._F, 'forward', flags = FFTWFLAGS, nthreads=NTHREADS)
        self._plan_F_r = fftw3f.Plan(self._F, self._r, 'backward', flags = FFTWFLAGS, nthreads=NTHREADS)
        
        fftwWisdom.save_wisdom()
        
        print('Done planning')
Beispiel #6
0
    def psf_calc(self, psf, data_size):
        '''Precalculate the OTF etc...'''
#        pw = (numpy.array(data_size) - psf.shape)/2.
#        pw1 = numpy.floor(pw)
#        pw2 = numpy.ceil(pw)
#
#        g = psf/psf.sum()
#
#        #work out how we're going to need to pad to get the PSF the same size as our data
#        if pw1[0] < 0:
#            if pw2[0] < 0:
#                g = g[-pw1[0]:pw2[0]]
#            else:
#                g = g[-pw1[0]:]
#
#            pw1[0] = 0
#            pw2[0] = 0
#
#        if pw1[1] < 0:
#            if pw2[1] < 0:
#                g = g[-pw1[1]:pw2[1]]
#            else:
#                g = g[-pw1[1]:]
#
#            pw1[1] = 0
#            pw2[1] = 0
#
#        if pw1[2] < 0:
#            if pw2[2] < 0:
#                g = g[-pw1[2]:pw2[2]]
#            else:
#                g = g[-pw1[2]:]
#
#            pw1[2] = 0
#            pw2[2] = 0
#
#
#        #do the padding
#        #g = pad.with_constant(g, ((pw2[0], pw1[0]), (pw2[1], pw1[1]),(pw2[2], pw1[2])), (0,))
#        g_ = fftw3f.create_aligned_array(data_size, 'float32')
#        g_[:] = 0
#        #print g.shape, g_.shape, g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:-pw1[2]].shape
#        if pw1[2] == 0:
#            g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:] = g
#        else:
#            g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:-pw1[2]] = g
#        #g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:-pw1[2]] = g
#        g = g_

        g = resizePSF(psf, data_size)


        #keep track of our data shape
        self.height = data_size[0]
        self.width  = data_size[1]
        self.depth  = data_size[2]

        self.shape = data_size

        self.g = g;

        #calculate OTF and conjugate transformed OTF
        self.H = (fftn(g));
        self.Ht = g.size*(ifftn(g));
Beispiel #7
0
    def psf_calc(self, psf, data_size):
        '''Precalculate the OTF etc...'''
        #        pw = (numpy.array(data_size) - psf.shape)/2.
        #        pw1 = numpy.floor(pw)
        #        pw2 = numpy.ceil(pw)
        #
        #        g = psf/psf.sum()
        #
        #        #work out how we're going to need to pad to get the PSF the same size as our data
        #        if pw1[0] < 0:
        #            if pw2[0] < 0:
        #                g = g[-pw1[0]:pw2[0]]
        #            else:
        #                g = g[-pw1[0]:]
        #
        #            pw1[0] = 0
        #            pw2[0] = 0
        #
        #        if pw1[1] < 0:
        #            if pw2[1] < 0:
        #                g = g[-pw1[1]:pw2[1]]
        #            else:
        #                g = g[-pw1[1]:]
        #
        #            pw1[1] = 0
        #            pw2[1] = 0
        #
        #        if pw1[2] < 0:
        #            if pw2[2] < 0:
        #                g = g[-pw1[2]:pw2[2]]
        #            else:
        #                g = g[-pw1[2]:]
        #
        #            pw1[2] = 0
        #            pw2[2] = 0
        #
        #
        #        #do the padding
        #        #g = pad.with_constant(g, ((pw2[0], pw1[0]), (pw2[1], pw1[1]),(pw2[2], pw1[2])), (0,))
        #        g_ = fftw3f.create_aligned_array(data_size, 'float32')
        #        g_[:] = 0
        #        #print g.shape, g_.shape, g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:-pw1[2]].shape
        #        if pw1[2] == 0:
        #            g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:] = g
        #        else:
        #            g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:-pw1[2]] = g
        #        #g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:-pw1[2]] = g
        #        g = g_

        print psf.sum()

        g = resizePSF(psf, data_size)
        print g.sum()

        #keep track of our data shape
        self.height = data_size[0]
        self.width = data_size[1]
        self.depth = data_size[2]

        self.shape = data_size

        print('Calculating OTF')

        FTshape = [self.shape[0], self.shape[1], self.shape[2] / 2 + 1]

        self.g = g.astype('f4')
        self.g2 = 1.0 * self.g[::-1, ::-1, ::-1]

        #allocate memory
        self.H = fftw3f.create_aligned_array(FTshape, 'complex64')
        self.Ht = fftw3f.create_aligned_array(FTshape, 'complex64')
        #self.f = zeros(self.shape, 'f4')
        #self.res = zeros(self.shape, 'f4')
        #self.S = zeros((size(self.f), 3), 'f4')

        self._F = fftw3f.create_aligned_array(FTshape, 'complex64')
        self._r = fftw3f.create_aligned_array(self.shape, 'f4')
        #S0 = self.S[:,0]

        #create plans & calculate OTF and conjugate transformed OTF
        fftw3f.Plan(self.g, self.H, 'forward')()
        fftw3f.Plan(self.g2, self.Ht, 'forward')()

        self.Ht /= g.size
        self.H /= g.size

        print('Creating plans for FFTs - this might take a while')

        #calculate plans for other ffts
        self._plan_r_F = fftw3f.Plan(self._r,
                                     self._F,
                                     'forward',
                                     flags=FFTWFLAGS,
                                     nthreads=NTHREADS)
        self._plan_F_r = fftw3f.Plan(self._F,
                                     self._r,
                                     'backward',
                                     flags=FFTWFLAGS,
                                     nthreads=NTHREADS)

        fftwWisdom.save_wisdom()

        print('Done planning')
Beispiel #8
0
    def psf_calc(self, psf, data_size):
        '''Precalculate the OTF etc...'''
        #        pw = (numpy.array(data_size) - psf.shape)/2.
        #        pw1 = numpy.floor(pw)
        #        pw2 = numpy.ceil(pw)
        #
        #        g = psf/psf.sum()
        #
        #        #work out how we're going to need to pad to get the PSF the same size as our data
        #        if pw1[0] < 0:
        #            if pw2[0] < 0:
        #                g = g[-pw1[0]:pw2[0]]
        #            else:
        #                g = g[-pw1[0]:]
        #
        #            pw1[0] = 0
        #            pw2[0] = 0
        #
        #        if pw1[1] < 0:
        #            if pw2[1] < 0:
        #                g = g[-pw1[1]:pw2[1]]
        #            else:
        #                g = g[-pw1[1]:]
        #
        #            pw1[1] = 0
        #            pw2[1] = 0
        #
        #        if pw1[2] < 0:
        #            if pw2[2] < 0:
        #                g = g[-pw1[2]:pw2[2]]
        #            else:
        #                g = g[-pw1[2]:]
        #
        #            pw1[2] = 0
        #            pw2[2] = 0
        #
        #
        #        #do the padding
        #        #g = pad.with_constant(g, ((pw2[0], pw1[0]), (pw2[1], pw1[1]),(pw2[2], pw1[2])), (0,))
        #        g_ = fftw3f.create_aligned_array(data_size, 'float32')
        #        g_[:] = 0
        #        #print g.shape, g_.shape, g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:-pw1[2]].shape
        #        if pw1[2] == 0:
        #            g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:] = g
        #        else:
        #            g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:-pw1[2]] = g
        #        #g_[pw2[0]:-pw1[0], pw2[1]:-pw1[1], pw2[2]:-pw1[2]] = g
        #        g = g_

        g = resizePSF(psf, data_size)

        #keep track of our data shape
        self.height = data_size[0]
        self.width = data_size[1]
        self.depth = data_size[2]

        self.shape = data_size

        self.g = g

        #calculate OTF and conjugate transformed OTF
        self.H = (fftn(g))
        self.Ht = g.size * (ifftn(g))