예제 #1
0
javabridge.start_vm(class_path=bioformats.JARS)

#path_to_data = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', '..', 'Daten', '24h', 'untreated'))
path_to_data = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', '..', '..', 'Daten2'))
interpolator = 'bspline'

for directory in os.listdir(path_to_data):
    data_dir = os.path.join(path_to_data, directory)
    if os.path.exists(data_dir):
        for filename in os.listdir(data_dir):
            if filename.endswith('.tif'):
                path_to_tif = os.path.join(data_dir, filename)
                print('Processing image: ', path_to_tif)
                
                # Get a numpy array from the tif stack with the dimension
                meta_data, raw_data = bfio.get_tif_stack(filepath=path_to_tif, series=0, depth='z', return_dim_order='XYZC') # XYZC
                
                # Transpose the numpy array from XYZC to CZYX for the use with SimpleITK
                raw_data = np.transpose(raw_data, axes=[3,2,1,0]) # CZYX
                
                # Extract the channel -> make for each channel
                raw_data = raw_data[0,:,:,:]
                
                # Make a SimpleITK out of the numpy array and set its metadata
                image = sitk.GetImageFromArray(raw_data, isVector=False) # XYZ
                image.SetOrigin([0.0, 0.0, 0.0])
                image.SetDirection(np.identity(3, dtype=np.double).flatten().tolist())
                image.SetSpacing((meta_data.get('physical_size_x'), 
                                  meta_data.get('physical_size_y'), 
                                  meta_data.get('physical_size_z')))
                #print(image.GetOrigin())
예제 #2
0
import bioformats
import SimpleITK as sitk
import numpy as np
import matplotlib.pyplot as plt
import nrrd
from tools import image_io as bfio

# Start the Java VM
javabridge.start_vm(class_path=bioformats.JARS)

filepath = 'test_data/Nucleisegmentedfill.tif'
depth = 't'

# Get a numpy array from the tif stack with the dimension
meta_data, raw_data = bfio.get_tif_stack(filepath=filepath,
                                         series=0,
                                         depth=depth,
                                         return_dim_order='XYZC')  # XYZ

# Extract the channel
raw_data = raw_data[:, :, :, 0]

# Transpose the numpy array from XYZC to CZYX for the use with SimpleITK
raw_data = np.transpose(raw_data, axes=[2, 1, 0])  # ZYX

# Make a SimpleITK out of the numpy array
image = sitk.GetImageFromArray(raw_data, isVector=False)  # XYZ
print('Dimension: ', image.GetDimension())
print('Width: ', image.GetWidth())
print('Height: ', image.GetHeight())
print('Depth: ', image.GetDepth())
print('XYZ: ', image.GetSize())
예제 #3
0
#path_to_data = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', '..', 'Daten', '24h', 'untreated'))
path_to_data = os.path.abspath(
    os.path.join(os.path.dirname(__file__), '..', '..', 'Daten'))

for directory in os.listdir(path_to_data):
    data_dir = os.path.join(path_to_data, directory, 'untreated')
    if os.path.exists(data_dir):
        for item in os.listdir(data_dir):
            if item.endswith('.tif'):
                tif_name = os.path.splitext(item)
                path_to_tif = os.path.join(data_dir, item)
                path_to_nrrd = os.path.join(data_dir, tif_name[0] + ".nrrd")
                print('Processing image: ', path_to_tif)
                orig_meta_data, orig_raw_data = bfio.get_tif_stack(
                    filepath=path_to_tif,
                    series=0,
                    depth='z',
                    return_dim_order='XYZC')  # XYZC
                own_raw_data, own_meta_data = nrrd.read(path_to_nrrd)
                #print('Original z: ', orig_raw_data.shape[2], 'Own z: ', own_raw_data.shape[2])
            abspath = os.path.join(data_dir, item)
            if (os.path.isdir(abspath)):
                tiffile = os.path.splitext(path_to_tif)
                tiffile = tiffile[0].split('\\')
                tiffile = tiffile[-1]
                if (tiffile in abspath):
                    path_to_original_stack = os.path.join(
                        abspath, 'OriginalStack.tif')
                    #print('Correspondig OpenSegSPIM data: ', path_to_original_stack)
                    oss_meta_data, oss_raw_data = bfio.get_tif_stack(
                        filepath=path_to_original_stack,
예제 #4
0
sys.path.append("..")
import javabridge
import bioformats
import SimpleITK as sitk
import numpy as np
import matplotlib.pyplot as plt
import nrrd
from tools import image_io as bfio

# Start the Java VM
javabridge.start_vm(class_path=bioformats.JARS)

# Get a numpy array from the tif stack with the dimension
meta_data, raw_data = bfio.get_tif_stack(
    filepath='test_data/test_nucleid_1ch.tif',
    series=0,
    depth='z',
    return_dim_order='XYZC')  # XYZC

# Write the data without header to nrrd-file and view it in Fiji
# -> the z-axis is much shorter
nrrd.write('export\test_nrrd.nrrd',
           data=raw_data,
           header=None,
           index_order='F')

# Transpose the numpy array from XYZC to CZYX for the use with SimpleITK
raw_data = np.transpose(raw_data, axes=[3, 2, 1, 0])  # CZYX

# Extract the channel
raw_data = raw_data[0, :, :, :]
    print(directory)
    if directory == '24h' or directory == '48h' or directory == '72h':
        print('###########################################################')
        cultivation_period = directory
        data_dir = os.path.join(path_to_data, directory, 'untreated')
        if os.path.exists(data_dir):
            for filename in os.listdir(data_dir):
                if filename.endswith('.nrrd'):
                    spheroid_name = os.path.splitext(filename)[0]
                    print('Actual file: ', spheroid_name)

                    # Read the original data
                    tif_file = os.path.join(data_dir, spheroid_name + '.tif')
                    tif_header, tif_data = bfio.get_tif_stack(
                        filepath=tif_file,
                        series=0,
                        depth='z',
                        return_dim_order='XYZC')  # XYZC
                    tif_data = tif_data[:, :, :, 0]
                    tif_data = np.transpose(tif_data, axes=(2, 1, 0))  #ZYX
                    print('TIF Dimension: ', tif_data.shape)

                    # Read the isotropic data
                    nrrd_file = os.path.join(data_dir, spheroid_name + '.nrrd')
                    nrrd_data, nrrd_header = nrrd.read(nrrd_file)
                    nrrd_data = np.transpose(nrrd_data, axes=(2, 1, 0))  #ZYX
                    print('NRRD Dimension: ', nrrd_data.shape)

                    # Save the dimensions in a table
                    table.append([
                        cultivation_period, spheroid_name, tif_data.shape[0:3],
                for seg_file in seg_files:
                    if spheroid_name in seg_file and 'NucleiBinary' in seg_file and seg_file.endswith(
                            '.tif'):
                        spheroid_file = os.path.abspath(spheroid_file)
                        spheroid_dir = os.path.abspath(spheroid_dir)
                        seg_file = os.path.join(spheroid_dir, subdir2,
                                                seg_file)
                        seg_filename = os.path.splitext(seg_file)[0]
                        print('Corresponding Segmentation: ', seg_file)

                        # Load the Spheroid and corresponding segmentation
                        spheroid_data, spheroid_header = nrrd.read(
                            spheroid_file)
                        segmentation_meta_data, segmentation_data = bfio.get_tif_stack(
                            filepath=seg_file,
                            series=0,
                            depth='t',
                            return_dim_order='XYZC')  # XYZC

                        segmentation_data = segmentation_data[:, :, :, 0]
                        segmentation_data = np.transpose(segmentation_data,
                                                         axes=(2, 1, 0))  # ZYX

                        # Label the segmentations
                        labelled_segmentation_data = cc3d.connected_components(
                            segmentation_data, connectivity=6)

                        labelled_segmentation_data = np.transpose(
                            labelled_segmentation_data,
                            axes=(2, 1, 0)).astype(np.uint16)  # XYZ
예제 #7
0
import sys
sys.path.append("..")
import javabridge
import bioformats
import SimpleITK as sitk
import numpy as np
import matplotlib.pyplot as plt
import nrrd
from tools import image_io as bfio

# Start the Java VM
javabridge.start_vm(class_path=bioformats.JARS)

# Get a numpy array from the tif stack with the dimension
meta_data, raw_data = bfio.get_tif_stack(filepath='labeling_test.tif',
                                         series=0,
                                         depth='z',
                                         return_dim_order='XYZC')  # YXZ

# Extract the channel
raw_data = raw_data[:, :, :, 0]

# Plot the image stack through the x-Axis (side view)
for x in range(raw_data.shape[0]):
    raw_slice = raw_data[x, :, :]
    plt.figure()
    plt.imshow(raw_slice)

# Plot the image stack through the y-Axis (frontal view)
for y in range(raw_data.shape[1]):
    raw_slice = raw_data[:, y, :]
    plt.figure()