Exemple #1
0
    def test_read_as_AcquisitionData1(self):
        ag = AcquisitionGeometry.create_Parallel3D()
        ag.set_panel([10, 11])
        ag.set_angles([i for i in range(12)])
        ag.set_channels(3)
        print(ag.shape)
        # print (glob.glob(os.path.join(self.data_dir, '*')))
        reader = TIFFStackReader(file_name=self.data_dir)
        acq = reader.read_as_AcquisitionData(ag)

        np.testing.assert_array_equal(acq.as_array(), self.data.as_array())
Exemple #2
0
    def test_read_as_AcquisitionData2(self):
        # with this data will be scrambled but reshape is possible
        ag = AcquisitionGeometry.create_Parallel3D()
        ag.set_panel([11, 10])
        ag.set_angles([i for i in range(12)])
        ag.set_channels(3)

        reader = TIFFStackReader(file_name=self.data_dir)
        acq = reader.read_as_AcquisitionData(ag)

        np.testing.assert_array_equal(acq.as_array().flatten(),
                                      self.data.as_array().flatten())
Exemple #3
0
    def test_read_as_ImageData_Exceptions(self):
        igs = [ImageGeometry(10, 11, 12, channels=5)]
        igs.append(ImageGeometry(12, 32))
        reader = TIFFStackReader(file_name=self.data_dir)

        for geom in igs:
            try:
                img = reader.read_as_ImageData(geom)
                assert False
            except ValueError as ve:
                print(ve)
                assert True
Exemple #4
0
    def test_read_as_AcquisitionData_Exceptions1(self):

        ag = AcquisitionGeometry.create_Parallel3D()
        ag.set_panel([11, 12])
        ag.set_angles([i for i in range(12)])
        ag.set_channels(3)
        reader = TIFFStackReader(file_name=self.data_dir)
        try:
            acq = reader.read_as_AcquisitionData(ag)
            assert False
        except ValueError as ve:
            print(ve)
            assert True
Exemple #5
0
    def test_read_as_AcquisitionData_Exceptions2(self):

        ag = AcquisitionGeometry.create_Parallel3D()
        ag.set_panel([11, 12])
        ag.set_angles([i for i in range(12)])
        ag.set_channels(3)
        reader = TIFFStackReader(file_name=self.data_dir)

        try:

            class Fake(object):
                pass

            fake = Fake()
            fake.shape = (36, 11, 10)
            acq = reader.read_as_ImageData(fake)
            assert False
        except TypeError as te:
            print(te)
            assert True
Exemple #6
0
    def test_read_as_ImageData1(self):
        reader = TIFFStackReader(file_name=self.data_dir)

        img = reader.read_as_ImageData(self.ig)
        np.testing.assert_array_equal(img.as_array(), self.data.as_array())
Exemple #7
0
 def test_read1(self):
     data = self.data
     reader = TIFFStackReader(file_name=self.data_dir)
     read = reader.read()
     np.testing.assert_array_equal(read.flatten(),
                                   data.as_array().flatten())
Exemple #8
0

if __name__ == '__main__':
    ig = ImageGeometry(10, 11, 12, channels=3)

    data = ig.allocate(0)
    arr = data.as_array()
    k = 0
    for i in range(data.shape[0]):
        for j in range(data.shape[1]):
            arr[i][j] += k
            k += 1
    data.fill(arr)
    os.mkdir("test_tiff")
    cwd = os.getcwd()
    fname = os.path.join(cwd, 'test_tiff', 'myfile.tif')
    data_dir = os.path.dirname(fname)
    writer = TIFFWriter(data=data, file_name=fname, counter_offset=0)
    writer.write()

    ag = AcquisitionGeometry.create_Parallel3D()
    ag.set_panel([10, 11])
    ag.set_angles([i for i in range(12)])
    ag.set_channels(3)
    print(ag.shape)
    print(glob.glob(os.path.join(data_dir, '*')))
    reader = TIFFStackReader(file_name=os.path.dirname(fname))
    acq = reader.read_as_AcquisitionData(ag)

    print(type(acq), type(data))
    np.testing.assert_array_equal(acq.as_array(), data.as_array())
Exemple #9
0
    path = "/mnt/data/CCPi/Dataset/SophiaBeads_64_averaged/CentreSlice"

    # Create a 2D fan beam Geometry

    source_position=(0, -80.6392412185669)
    detector_position=(0, 1007.006 - source_position[1])
    angles = np.asarray([- 5.71428571428571 * i for i in range(63)], dtype=np.float32) * np.pi / 180.
    panel = 2000
    panel_pixel_size = 0.2

    ag_cs =  AcquisitionGeometry.create_Cone2D(source_position, detector_position)\
                                .set_angles(angles, angle_unit='radian')\
                                .set_panel(panel, pixel_size=panel_pixel_size, origin='top-right')

    #%%
    reader = TIFFStackReader()
    reader.set_up(file_name=os.path.join(path, 'Sinograms', 'SophiaBeads_64_averaged_0001.tif'))
    data = reader.read_as_AcquisitionData(ag_cs)

    white_level = 60000.0

    data_raw = data.subset(dimensions=['angle','horizontal'])
    data_raw = data / white_level

    # negative log
    ldata = data_raw.log()
    ldata *= -1

    shift_mm = 0.0024

Exemple #10
0
from cil.io import TIFFStackReader

import numpy as np
import matplotlib.pyplot as plt
import math
import os

#%% read in all Tiff stack from directory
path_common = '/mnt/data/CCPi/LegoLaminography'
path = 'Lego_Lamino30deg_XTH/'

bins = 2
roi = {'axis_1': (None, None, bins), 'axis_2': (None, None, bins)}

reader = TIFFStackReader(file_name=os.path.join(path_common, path), roi=roi)
data = reader.read()

#%% Read in the flat-field and dark-field radiographs and apply shading correction to the data
tiffs = [
    os.path.join(path_common,
                 'Lego_Lamino30deg_ShadingCorrection_XTH/Dark_80kV85uA.tif'),
    os.path.join(path_common,
                 'Lego_Lamino30deg_ShadingCorrection_XTH/Flat_80kV85uA.tif')
]

reader = TIFFStackReader(file_name=tiffs, roi=roi)
SC = reader.read()
data = (data - SC[0]) / (SC[1] - SC[0])

#%% set up the geometry of the AcquisitionData
Exemple #11
0
#%%
# save output to TIFF and NeXuS
from cil.io import TIFFWriter

path = os.path.abspath('/home/edo/scratch/Dataset/')
out_file = os.path.join(path, 'edo', 'recon')
writer = TIFFWriter(data=recon, file_name=out_file)
writer.write()

#%%
from cil.io import TIFFStackReader

path = os.path.abspath('/home/edo/scratch/Dataset/')
fname = os.path.join(path, 'edo')
treader = TIFFStackReader()
treader.set_up(file_name=fname)
# treader.read()

#%%
recon = treader.read_as_ImageData(ig)
#%%
from cil.utilities.jupyter import islicer

islicer(recon, direction='vertical', cmap='inferno', origin='upper-right')

#%%
from cil.io import NikonDataReader

reader = NikonDataReader()
path = os.path.abspath('/home/edo/scratch/Dataset/')