示例#1
0
def find_center_blurred(img, msk, x0=0, y0=0, threshold=None, blur_radius=4., dmax=5):
    """
    Find the center using blurred version of 'pixelwise' method.

    usage: 
    ======
    x,y = find_center_blurred(img, msk, x0=0, y0=0, threshold=None, blur_radius=4, dmax=5)
    """
    if threshold is None: threshold = img.min()
    I = spimage.sp_image_alloc(img.shape[1],img.shape[0],1)
    I.image[:] = img * (img >= threshold)
    I.mask[:] = msk[:]
    I.detector.image_center[:] = np.array([center_to_pos(x0,img.shape[1]),
                                           center_to_pos(y0,img.shape[0]), 0 ])
    kernel = spimage.sp_gaussian_kernel(float(blur_radius),int(blur_radius*8+1),int(blur_radius*8+1),1)
    c = spimage.sp_image_convolute_with_mask(I,kernel,np.array([1,1,1]).astype(np.int32))
    ds = spimage.sp_image_alloc(int(img.shape[1]/4),int(img.shape[0]/4),1)
    ds.image[:] = c.image[:-3:4,:-3:4]
    ds.mask[:] = c.mask[:-3:4,:-3:4]
    ds.detector.image_center[:] = c.detector.image_center[:] / 4.0
    spimage.sp_find_center_refine_minimal_mask(ds, int(1+dmax/4), 0)
    c.detector.image_center[:] = ds.detector.image_center[:] * 4.0
    spimage.sp_image_free(ds)
    score = spimage.sp_find_center_refine_minimal_mask(c, 4, 0)
    x = pos_to_center(c.detector.image_center[0],img.shape[1])
    y = pos_to_center(c.detector.image_center[1],img.shape[0])
    spimage.sp_image_free(I)
    spimage.sp_image_free(kernel)
    spimage.sp_image_free(c)
    return (x,y,score)
示例#2
0
def find_center_blurred(img, msk, x0=0, y0=0, threshold=None, blur_radius=4., dmax=5):
    """
    Find the center using blurred version of 'pixelwise' method.

    usage: 
    ======
    x,y = find_center_blurred(img, msk, x0=0, y0=0, threshold=None, blur_radius=4, dmax=5)
    """
    if threshold is None: threshold = img.min()
    I = spimage.sp_image_alloc(img.shape[1],img.shape[0],1)
    I.image[:] = img * (img >= threshold)
    I.mask[:] = msk[:]
    I.detector.image_center[:] = np.array([center_to_pos(x0,img.shape[1]),
                                           center_to_pos(y0,img.shape[0]), 0 ])
    kernel = spimage.sp_gaussian_kernel(float(blur_radius),int(blur_radius*8+1),int(blur_radius*8+1),1)
    c = spimage.sp_image_convolute_with_mask(I,kernel,np.array([1,1,1]).astype(np.int32))
    ds = spimage.sp_image_alloc(img.shape[1]/4,img.shape[0]/4,1)
    ds.image[:] = c.image[:-3:4,:-3:4]
    ds.mask[:] = c.mask[:-3:4,:-3:4]
    ds.detector.image_center[:] = c.detector.image_center[:] / 4.0
    spimage.sp_find_center_refine_minimal_mask(ds, int(1+dmax/4), 0)
    c.detector.image_center[:] = ds.detector.image_center[:] * 4.0
    spimage.sp_image_free(ds)
    score = spimage.sp_find_center_refine_minimal_mask(c, 4, 0)
    x = pos_to_center(c.detector.image_center[0],img.shape[1])
    y = pos_to_center(c.detector.image_center[1],img.shape[0])
    spimage.sp_image_free(I)
    spimage.sp_image_free(kernel)
    spimage.sp_image_free(c)
    return (x,y,score)
示例#3
0
def find_center_pixelwise_fast(img, msk, x0=0, y0=0, dmax=5, rmax=None):
    """
    Find center of diffraction pattern using a pixelwise comparison of centry-symmetric pixels.

    This is a faster C implementation.

    usage:
    ======
    x,y = find_center_pixelwise_fast(img, msk, x0, y0, dmax=5, rmax=None)
    """
    if rmax is not None: msk &= (spimage.rgrid(msk.shape, (x0,y0)) < rmax)
    I = spimage.sp_image_alloc(int(np.ceil(img.shape[1])), int(np.ceil(img.shape[0])), 1)
    I.image[:] = img
    I.mask[:]  = msk
    I.detector.image_center[:] = np.array([center_to_pos(x0,img.shape[1]), center_to_pos(y0,img.shape[0]), 0 ])
    success = spimage.sp_find_center_refine(I, dmax, 0, None)
    x = pos_to_center(I.detector.image_center[0],img.shape[1])
    y = pos_to_center(I.detector.image_center[1],img.shape[0])
    spimage.sp_image_free(I)
    return (x,y,success)
示例#4
0
def find_center_pixelwise_fast(img, msk, x0=0, y0=0, dmax=5, rmax=None):
    """
    Find center of diffraction pattern using a pixelwise comparison of centry-symmetric pixels.

    This is a faster C implementation.

    usage:
    ======
    x,y = find_center_pixelwise_fast(img, msk, x0, y0, dmax=5, rmax=None)
    """
    if rmax is not None: msk &= (spimage.rgrid(msk.shape, (x0,y0)) < rmax)
    I = spimage.sp_image_alloc(int(np.ceil(img.shape[1])), int(np.ceil(img.shape[0])), 1)
    I.image[:] = img
    I.mask[:]  = msk
    I.detector.image_center[:] = np.array([center_to_pos(x0,img.shape[1]), center_to_pos(y0,img.shape[0]), 0 ])
    success = spimage.sp_find_center_refine(I, dmax, 0, None)
    x = pos_to_center(I.detector.image_center[0],img.shape[1])
    y = pos_to_center(I.detector.image_center[1],img.shape[0])
    spimage.sp_image_free(I)
    return (x,y,success)