コード例 #1
0
    def flatFieldFromFunction(self):
        '''
        calculate flatField from fitting vignetting function to averaged fit-image
        returns flatField, average background level, fitted image, valid indices mask
        '''
        fitimg, mask = self._prepare()
        mask = ~mask

        s0, s1 = fitimg.shape
        #f-value, alpha, fx, cx,     cy
        guess = (s1 * 0.7, 0, 1, s0 / 2, s1 / 2)

        # set assume normal plane - no tilt and rotation:
        fn = lambda xy, f, alpha, fx, cx, cy: vignetting(
            (xy[0] * fx, xy[1]), f, alpha, cx=cx, cy=cy)

        #         mask = fitimg>0.5

        flatfield = fit2dArrayToFn(fitimg,
                                   fn,
                                   mask=mask,
                                   guess=guess,
                                   output_shape=self._orig_shape)[0]

        return flatfield, self.bglevel / self._n, fitimg, mask
コード例 #2
0
 def flatFieldFromFunction(self): 
     '''
     calculate flatField from fitting vignetting function to averaged fit-image
     returns flatField, average background level, fitted image, valid indices mask
     '''   
     s0,s1 = self._m.avg.shape
             #f-value, alpha, fx, cx,     cy
     guess = (s1*0.7,  0,     1 , s0/2.0, s1/2.0)
     
     #set assume normal plane - no tilt and rotation:
     fn = lambda (x,y),f,alpha, fx,cx,cy:  vignetting((x*fx,y),  f, alpha, 
             cx=cx,cy=cy)
 
     fitimg = self._m.avg
     mask = fitimg>0.5
     
     flatfield = fit2dArrayToFn(fitimg, fn, mask=mask, 
                     guess=guess,output_shape=self._orig_shape)[0]
     
     return flatfield, self.bglevel/self._n, fitimg, mask
コード例 #3
0
    import pylab as plt

    n = 50
    s0, s1 = 300, 400
    size = 30  # ...of the small rect within image
    SNR = 10

    # create synthetic data:
    imgs = []
    for i in range(n):
        # random top-left position:
        r0, r1 = np.random.rand(2)
        p0, p1 = int(r0 * (s0 - size)), int(r1 * (s1 - size))
        # rect intensity depending on current position:
        color = int(vignetting((p0 + size // 2, p1 + size // 2),
                               cx=s0 // 2, cy=s1 // 2) * 255)

        img = np.zeros((s0, s1))
        img[p0: p0 + size, p1: p1 + size] = color
        imgs.append(addNoise(img, SNR))

    ###
    out, _ = vignettingFromSpotAverage(imgs, 0, averageSpot=False)
    out2, _ = vignettingFromSpotAverage(imgs, 0)
    ###
    if 'no_window' not in sys.argv:
        plt.figure('without spot average')
        plt.imshow(out, interpolation='none')

        plt.figure('with spot average')
        plt.imshow(out2, interpolation='none')
コード例 #4
0
        out = np.clip(out,0.1,1) 

        out = resize(out,self._orig_shape, mode='reflect')
        return  out, self.bglevel / self._n, fitimg, mask



if __name__ == '__main__':
    import pylab as plt
    import sys
    
    s0,s1 = 200,300
            #f-value, alpha,  rot, tilt,cx,     cy
    params = (s1*0.7,  0,     0,   0 ,  s0/2.0, s1/2.0)
    vig = np.fromfunction(lambda x,y: vignetting((x,y),*params),  (s0,s1))


    o0,o1 = 120,150
    p0,p1 = 50,75
    d0,d1 = 10,15

    ff = FlatFieldFromImgFit()
    
    #lets say we have 10 images of an object at slightly different positions
    for c in xrange(10):
        img = np.zeros((s0,s1))
        dev0 = np.random.rand()*d0
        dev1 = np.random.rand()*d1
        img[dev0+p0:dev0+p0+o0,dev1+p1:dev1+p1+o1] = 1
        img += np.random.rand(s0,s1)
コード例 #5
0

if __name__ == '__main__':
    import sys
    from time import time
    from matplotlib import pyplot as plt
    from imgProcessor.equations.vignetting import vignetting

    # make 10 vignetting arrays with slightly different optical centre
    # to simulate effects that occur when vignetting is measured badly
    d = np.linspace(-20, 20, 100)
    bg = np.random.rand(100, 100) * 10
    vigs = [np.fromfunction(
            # vignetting from function
            lambda x, y:
            vignetting((x, y), cx=50 - di, cy=50 + di),
            (100, 100)) * 100 +
            # add noise
            np.random.rand(100, 100) * 10
            for di in d]
    ###
    t0 = time()
    avg = flatFieldFromCloseDistance(vigs, bg)
    t1 = time()
    print('[flatFieldFromCloseDistance] elapsed time: %s' % (t1 - t0))

    avg2, std2 = flatFieldFromCloseDistance2(vigs, bg, calcStd=True)
    t2 = time()
    print('[flatFieldFromCloseDistance2] elapsed time: %s' % (t2 - t1))
    ###
    if 'no_window' not in sys.argv:
コード例 #6
0
        return m.avg/mx, m.var**0.5/mx
    return m.avg/mx



if __name__ == '__main__':
    from imgProcessor.equations.vignetting import vignetting
    from matplotlib import pyplot as plt
    import sys

    #make 10 vignetting arrays with slightly different optical centre
    #to simulate effects that occur when vignetting is measured badly
    d = np.linspace(-20,20,10)
    bg = np.random.rand(100,100)*10
    vigs = [np.fromfunction(lambda x,y: 
                vignetting((x,y), cx=50-di, cy=50+di),(100,100))*100+bg for di in d] 
    
    
    avg, std = flatFieldFromCalibration(bg, vigs, calcStd=True)

    if 'no_window' not in sys.argv:
        plt.figure('example vignetting img (1/10)')
        plt.imshow(vigs[0])
        plt.colorbar()
    
        plt.figure('example vignetting img (10/10)')
        plt.imshow(vigs[-1])
        plt.colorbar()
        
        plt.figure('averaged vignetting array')
        plt.imshow(avg)   
コード例 #7
0
ファイル: function.py プロジェクト: rodney-wang/imgProcessor
 def fn(xy, f, alpha, cx, cy): return vignetting(xy, f=f,
                                                 alpha=alpha,
                                                 cx=cx, cy=cy)
 f, alpha, _rot, _tilt, cx, cy = guess
コード例 #8
0
            lastm = m

        out = np.clip(out, 0.1, 1)

        out = resize(out, self._orig_shape, mode='reflect')
        return out, self.bglevel / self._n, fitimg, mask


if __name__ == '__main__':
    import pylab as plt
    import sys

    s0, s1 = 200, 300
    #f-value, alpha,  rot, tilt,cx,     cy
    params = (s1 * 0.7, 0, 0, 0, s0 / 2.0, s1 / 2.0)
    vig = np.fromfunction(lambda x, y: vignetting((x, y), *params), (s0, s1))

    o0, o1 = 120, 150
    p0, p1 = 50, 75
    d0, d1 = 10, 15

    ff = FlatFieldFromImgFit()

    #lets say we have 10 images of an object at slightly different positions
    for c in xrange(10):
        img = np.zeros((s0, s1))
        dev0 = np.random.rand() * d0
        dev1 = np.random.rand() * d1
        img[dev0 + p0:dev0 + p0 + o0, dev1 + p1:dev1 + p1 + o1] = 1
        img += np.random.rand(s0, s1)
        img *= vig
コード例 #9
0
        return m.avg / mx, m.var**0.5 / mx
    return m.avg / mx


if __name__ == '__main__':
    from imgProcessor.equations.vignetting import vignetting
    from matplotlib import pyplot as plt
    import sys

    #make 10 vignetting arrays with slightly different optical centre
    #to simulate effects that occur when vignetting is measured badly
    d = np.linspace(-20, 20, 10)
    bg = np.random.rand(100, 100) * 10
    vigs = [
        np.fromfunction(
            lambda x, y: vignetting((x, y), cx=50 - di, cy=50 + di),
            (100, 100)) * 100 + bg for di in d
    ]

    avg, std = flatFieldFromCalibration(bg, vigs, calcStd=True)

    if 'no_window' not in sys.argv:
        plt.figure('example vignetting img (1/10)')
        plt.imshow(vigs[0])
        plt.colorbar()

        plt.figure('example vignetting img (10/10)')
        plt.imshow(vigs[-1])
        plt.colorbar()

        plt.figure('averaged vignetting array')
コード例 #10
0
 def fn(xy, f, alpha, cx, cy):
     return vignetting(xy, f=f, alpha=alpha, cx=cx, cy=cy)