コード例 #1
0
def circular_average(image,
                     calibrated_center,
                     threshold=-1,
                     nx=None,
                     pixel_size=None,
                     mask=None):
    """Circular average of the the image data
    The circular average is also known as the radial integration
    Parameters
    ----------
    image : array
        Image to compute the average as a function of radius
    calibrated_center : tuple
        The center of the image in pixel units
        argument order should be (row, col)
    threshold : int, optional
        Ignore counts above `threshold`
    nx : int, optional
        Number of bins in R. Defaults to 100
    pixel_size : tuple, optional
        The size of a pixel (in a real unit, like mm).
        argument order should be (pixel_height, pixel_width)
    Returns
    -------
    bin_centers : array
        The center of each bin in R. shape is (nx, )
    ring_averages : array
        Radial average of the image. shape is (nx, ).
    """
    radial_val = utils.radial_grid(calibrated_center, image.shape, pixel_size)

    if nx is None:
        ps = np.min(pixel_size)
        max_x = np.max(radial_val) / ps
        min_x = np.min(radial_val) / ps
        nx = int(max_x - min_x)
    #print (nx)

    if mask is None: mask = 1

    bin_edges, sums, counts = bin_1D(np.ravel(radial_val * mask),
                                     np.ravel(image * mask), nx)
    th_mask = counts > threshold
    ring_averages = sums[th_mask] / counts[th_mask]

    bin_centers = utils.bin_edges_to_centers(bin_edges)[th_mask]

    return bin_centers, ring_averages
コード例 #2
0
ファイル: develop.py プロジェクト: yugangzhang/chx_backups
def circular_average(image, calibrated_center, threshold=-1, nx=None,
                     pixel_size=None, mask=None):
    """Circular average of the the image data
    The circular average is also known as the radial integration
    Parameters
    ----------
    image : array
        Image to compute the average as a function of radius
    calibrated_center : tuple
        The center of the image in pixel units
        argument order should be (row, col)
    threshold : int, optional
        Ignore counts above `threshold`
    nx : int, optional
        Number of bins in R. Defaults to 100
    pixel_size : tuple, optional
        The size of a pixel (in a real unit, like mm).
        argument order should be (pixel_height, pixel_width)
    Returns
    -------
    bin_centers : array
        The center of each bin in R. shape is (nx, )
    ring_averages : array
        Radial average of the image. shape is (nx, ).
    """
    radial_val = utils.radial_grid(calibrated_center, image.shape,  pixel_size )
    
    if nx is None:
        ps =np.min( pixel_size )
        max_x = np.max(radial_val)/ps
        min_x = np.min(radial_val)/ps        
        nx = int(max_x - min_x)
    #print (nx)

    if mask is  None: mask =1

    bin_edges, sums, counts =  bin_1D(np.ravel(radial_val  * mask ),
                                           np.ravel(image  * mask), nx)
    th_mask = counts > threshold
    ring_averages = sums[th_mask] / counts[th_mask]

    bin_centers = utils.bin_edges_to_centers(bin_edges)[th_mask]

    return bin_centers, ring_averages
コード例 #3
0
ファイル: test_roi.py プロジェクト: giltis/scikit-xray
def _helper_check(pixel_list, inds, num_pix, edges, center,
                  img_dim, num_qs):
    # recreate the indices using pixel_list and inds values
    ty = np.zeros(img_dim).ravel()
    ty[pixel_list] = inds
    data = ty.reshape(img_dim[0], img_dim[1])

    # get the grid values from the center
    grid_values = core.radial_grid(img_dim, center)

    # get the indices into a grid
    zero_grid = np.zeros((img_dim[0], img_dim[1]))
    for r in range(num_qs):
        vl = (edges[r][0] <= grid_values) & (grid_values < edges[r][1])
        zero_grid[vl] = r + 1

    # check the num_pixels
    num_pixels = []
    for r in range(num_qs):
        num_pixels.append(int((np.histogramdd(np.ravel(grid_values), bins=1,
                                              range=[[edges[r][0],
                                                      (edges[r][1]
                                                       - 0.000001)]]))[0][0]))
    assert_array_equal(num_pix, num_pixels)
コード例 #4
0
ファイル: test_utils.py プロジェクト: giltis/scikit-xray
def test_radial_grid():
    a = core.radial_grid((3, 3), (7, 7))
    assert_equal(a[3, 3], 0)
    assert_equal(a[3, 4], 1)
コード例 #5
0
def brownian(im_shape, step_scale=1, decay=30,
             I_fluc_function=None, step_fluc_function=None):
    """
    Return a generator that yields simulated images
    of a dot moving around under brownian motion with varying intensity

    Parameters
    ----------
    im_shape : tuple
        The shape of the image.  The synthetic images gets emitted with the
        label 'img'

    step_scale : float, optional
        The size of the random steps.  This value get emitted with the label
        'T'

    decay : float, optional
        The size of the spot

    I_fluc_function : callable
        Determine the maximum intensity of the spot as a function of count

        Signature of ::

            def func(count):
                return I(count)

    step_fluc_function : callable
         Determine if step should change and new step value.  Either return
         the new step value or None.  If the new step is None, then don't emit
         a 'T' event, other wise change the temperature and emit the event

         Signature of ::

             def func(step, count):
                 if not change_step(count):
                     return new_step(step, count)
                 else:
                     return None
    """
    # This code was ported from a class-based implementation,
    # so the style of what follows is a little tortured but functional.
    im_shape = np.asarray(im_shape)
    scale = step_scale

    if I_fluc_function is None:
        I_fluc_function = lambda x: np.random.randn()

    I_func = I_fluc_function

    if step_fluc_function is None:
        step_fluc_function = lambda step, count: None

    if im_shape.ndim != 1 and len(im_shape) != 2:
        raise ValueError("image shape must be 2 dimensional "
                         "you passed in {}".format(im_shape))

    cur_position = np.asarray(im_shape) // 2
    count = 0
    while True:
        # add a random step
        step = np.random.randn(2) * scale
        cur_position += step
        # clip it
        cur_position = np.array([np.clip(v, 0, mx) for
                                 v, mx in zip(cur_position, im_shape)])
        R = utils.radial_grid(cur_position,
                                 im_shape)
        I = I_func(count)
        im = np.exp((-R**2 / decay)) * I
        count += 1
        yield im