Beispiel #1
0
def setupCCPiGeometries(ig, ag, counter):
    Phantom_ccpi = ig.allocate(dimension_labels=[
        ImageGeometry.HORIZONTAL_X, ImageGeometry.HORIZONTAL_Y,
        ImageGeometry.VERTICAL
    ])

    voxel_per_pixel = 1
    angles = ag.angles
    geoms = pbalg.pb_setup_geometry_from_image(Phantom_ccpi.as_array(), angles,
                                               voxel_per_pixel)

    pg = AcquisitionGeometry(
        'parallel',
        '3D',
        angles,
        geoms['n_h'],
        1.0,
        geoms['n_v'],
        1.0  #2D in 3D is a slice 1 pixel thick
    )

    center_of_rotation = Phantom_ccpi.get_dimension_size('horizontal_x') / 2
    #ad = AcquisitionData(geometry=pg,dimension_labels=['angle','vertical','horizontal'])
    ad = pg.allocate(dimension_labels=[
        AcquisitionGeometry.ANGLE, AcquisitionGeometry.VERTICAL,
        AcquisitionGeometry.HORIZONTAL
    ])
    geoms_i = pbalg.pb_setup_geometry_from_acquisition(ad.as_array(), angles,
                                                       center_of_rotation,
                                                       voxel_per_pixel)

    counter += 1

    if counter < 4:
        print(geoms, geoms_i)
        if (not (geoms_i == geoms)):
            print("not equal and {} {} {}".format(counter,
                                                  geoms['output_volume_z'],
                                                  geoms_i['output_volume_z']))
            X = max(geoms['output_volume_x'], geoms_i['output_volume_x'])
            Y = max(geoms['output_volume_y'], geoms_i['output_volume_y'])
            Z = max(geoms['output_volume_z'], geoms_i['output_volume_z'])
            return setupCCPiGeometries(X, Y, Z, angles, counter)
        else:
            print("happy now {} {} {}".format(counter,
                                              geoms['output_volume_z'],
                                              geoms_i['output_volume_z']))

            return geoms
    else:
        return geoms_i
def setupCCPiGeometries(voxel_num_x, voxel_num_y, voxel_num_z, angles, counter):
    
    vg = ImageGeometry(voxel_num_x=voxel_num_x,voxel_num_y=voxel_num_y, voxel_num_z=voxel_num_z)
    Phantom_ccpi = ImageData(geometry=vg,
                        dimension_labels=['horizontal_x','horizontal_y','vertical'])
    #.subset(['horizontal_x','horizontal_y','vertical'])
    # ask the ccpi code what dimensions it would like
        
    voxel_per_pixel = 1
    geoms = pbalg.pb_setup_geometry_from_image(Phantom_ccpi.as_array(),
                                                angles,
                                                voxel_per_pixel )
    
    pg = AcquisitionGeometry('parallel',
                              '3D',
                              angles,
                              geoms['n_h'], 1.0,
                              geoms['n_v'], 1.0 #2D in 3D is a slice 1 pixel thick
                              )
    
    center_of_rotation = Phantom_ccpi.get_dimension_size('horizontal_x') / 2
    ad = AcquisitionData(geometry=pg,dimension_labels=['angle','vertical','horizontal'])
    geoms_i = pbalg.pb_setup_geometry_from_acquisition(ad.as_array(),
                                                angles,
                                                center_of_rotation,
                                                voxel_per_pixel )
    
    counter+=1
    
    if counter < 4:
        if (not ( geoms_i == geoms )):
            print ("not equal and {0}".format(counter))
            X = max(geoms['output_volume_x'], geoms_i['output_volume_x'])
            Y = max(geoms['output_volume_y'], geoms_i['output_volume_y'])
            Z = max(geoms['output_volume_z'], geoms_i['output_volume_z'])
            return setupCCPiGeometries(X,Y,Z,angles, counter)
        else:
            return geoms
    else:
        return geoms_i
    def process(self, out=None):
        projections = self.get_input()
        w = projections.get_dimension_size('horizontal')
        delta = w - 2 * self.center_of_rotation

        padded_width = int(numpy.ceil(abs(delta)) + w)
        delta_pix = padded_width - w

        voxel_per_pixel = 1
        geom = pbalg.pb_setup_geometry_from_acquisition(
            projections.as_array(), self.acquisition_geometry.angles,
            self.center_of_rotation, voxel_per_pixel)

        padded_geometry = self.acquisition_geometry.clone()

        padded_geometry.pixel_num_h = geom['n_h']
        padded_geometry.pixel_num_v = geom['n_v']

        delta_pix_h = padded_geometry.pixel_num_h - self.acquisition_geometry.pixel_num_h
        delta_pix_v = padded_geometry.pixel_num_v - self.acquisition_geometry.pixel_num_v

        if delta_pix_h == 0:
            delta_pix_h = delta_pix
            padded_geometry.pixel_num_h = padded_width
        #initialize a new AcquisitionData with values close to 0
        out = AcquisitionData(geometry=padded_geometry)
        out = out + self.pad_value

        #pad in the horizontal-vertical plane -> slice on angles
        if delta > 0:
            #pad left of middle
            command = "out.array["
            for i in range(out.number_of_dimensions):
                if out.dimension_labels[i] == 'horizontal':
                    value = '{0}:{1}'.format(delta_pix_h, delta_pix_h + w)
                    command = command + str(value)
                else:
                    if out.dimension_labels[i] == 'vertical':
                        value = '{0}:'.format(delta_pix_v)
                        command = command + str(value)
                    else:
                        command = command + ":"
                if i < out.number_of_dimensions - 1:
                    command = command + ','
            command = command + '] = projections.array'
            #print (command)
        else:
            #pad right of middle
            command = "out.array["
            for i in range(out.number_of_dimensions):
                if out.dimension_labels[i] == 'horizontal':
                    value = '{0}:{1}'.format(0, w)
                    command = command + str(value)
                else:
                    if out.dimension_labels[i] == 'vertical':
                        value = '{0}:'.format(delta_pix_v)
                        command = command + str(value)
                    else:
                        command = command + ":"
                if i < out.number_of_dimensions - 1:
                    command = command + ','
            command = command + '] = projections.array'
            #print (command)
            #cleaned = eval(command)
        exec(command)
        return out