Esempio n. 1
0
def push_zero_projections(resolution, host="localhost", port=5558):
    m = resolution
    proj_count, rows, cols = m, m, m
    scene_id = 0

    pub = tomop.publisher(host, port)

    # We let the server know we will send one dark field, and one flat field
    num_darks, num_flats = 1, 1
    packet_scan_settings = tomop.scan_settings_packet(scene_id, num_darks,
                                                      num_flats, False)
    pub.send(packet_scan_settings)

    # Initialize volume and acquisition geometry
    packet_vol_geom = tomop.geometry_specification_packet(
        scene_id, [0, 0, 0], [1, 1, 1])
    pub.send(packet_vol_geom)

    angles = np.linspace(0, np.pi, proj_count, endpoint=False)
    packet_geometry = tomop.parallel_beam_geometry_packet(
        scene_id, rows, cols, proj_count, angles)
    pub.send(packet_geometry)

    # Send dark(s) and flat(s)
    dark = np.zeros((rows, cols), dtype=np.float32).ravel()
    packet_dark = tomop.projection_packet(0, 0, [rows, cols], dark)
    pub.send(packet_dark)

    flat = np.ones((rows, cols), dtype=np.float32).ravel()
    packet_flat = tomop.projection_packet(1, 0, [rows, cols], flat)
    pub.send(packet_flat)

    # Create and send projection data consisting of zeros
    proj_data = np.zeros((proj_count, rows, cols))
    for i in np.arange(0, proj_count):
        packet_proj = tomop.projection_packet(2, i, [rows, cols],
                                              proj_data[i, :, :].ravel())
        pub.send(packet_proj)
Esempio n. 2
0
angles = angles * (math.pi / 180.0)
print(angles)


def align(xs, ys):
    zs = ss.fftconvolve(xs, ys[::-1, ::-1])
    return np.array(np.unravel_index(np.argmax(zs, axis=None),
                                     zs.shape)) - np.array(xs.shape) + [1, 1]


# start MATLAB
#future = matlab.engine.start_matlab(async=True)
#print("Finish loading MATLAB...")
#eng = future.result()

pub = tomop.publisher(args.host, args.port)
path = args.path

# PACKET 1: object volume specification
print("Sending object volume")
geom_spec = tomop.geometry_specification_packet(0, [-n / 2, -n / 2, -n / 2],
                                                [n / 2, n / 2, n / 2])
pub.send(geom_spec)
# PACKET 2: acquisition geometry
print("Sending acquisition geometry")
par_beam = tomop.parallel_beam_geometry_packet(0, m, n, count, angles)
pub.send(par_beam)

# PACKET 3: scan settings
print("Sending scan data (linear: ", not args.linearize, ")")
pub.send(tomop.scan_settings_packet(0, 0, 0, not args.linearize))
Esempio n. 3
0
    theta_vec[np.isnan(theta_vec)] = 0
    sign = np.subtract(1 * (theta_vec < 90), 1 * (theta_vec >= 90))

    curvature = np.divide(1, np.multiply(R_smallgrid, sign))

    output = dict()
    output['xmesh'] = x_smallgrid
    output['ymesh'] = y_smallgrid
    output['R'] = R_smallgrid
    output['K'] = K_combined
    output['curvature'] = curvature

    return output


pub = tomop.publisher("localhost", 5555, 0)


def callback(shape, xs, idx):
    print("callback called")

    xs = np.array(xs).reshape(shape)

    # need scene_id
    #trackerp = tomop.tracker_packet(0, "...")

    if np.amax(abs(xs)) != 0.0:
        blurred_slice = ndimage.median_filter(xs, 2)
        global_thresh = threshold_otsu(blurred_slice)
        binary_slice = blurred_slice > global_thresh  #0.3
        output = CurvatureBoundary(binary_slice, 6)
Esempio n. 4
0
def main(arg):
    parser = argparse.ArgumentParser(
        description='Push a dxchange/HDF5 data set to Slicerecon.')
    parser.add_argument("fname", help="file name of a tomographic dataset")
    parser.add_argument("--type",
                        nargs='?',
                        type=str,
                        default="slice",
                        help="reconstruction type: full (default slice)")
    parser.add_argument(
        "--nsino",
        nargs='?',
        type=float,
        default=0.5,
        help=
        "location of the sinogram used by slice reconstruction (0 top, 1 bottom): 0.5 (default 0.5)"
    )
    parser.add_argument(
        "--nsinoheight",
        nargs='?',
        type=int,
        default=16,
        help=
        "amount of vertical detector pixels to use, has to be a multiple of 2")
    parser.add_argument(
        "--tv",
        nargs='?',
        type=bool,
        default=False,
        help=
        "Use Total variation reconstruction method (Gridrec otherwise): False (default False)"
    )
    parser.add_argument("--frame",
                        nargs='?',
                        type=str,
                        default=92,
                        help="time frame with motion: 92 (default 92)")
    parser.add_argument(
        '--dataset',
        default='data',
        help=
        'which dataset to use from the HDF5 file, {data,data_dark,data_white}')
    parser.add_argument('--binning',
                        nargs='?',
                        type=int,
                        default=1,
                        help="binning factor")
    parser.add_argument(
        '--sample',
        type=int,
        default=1,
        help=
        'the binning to use on the detector, and how many projections to skip')
    parser.add_argument('--host',
                        default="localhost",
                        help='the projection server host')
    parser.add_argument('--port',
                        type=int,
                        default=5558,
                        help='the projection server port')
    parser.add_argument('--skipgeometry',
                        action='store_true',
                        help='assume the geometry packet is already sent')
    args = parser.parse_args()

    fname = args.fname

    if not os.path.isfile(fname):
        print("HDF5/dx file not found.")
        return

    nsino = float(args.nsino)
    nsinoheight = int(args.nsinoheight)
    binning = int(args.binning)
    subsampling = int(
        args.sample)  # taking 1 per (subsampling) instead of all the frames

    nproj = 600  # number of projections per 180 degrees interval, this is coded
    scene_id = 0

    assert ((nproj / subsampling).is_integer())
    assert ((nsinoheight / 2).is_integer())
    proj_count = int(
        nproj / subsampling
    )  # this should be the --group-size on the server, because we want
    # reconstructions from a sampled 180 shot
    print("Note: call the SliceRecon server with --group-size", proj_count,
          "to get reconstruction from 180 degrees angles")

    data_size = get_dx_dims(fname, 'data')

    # Select sinogram range to reconstruct.
    ssino = int(data_size[1] * nsino)
    sino_start = ssino - nsinoheight / 2 * pow(2, binning)
    sino_end = ssino + nsinoheight / 2 * pow(2, binning)
    sino = (int(sino_start), int(sino_end))

    # Read APS 32-BM raw data, for the sake of darks and flats
    print("Reading flats, darks ...")
    proj, flat, dark, _ = dxchange.read_aps_32id(
        fname, proj=1, sino=sino)  # angles give nonsense values

    # Phase retrieval for tomobank id 00080
    # sample_detector_distance = 25
    # detector_pixel_size_x = 3.0e-4
    # monochromator_energy = 16

    # Phase retrieval
    # data = tomopy.prep.phase.retrieve_phase(data,pixel_size=detector_pixel_size_x,dist=sample_detector_distance,energy=monochromator_energy,alpha=8e-03,pad=True)

    # @todo Fix center of rotation shift!
    # rot_center = data.shape[2]/2

    # Detector dimensions
    rows = proj.shape[1]
    cols = proj.shape[2]

    # parallel beam data is easy, the geometry volume is never bigger than the projection volume
    rx = np.ceil(data_size[2] / 2)  # max radius in the x,y plane
    rz = np.ceil(data_size[1] / 2)  # max radius in the z axis

    pub = tp.publisher(args.host, args.port)

    if not args.skipgeometry:
        window_min_point = [-rx, -rx, -rz]  # x,y,z
        window_max_point = [rx, rx, rz]  # x,y,z

        angles = np.linspace(0, 2 * np.pi, proj_count,
                             endpoint=False)  # np.mod(theta[0:nproj], np.pi)

        pub.send(
            tp.geometry_specification_packet(scene_id, window_min_point,
                                             window_max_point))
        pub.send(
            tp.parallel_beam_geometry_packet(scene_id, rows, cols, proj_count,
                                             angles))

        # We're not sending flats and darks to the SliceRecon server (see below) because (i) buffer may not be large
        # enough and (ii) we will want to do preprocessing of the projection data here anyway

        # already_linear_flatdarks = False
        # pub.send(tp.scan_settings_packet(scene_id, dark.shape[0], flat.shape[0], already_linear_flatdarks))
        # for i in np.arange(0, 2):
        #     pub.send(tp.projection_packet(0, i, [rows, cols], np.ascontiguousarray(dark[i, :, :].flatten())))
        #
        # for i in np.arange(0, 2):
        #     pub.send(tp.projection_packet(1, i, [rows, cols], np.ascontiguousarray(flat[i, :, :].flatten())))

    # I'm circumventing the dxchange.read_aps_32id, as it cannot select specific projections (always loading the full
    # dataset)
    exchange_base = "exchange"
    tomo_grp = '/'.join([exchange_base, 'data'])

    j = 0
    for i in np.arange(1, data_size[0], subsampling):
        print("Pushing ", i, " of ", data_size[0])
        data = dxreader.read_hdf5(fname,
                                  tomo_grp,
                                  slc=((int(i), int(i) + 1), sino))

        # Flat-field correction of raw data.
        data = tomopy.normalize(data, flat, dark)

        # Remove stripes (not so suitable for realtime really!)
        # data = tomopy.remove_stripe_fw(data, level=7, wname='sym16', sigma=1, pad=True)

        # Log filter
        # data = tomopy.minus_log(data)
        # data = tomopy.remove_nan(data, val=0.0)
        # data = tomopy.remove_neg(data, val=0.00)
        # data[np.where(data == np.inf)] = 0.00

        packet_type = 2  # projection packet
        pub.send(
            tp.projection_packet(packet_type, j, [rows, cols],
                                 np.ascontiguousarray(data[0].flatten())))
        j = j + 1