Ejemplo n.º 1
0
def main():

    # locate the input data
    input_file = existing_filepath(data_path, data_file)
    acq_data = AcquisitionData(input_file)
    
    # create reconstruction object
    recon = Reconstructor([ \
        'NoiseAdjustGadget', \
        'PCACoilGadget', \
        'CoilReductionGadget(coils_out=16)', \
        'gpuRadialSensePrepGadget(' + \
            'mode=2,' + \
            'profiles_per_frame=16,' + \
            'rotations_per_reconstruction=16,' + \
            'buffer_frames_per_rotation=16,' + \
            'buffer_length_in_rotations=2,' + \
            'reconstruction_os_factor_x=1.5,' + \
            'reconstruction_os_factor_y=1.5' + \
        ')', \
        'slice0:gpuCgSenseGadget(' + \
            'number_of_iterations=10,' + \
            'oversampling_factor=1.25,' + \
            'output_convergence=true' + \
        ')', \
        'slice1:gpuCgSenseGadget(' + \
            'sliceno=1,' + \
            'number_of_iterations=10,' + \
            'oversampling_factor=1.25,' + \
            'output_convergence=true' + \
        ')', \
        'slice2:gpuCgSenseGadget(' + \
            'sliceno=2,' + \
            'number_of_iterations=10,' + \
            'oversampling_factor=1.25,' + \
            'output_convergence=true' + \
        ')', \
        'ExtractGadget', 'AutoScaleGadget'])

    # provide raw k-space data as input
    recon.set_input(acq_data)

    # perform reconstruction
    recon.process()

    # retrieve reconstructed image data
    image_data = recon.get_output()

    image_data.show(title = 'Images')
def main():

    # locate the input data
    input_file = existing_filepath(data_path, data_file)
    acq_data = AcquisitionData(input_file)
    
    # create reconstruction object
    # Rather than using a predefined image reconstruction object, here a new 
    # image reconstruction object is created by concatinating multiple gadgets 
    # (for more information on Gadgetron and its gadgets please see: 
    # https://github.com/gadgetron/.).
    # Parameters for individual gadgets can be defined either during the 
    # creation of the reconstruction object:
    #   e.g. AcquisitionAccumulateTriggerGadget(trigger_dimension=repetition)
    # or by giving a gadget a label (cf. label ex: for the last gadget)
    # and using set_gadget_property(label, propery, value).
    # The gadgets will be concatenated and will be executed as soon as 
    # process() is called.
    recon = Reconstructor([ \
        'NoiseAdjustGadget', \
        'AsymmetricEchoAdjustROGadget', \
        'RemoveROOversamplingGadget', \
        'AcquisitionAccumulateTriggerGadget(trigger_dimension=repetition)', \
        'BucketToBufferGadget(split_slices=true, verbose=false)', \
        'SimpleReconGadget', 'ImageArraySplitGadget', 'ex:ExtractGadget'])
##        'SimpleReconGadget', 'FatWaterGadget', 'ImageArraySplitGadget', \
##        'PhysioInterpolationGadget', 'ex:ExtractGadget'])
        
    # ExtractGadget defines which type of image should be returned:
    # none      0
    # magnitude 1
    # real      2
    # imag      4
    # phase     8
    # in this example '5' returns both magnitude and imaginary part
##    recon.set_gadget_property('ex', 'extract_mask', 5)
    recon.set_gadget_property('ex', 'extract_magnitude', True)
    recon.set_gadget_property('ex', 'extract_imag', True)
    
    # provide raw k-space data as input
    recon.set_input(acq_data)
    
    # perform reconstruction
    recon.process()
    
    # retrieve reconstructed image data
    image_data = recon.get_output()

    # show reconstructed image data
    for im in range(image_data.number()):
        image = image_data.image(im)
        # image types   series
        # magnitude 1       0
        # phase     2    3000
        # real      3    1000
        # imag      4    2000
        im_type = image.image_type()
        im_series = image.image_series_index()
        print('image: %d, type: %d, series: %d' % (im, im_type, im_series))
    image_data.show(title = 'Images magnitude and imaginary part')

    if output_file is not None:
        # write images to a new group in args.output
        # named after the current date and time
        time_str = time.asctime()
        print('writing to %s' % output_file)
        image_data.write(output_file) #, time_str)
Ejemplo n.º 3
0
def main():

    # locate the input data
    input_file = existing_filepath(data_path, data_file)
    acq_data = AcquisitionData(input_file)

    if algorithm == 'SimpleReconGadget':
        extra_gadgets = [algorithm]
    else:
        extra_gadgets = [algorithm, 'GenericReconFieldOfViewAdjustmentGadget']

    # create reconstruction object
    # Rather than using a predefined image reconstruction object, here a new
    # image reconstruction object is created by concatinating multiple gadgets
    # (for more information on Gadgetron and its gadgets please see:
    # https://github.com/gadgetron/.).
    # Parameters for individual gadgets can be defined either during the
    # creation of the reconstruction object:
    #   e.g. AcquisitionAccumulateTriggerGadget(trigger_dimension=repetition)
    # or by giving a gadget a label (cf. label ex: for the last gadget)
    # and using set_gadget_property(label, propery, value).
    # The gadgets will be concatenated and will be executed as soon as
    # process() is called.
    recon_gadgets = ['NoiseAdjustGadget',
        'AsymmetricEchoAdjustROGadget',
        'RemoveROOversamplingGadget',
        'AcquisitionAccumulateTriggerGadget(trigger_dimension=repetition)',
        'BucketToBufferGadget(split_slices=true, verbose=false)'] \
        + extra_gadgets + \
        ['ImageArraySplitGadget',
        'ex:ExtractGadget'
        ]

    recon = Reconstructor(recon_gadgets)

    # ExtractGadget defines which type of image should be returned:
    # none      0
    # magnitude 1
    # real      2
    # imag      4
    # phase     8
    # in this example '5' returns both magnitude and imaginary part
    ##    recon.set_gadget_property('ex', 'extract_mask', 5)
    # === THE ABOVE IS OBSOLETE, NOW SHOULD USE ===>
    if type_to_save == 'mag' or type_to_save == 'all':
        recon.set_gadget_property('ex', 'extract_magnitude', True)
    if type_to_save == 'imag' or type_to_save == 'all':
        recon.set_gadget_property('ex', 'extract_imag', True)

    # provide raw k-space data as input
    recon.set_input(acq_data)

    # optionally set Gadgetron server host and port
    recon.set_host('localhost')
    # On VM you can try a port other than the default 9002, e.g. 9003, by taking
    # the following steps:
    # 1) in ~/devel/install/share/gadgetron/config/gadgetron.xml replace
    #    <port>9002</port> with <port>9003</port>
    # 2) go to Settings->Network->Advanced->Port Forwarding and add new rule
    #    (click on green + in the upper right corner) with Host and Guest ports
    #    set to 9003
    # 3) uncomment the next line
    #recon.set_port('9003')
    # Note: each gadget chain can run on a different VM - to try, start two VMs
    # and do the above steps 1 and 2 on one of them, then add
    # recon.set_port('9003') before recon.process in grappa_detail.py
    # (where preprocessing will still run on default port 9002).

    # perform reconstruction
    recon.process()

    # retrieve reconstructed image data
    image_data = recon.get_output()

    # show reconstructed image data
    if show_plot:
        for im in range(image_data.number()):
            image = image_data.image(im)
            # image types   series
            # magnitude 1       0
            # phase     2    3000
            # real      3    1000
            # imag      4    2000
            im_type = image.image_type()
            im_series = image.image_series_index()
            print('image: %d, type: %d, series: %d' % (im, im_type, im_series))
        image_data.show(title='Images magnitude and imaginary part')

    if output_file is not None:
        filename = output_file
        i = filename.find('.')
        if i < 0:
            ext = 'h5'
        else:
            ext = filename[i + 1:]
            filename = filename[:i]
        print('writing to %s' % (filename + '.' + ext))
        image_data.write(filename, ext=ext)
Ejemplo n.º 4
0
def test_main(rec=False, verb=False, throw=True):
    datafile = RE_PYEXT.sub(".txt", __file__)
    test = pTest(datafile, rec, throw=throw)
    test.verbose = verb

    msg_red = MessageRedirector()

    for scheme in ("file", "memory"):
        AcquisitionData.set_storage_scheme(scheme)

        data_path = petmr_data_path('pet')
        raw_data_file = existing_filepath(data_path,
                                          'my_forward_projection.hs')
        acq_data = AcquisitionData(raw_data_file)

        if verb:
            print('Checking images algebra:')
        image_data = acq_data.create_uniform_image(1.0)
        dims = image_data.dimensions()
        # N number of elements in the array
        N = 1
        for i, el in enumerate(dims):
            N *= el

        # 1 test sum: N * 1 / N = 1
        test.check(image_data.sum() / N)
        # test algebra 2 to 5
        # 2 DataContainer add (2+1) = 3
        # image_data = acq_data.create_uniform_image(1.0)
        b = acq_data.create_uniform_image(2.0)
        c = b + image_data
        test.check(c.sum() / N)
        # 3 DataContainer subtract 1 - (2) = -1
        image_data = acq_data.create_uniform_image(1.0)
        b = acq_data.create_uniform_image(2.0)
        c = image_data - b
        test.check(c.sum() / N)
        # 4 DataContainer multiply ( 2 * 1 ) = 2
        c = b * image_data
        test.check(c.sum() / N)
        # 5 DataContainer divide (1 / 2) = 0.5
        c = image_data.divide(b)
        test.check(c.sum() / N)
        # 6 power
        b = 1.5 * image_data
        c = b.power(0.5)
        test.check(c.sum() / N)
        # 7 maximum
        test.check(c.maximum(b).sum() / N)
        # 8 sign
        b = -1 * image_data
        test.check(b.sign().sum() / N)
        # 9 abs
        test.check(b.abs().sum() / N)
        # 10 sqrt
        b = 1.5 * image_data
        c = b.sqrt()
        test.check(c.sum() / N)
        # inline algebra
        # 11 inline add [1.5] + [1] = [2.5]
        b = acq_data.create_uniform_image(1.5)
        b += image_data
        test.check(b.sum() / N)
        # 12 inline subtract [1.5] - [1]
        b = acq_data.create_uniform_image(1.5)
        b -= image_data
        test.check(b.sum() / N)
        # 13 inline multiply
        b = acq_data.create_uniform_image(1.8)
        b *= 2.5
        # b = b.imul(2.5)
        test.check(b.sum() / N)
        # 14 inline divide
        b = acq_data.create_uniform_image(1.5)
        b /= 3
        test.check(b.sum() / N)

    return test.failed, test.ntest
Ejemplo n.º 5
0
    """Check file exists, else throw error."""
    if not path.isfile(filename):
        raise error('File not found: %s' % filename)


# process command-line options
data_path = args['--path']
if data_path is None:
    # default to data/examples/PET/mMR
    # Note: seem to need / even on Windows
    #data_path = os.path.join(examples_data_path('PET'), 'mMR')
    data_path = examples_data_path('PET') + '/mMR'
print('Finding files in %s' % data_path)

# Sinogram. if sino not found, get the one in the example data
sino_file = existing_filepath(data_path, args['--sino'])

# Attenuation - image
attn_im_file = existing_filepath(data_path, args['--attn'])

# Norm - ECAT8
norm_e8_file = existing_filepath(data_path, args['--norm'])

# Attn transformation
trans = args['--trans']
if trans:
    check_file_exists(trans)
trans_type = args['--trans_type']

# Output file
outp_file = args['--outp']