コード例 #1
0
def calculate_beam_uniformity (imagearray,roidim=100,neighborhood_size=400):
     ''' Function receives image array and optionally ROI dimension (#pixels). The optional neighborhood_size parameter determines the scale of the distances between local maxima.

    Four ROIs are defined and for each ROI a mean, std and snr is calculated from the image array. The result is returned as a dictionary.
     '''

     thr = imagearray.min()/4.0     
     output = imagearray
     x,y = findmax.find_max(imagearray,neighborhood_size, threshold=thr)

     width = roidim
     height = roidim

     xdim ,ydim = np.shape(imagearray)

     middle = [elem for elem in zip(x,y) if xdim/2 - neighborhood_size < elem[0] < xdim/2 + neighborhood_size and ydim/2 - neighborhood_size < elem[1] < ydim/2 + neighborhood_size]
     
     x0 = int(middle[0][0]/2)
     x1 = int(xdim + middle[0][0])/2
     y0 = int(middle[0][1]/2)
     y1 = int(ydim + middle[0][1])/2
     
     widthx = int(xdim/10)
     widthy = int(xdim/10)

     deltax = int(xdim/10)
     deltay = int(ydim/10)

     roi1 = np.zeros(np.shape(imagearray))
     roi1[x0 - widthx : x0 +widthx, y0 - widthy:y0 + widthy] = 1
     roi1 = ma.make_mask(roi1)

     roi2 = np.zeros(np.shape(imagearray))
     roi2[x1 - widthx : x1 + widthx, y0 - widthy:y0 + widthy]=1
     roi2 = ma.make_mask(roi2)

     roi3 = np.zeros(np.shape(imagearray))
     roi3[x0 - widthx : x0 + widthx, y1 - widthy:y1 + widthy]=1
     roi3 = ma.make_mask(roi3)

     roi4 = np.zeros(np.shape(imagearray))
     roi4[x1 - widthx : x1 + widthx, y1 - widthy:y1 + widthy]=1
     roi4 = ma.make_mask(roi4)



     results = {}

     tmp1 = ma.array(imagearray,mask=1-roi1)
     print ma.count(tmp1)
     results['roi1']={'mean':np.mean(tmp1),'std':np.std(tmp1)}


     tmp2 = ma.array(imagearray,mask=1-roi2)
     results['roi2']={'mean':np.mean(tmp2),'std':np.std(tmp2)}


     tmp3 = ma.array(imagearray,mask=1-roi3)
     results['roi3']={'mean':np.mean(tmp3),'std':np.std(tmp3)}


     tmp4 = ma.array(imagearray,mask=1-roi4)
     results['roi4']={'mean':np.mean(tmp4),'std':np.std(tmp4)}



     
     avgmean = (results['roi1']['mean']+results['roi2']['mean']+results['roi3']['mean']+results['roi4']['mean'])/4.0

     avgstd = (results['roi1']['std']+results['roi2']['std']+results['roi3']['std']+results['roi4']['std'])/4.0

     if avgstd > 0:
          tmpsnr = avgmean/avgstd
     else:
          tmpsnr = -999

     results['avg']={'mean':avgmean,'std':avgstd,'snr':tmpsnr}
     results['middle'] = middle
     results['image'] = imagearray

     return results
コード例 #2
0
 def findmax(self, frame_id, neighborhood_size):
     x, y = findmax.find_max(self.pixelmap[frame_id], neighborhood_size)
     return x, y