コード例 #1
0
ファイル: czi_convert.py プロジェクト: gcerutti/SamMaps
# -- List of channel names:
channel_names = args.channel_names
print "Got following list of channel names as input: {}".format(channel_names)

# -- CZI data ordering pattern:
pattern = args.pattern

# -- Force overwrite existing file:
force =  args.force
if force:
    print "WARNING: any existing image will be overwritten!"
else:
    print "Existing images will be kept!"

# - Loading the CZI to convert:
czi_im = read_image(czi_fname, channel_names, pattern)
nb_ch = len(czi_im)

# -- Restricted list of channel to convert:
out_channels = args.out_channels
if out_channels == "":
    print "All {} channels will be extracted".format(nb_ch)
    out_channels = channel_names
else:
    print "Only the following channels will be extracted: '{}'".format(out_channels)

# -- Make the base filename to output (channel name & exrtension added later!)
output_fname =  args.output_fname
if output_fname == "":
    output_fname = splitext(czi_fname)[0]
print "Base filename used to export channels is: '{}'".format(output_fname)
コード例 #2
0
out_trsf_fnames = []  # list of transformation matrix filenames
for t_float, t_ref in zip(sorted_time_steps[:-1], sorted_time_steps[1:]):
    i_float = time2index[t_float]
    i_ref = time2index[t_ref]
    print "\n\n# -- Blockmatching registration t{}->t{}!".format(i_float, i_ref)
    # - Get the intensity image filenames corresponding to `t_ref` & `t_float`:
    ref_img_path, ref_img_fname = split(indexed_img_fnames[i_ref])
    float_img_path, float_img_fname = split(indexed_img_fnames[i_float])
    # - Defines the transformation matrix filename (output):
    out_trsf_fname = get_res_trsf_fname(float_img_fname, t_ref, t_float, trsf_type)
    # -- Add it to the list of transformation matrix filenames:
    out_trsf_fnames.append(out_trsf_fname)
    # - Read the reference and floating images:
    print "\n - Reading floating image (t{},{}{}): '{}'...".format(i_float, t_float, time_unit, float_img_fname)
    float_img = read_image(join(float_img_path, float_img_fname))
    print "\n - Reading reference image (t{},{}{}): '{}'...".format(i_ref, t_ref, time_unit, ref_img_fname)
    ref_img = read_image(join(ref_img_path, ref_img_fname))
    if not exists(join(out_folder, out_trsf_fname)) or force:
        print "\nComputing {} blockmatching registration t{}->t{}!".format(trsf_type.upper(), i_float, i_ref)
        # - Blockmatching registration:
        out_trsf, _ = registration(float_img, ref_img, method=trsf_type, pyramid_lowest_level=py_ll)
        # -- Save the transformation matrix:
        print "--> Saving {} transformation file: '{}'".format(trsf_type.upper(), out_trsf_fname)
        save_trsf(out_trsf, out_folder + out_trsf_fname)
    elif write_cons_img or extra_im is not None or seg_im is not None:
        print "\nFound existing tranformation t{}->t{}!".format(i_float, i_ref)
        print "--> Reading {} transformation file: '{}'".format(trsf_type.upper(), out_trsf_fname)
        out_trsf = read_trsf(out_folder + out_trsf_fname)
    else:
        print "\nFound existing tranformation t{}->t{}!".format(i_float, i_ref)
コード例 #3
0
ファイル: crop_image.py プロジェクト: gcerutti/SamMaps
axis = ['x', 'y', 'z']
# -- output format:
ext = args.out_fmt
try:
    assert ext in POSS_FMT
except AssertionError:
    raise ValueError("Unknown format '{}', availables are: {}".format(
        ext, POSS_FMT))

# -- Check all images have same shape and voxelsize (otherwise you don't know what you are doing!)
shape_list = []
vxs_list = []
ndim_list = []
for im2crop_fname in im2crop_fnames:
    # TODO: would be nice to access ONLY the file header to get those info:
    im2crop = read_image(im2crop_fname)
    shape_list.append(im2crop.shape)
    vxs_list.append(im2crop.voxelsize)
    ndim_list.append(im2crop.ndim)

# - Check dimensionality:
ndim = ndim_list[0]
try:
    assert all([nd == ndim for nd in ndim_list])
except AssertionError:
    raise ValueError("Images do not have the same dimensionality!")

axis = axis[:ndim]
if ndim == 2:
    lower_bounds = [x_min, y_min]
    upper_bounds = [x_max, y_max]
コード例 #4
0
output_path = args.output_path

force = args.force
if force:
    print "WARNING: any existing segmentation image will be overwritten!"
else:
    print "Existing segmentation will be kept!"

if output_fname:
    seg_img_fname = output_fname
else:
    seg_img_fname = segmentation_fname(scf_name, h_min, iso, equalize, stretch)

if output_path:
    assert exists(output_path)
    seg_img_fname = join(output_path, split(seg_img_fname)[1])

if exists(seg_img_fname) and not force:
    print "Found existing segmentation file: {}".format(seg_img_fname)
    print "ABORT!"
else:
    im2seg = read_image(scf_name)
    if substract_inr != "":
        im2sub = read_image(substract_inr)
    else:
        im2sub = None
    seg_im = seg_pipe(im2seg, h_min, im2sub, iso, equalize, stretch, std_dev,
                      min_cell_volume, back_id)
    print "\n - Saving segmentation under '{}'".format(seg_img_fname)
    imsave(seg_img_fname, seg_im)
コード例 #5
0
ファイル: segmentation2stl.py プロジェクト: gcerutti/SamMaps
    SamMaps_dir = '/data/Meristems/Carlos/SamMaps/'
    dirname = "/data/Meristems/Carlos/PIN_maps/"
elif platform.uname()[1] == "calculus":
    SamMaps_dir = '/projects/SamMaps/scripts/SamMaps_git/'
    dirname = "/projects/SamMaps/"
else:
    raise ValueError("Unknown custom path to 'SamMaps' for this system...")
sys.path.append(SamMaps_dir+'/scripts/lib/')

from segmentation_pipeline import read_image
from nomenclature import splitext_zip
from openalea.cellcomplex.property_topomesh.utils.image_tools import image_to_vtk_polydata

# fname = '/data/Meristems/Bihai/20180523_WT_Ler_SD+LD_1/20180523 WT_Ler SD+LD_1#-T0-seg-iso-adpat_eq-h_min9.inr'
fname = '/data/Meristems/Carlos/PIN_maps/nuclei_images/qDII-PIN1-CLV3-PI-LD_E37_171113_sam07_t14/qDII-PIN1-CLV3-PI-LD_E37_171113_sam07_t14_PI_raw_segmented.inr.gz'
im = read_image(fname)

import tissue_printer
reload(tissue_printer)
from tissue_printer import *


# - Performs vtkDiscreteMarchingCubes on labelled image (with all labels!)
# dmc = vtk_dmc(im, mesh_fineness=3.0)
# write_stl(bin_dmc, splitext_zip(fname)[0]+'.stl')


# - Performs vtkDiscreteMarchingCubes on inside/outside masked image:
back_id = 1
# -- Convert the labelled image into inside/outside mask image:
mask = np.array(im != back_id, dtype="uint8")
コード例 #6
0
    '--bounding_box',
    type=int,
    nargs='+',
    default=None,
    help=
    "if given, used to crop the image around these voxel coordinates, use '0' for the beginning and '-1' for the end"
)

args = parser.parse_args()

# - Variables definition from mandatory arguments parsing:
# -- Membrane labelling signal image:
memb_im_fname = args.membrane_im
print "\n\n# - Reading membrane labelling signal image file {}...".format(
    memb_im_fname)
memb_im = read_image(memb_im_fname)
print "Done."
# -- Membrane-targetted signal image:
sig_im_fname = args.signal_im
print "\n\n# - Reading membrane-targetted signal image file {}...".format(
    sig_im_fname)
sig_im = read_image(sig_im_fname)
print "Done."
# -- Segmented images:
seg_im_fname = args.segmented_im
print "\n\n# - Reading segmented image file {}...".format(seg_im_fname)
seg_im = read_image(seg_im_fname)
print "Done."

# - Variables definition from optional arguments parsing:
# -- Labels:
コード例 #7
0
# - Check if the result transformation files exists:
print ""
for f in seq_res_trsf_list:
    print "Existing tranformation file {}: {}\n".format(f, exists(f))

################################################################################
# - Computation:
################################################################################

# - Loading images:
list_img = []
print "\n# - Loading list of images to register:"
for n, img_fname in enumerate(list_img_fname):
    print "  - Time-point {}, reading image {}...".format(n, img_fname)
    im = read_image(img_fname)
    # print "  ---> Contrast stretching...".format(n, img_fname)
    # im = z_slice_contrast_stretch(im)
    list_img.append(im)

list_comp_trsf, list_res_img = [], []
# if not np.all([exists(f) for f in res_trsf_list]) or force:
if not np.all([exists(f) for f in seq_res_trsf_list]) or force:
    if not_sequence:
        list_comp_trsf, list_res_img = registration(
            list_img[0],
            list_img[1],
            method=trsf_type,
            pyramid_highest_level=py_hl,
            pyramid_lowest_level=py_ll)
        list_comp_trsf = [list_comp_trsf]
コード例 #8
0
except:
    raise ValueError("Negative distance provided!")
walls_min_area = args.walls_min_area
try:
    assert walls_min_area > 0.
except:
    raise ValueError("Negative minimal area!")
# -- Force overwritting of existing files:
force = args.force
if force:
    print "WARNING: any existing CSV files will be overwritten!"
else:
    print "Existing files will be kept."

print "\n\n# - Reading CZI intensity image file {}...".format(czi_fname)
czi_im = read_image(czi_fname, channel_names)
PIN_signal_im = czi_im[signal_ch_name]
PI_signal_im = czi_im[membrane_ch_name]
print "Done."

print "\n\n# - Reading segmented image file {}...".format(seg_img_fname)
seg_im = read_image(seg_img_fname)
print "Done."

min_cell_volume = args.cell_min_vol
if min_cell_volume is None:
    min_cell_volume = 0
max_cell_volume = args.cell_max_vol
if max_cell_volume is None:
    max_cell_volume = 0
if min_cell_volume > 0 or max_cell_volume > 0:
コード例 #9
0
output_fname = args.output_fname

force = args.force
if force:
    print "WARNING: any existing segmentation image will be overwritten!"
else:
    print "Existing segmentation will be kept!"

if output_fname != "":
    seg_img_fname = output_fname
else:
    seg_img_fname = segmentation_fname(czi_fname, h_min, args.iso,
                                       args.equalize, args.stretch)
print seg_img_fname

if exists(seg_img_fname) and not force:
    print "Found existing segmentation file: {}".format(seg_img_fname)
    print "ABORT!"
else:
    czi_im = read_image(czi_fname, channel_names)
    im2seg = czi_im[seg_ch_name]
    if substract_ch_name != "":
        im2sub = czi_im[substract_ch_name]
    else:
        im2sub = None
    seg_im = seg_pipe(im2seg, h_min, im2sub, args.iso, args.equalize,
                      args.stretch, args.std_dev, min_cell_volume,
                      args.back_id, args.to_8bits)
    print "\n - Saving segmentation under '{}'".format(seg_img_fname)
    imsave(seg_img_fname, seg_im)
コード例 #10
0
    type=int,
    default=None,
    help="if given, resampling factor used on segemented image")

# - Clear the world ???
if "world" in dir():
    world.clear()

args = parser.parse_args()
img_dict = {}
# - Variables definition from mandatory arguments parsing:
# -- Membrane labelling signal image:
memb_im_fname = args.membrane_im
print "\n\n# - Reading membrane labelling signal image file {}...".format(
    memb_im_fname)
img_dict[args.membrane_ch_name] = read_image(memb_im_fname)
print "Done."
# -- Membrane-targetted signal image:
sig_im_fname = args.signal_im
print "\n\n# - Reading membrane-targetted signal image file {}...".format(
    sig_im_fname)
img_dict[args.signal_ch_name] = read_image(sig_im_fname)
print "Done."
# -- Segmented images:
seg_im_fname = args.segmented_im
print "\n\n# - Reading segmented image file {}...".format(seg_im_fname)
seg_im = read_image(seg_im_fname)
print "Done."
# -- CSV filename:
csv_data = args.wall_quantif_csv