Ejemplo n.º 1
0
def main(name, arguments):
    parser.prog = name
    options, args = parser.parse_args(arguments)
    args = cli_tools.glob_args(args)
    if len(args) == 0:
        raise ValueError('Some contour files must be specified!')
    filenames = [path.path(arg) for arg in args]
    contours = simple_interface.load_contours(filenames, show_progress = options.show_progress)
    if options.first_point is not None:
        options.first_point -= 1
    if options.scale is not None or options.rotate is not None or options.units is not None or options.first_point is not None:
        in_radians = False
        if options.units is not None and options.units.lower() in ('um', 'micron', 'microns'):
            options.units = '\N{MICRO SIGN}m'
        contours = simple_interface.transform_contours(contours, options.scale, options.rotate, in_radians, 
            options.units, options.first_point, options.show_progress, title = 'Modifying Contours')
    if options.weights is not None:
        contours = simple_interface.reweight_landmarks(contours, options.weights, options.show_progress)
        
    
    destination = path.path(options.destination)
    destination.makedirs_p()
    # note that with path objects, the '/' operator means 'join path components.'
    names = [destination / filename.name for filename in filenames]
    simple_interface.save_contours(contours, names, options.show_progress)
Ejemplo n.º 2
0
def main(name, arguments):
    parser.prog = name
    options, args = parser.parse_args(arguments)
    args = cli_tools.glob_args(args)
    if len(args) == 0:
        raise ValueError('Some contour files must be specified!')
    filenames = [path.path(arg) for arg in args]
    contours = simple_interface.load_contours(
        filenames, show_progress=options.show_progress)
    if options.reference is not None:
        reference = contour_class.from_file(options.reference)
        contours = simple_interface.align_contours_to(
            contours,
            reference,
            align_steps=options.alignment_steps,
            allow_reflection=options.allow_reflection,
            show_progress=options.show_progress)
    else:
        contours = simple_interface.align_contours(
            contours,
            options.alignment_steps,
            options.allow_reflection,
            max_iters=options.max_iterations,
            show_progress=options.show_progress)
    destination = path.path(options.destination)
    destination.makedirs_p()
    # note that with path objects, the '/' operator means 'join path components.'
    names = [destination / filename.name for filename in filenames]
    simple_interface.save_contours(contours, names, options.show_progress)
Ejemplo n.º 3
0
def main(name, arguments):
    parser.prog = name
    options, args = parser.parse_args(arguments)
    args = cli_tools.glob_args(args)
    if len(args) == 0:
        raise ValueError('Some contour and image files must be specified!')
    intensity_ranges = []
    for r in options.intensity_ranges:
        try:
            low, high = r
        except:
            low = high = r
        intensity_ranges.append([low, high])
    if options.weights is None or len(options.weights) == 0:
        options.weights = [0.5]
    elif len(options.weights) != 1 and len(options.weights) != len(intensity_ranges):
        raise optparse.OptionValueError("Either one or %d weights are required; %d sepcified."%(len(intensity_ranges), len(options.weights)))
    elif sum(options.weights) > 1:
        raise optparse.OptionValueError("The sum of the weights must be <= 1.")

    matches = match_files.match_contours_and_images(args, options.match_by_name, options.show_progress)
    contours, image_names, unmatched_contours, unmatched_image_names = matches
    filenames = [path.path(contour._filename) for contour in contours]
    contours = simple_interface.add_image_landmarks_to_contours(contours, image_names,
        intensity_ranges, options.weights, options.image_type, options.show_progress)
    destination = path.path(options.destination)
    destination.makedirs_p()
    # note that with path objects, the '/' operator means 'join path components.'
    names = [destination / filename.name for filename in filenames]
    simple_interface.save_contours(contours, names, options.show_progress)
Ejemplo n.º 4
0
def main(name, arguments):
    parser.prog = name
    options, args = parser.parse_args(arguments)
    args = cli_tools.glob_args(args)
    if len(args) == 0:
        raise ValueError('Some image files must be specified!')
    filenames = [path.path(arg) for arg in args]
    contours_groups = simple_interface.extract_contours(
        filenames, options.contour_value, options.min_area, options.max_area,
        options.show_progress)
    contours = []
    names = []
    destination = path.path(options.destination)
    destination.makedirs_p()
    for contour_group, image_name in zip(contours_groups, filenames):
        num_contours = len(contour_group)
        if num_contours == 1:
            contours.append(contour_group[0])
            # note that with path objects, the '/' operator means 'join path components.'
            names.append(destination / image_name.namebase + '.contour')
            contour_group[0]._filename = image_name.namebase
        else:
            width = len(str(num_contours))
            for i, contour in enumerate(contour_group):
                contours.append(contour)
                names.append(destination / image_name.namebase +
                             '-%.*d.contour' % (width, i + 1))
                contour._filename = image_name.namebase + '-%.*d' % (width,
                                                                     i + 1)
    if options.scale is not None:
        # if not rescaling, contours are already denominated in pixels, so do nothing.
        units = options.units
        if units.lower() in ('um', 'micron', 'microns'):
            units = '\N{MICRO SIGN}m'
        contours = simple_interface.transform_contours(
            contours,
            scale_factor=options.scale,
            units=units,
            show_progress=options.show_progress,
            title='Rescaling Contours')
    if options.resample:
        contours = simple_interface.resample_contours(contours,
                                                      options.resample_points,
                                                      options.smoothing_factor,
                                                      options.show_progress)
    simple_interface.save_contours(contours, names, options.show_progress)
Ejemplo n.º 5
0
def main(name, arguments):
    parser.prog = name
    options, args = parser.parse_args(arguments)
    args = cli_tools.glob_args(args)
    if len(args) == 0:
        raise ValueError('Some contour files must be specified!')
    filenames = [path.path(arg) for arg in args]
    contours = simple_interface.load_contours(filenames, show_progress = options.show_progress)
    if options.endpoints is None:
        endpoints = options.endpoint_method
    else:
        endpoints = options.endpoints
    contours = simple_interface.find_centerlines(contours, options.axis_points, endpoints, options.show_progress)
    destination = path.path(options.destination)
    destination.makedirs_p()
    # note that with path objects, the '/' operator means 'join path components.'
    names = [destination / filename.name for filename in filenames]
    simple_interface.save_contours(contours, names, options.show_progress)
Ejemplo n.º 6
0
def main(name, arguments):
    parser.prog = name
    options, args = parser.parse_args(arguments)
    args = cli_tools.glob_args(args)
    if len(args) == 0:
        raise ValueError('Some contour files must be specified!')
    filenames = [path.path(arg) for arg in args]
    contours = simple_interface.load_contours(filenames, show_progress = options.show_progress)
    if options.reference is not None:
        reference = contour_class.from_file(options.reference)
        contours = simple_interface.align_contours_to(contours, reference, align_steps=options.alignment_steps,
            allow_reflection=options.allow_reflection, show_progress=options.show_progress)
    else:
        contours = simple_interface.align_contours(contours, options.alignment_steps, options.allow_reflection,
            max_iters=options.max_iterations, show_progress = options.show_progress)
    destination = path.path(options.destination)
    destination.makedirs_p()
    # note that with path objects, the '/' operator means 'join path components.'
    names = [destination / filename.name for filename in filenames]
    simple_interface.save_contours(contours, names, options.show_progress)
Ejemplo n.º 7
0
def main(name, arguments):
    parser.prog = name
    options, args = parser.parse_args(arguments)
    args = cli_tools.glob_args(args)
    if len(args) == 0:
        raise ValueError('Some contour files must be specified!')
    filenames = [path.path(arg) for arg in args]
    contours = simple_interface.load_contours(
        filenames, show_progress=options.show_progress)
    if options.first_point is not None:
        options.first_point -= 1
    if options.scale is not None or options.rotate is not None or options.units is not None or options.first_point is not None:
        in_radians = False
        if options.units is not None and options.units.lower() in ('um',
                                                                   'micron',
                                                                   'microns'):
            options.units = u'\N{MICRO SIGN}m'
        contours = simple_interface.transform_contours(
            contours,
            options.scale,
            options.rotate,
            in_radians,
            options.units,
            options.first_point,
            options.show_progress,
            title='Modifying Contours')
    if options.weights is not None:
        contours = simple_interface.reweight_landmarks(contours,
                                                       options.weights,
                                                       options.show_progress)

    destination = path.path(options.destination)
    if not destination.exists():
        destination.makedirs()
    # note that with path objects, the '/' operator means 'join path components.'
    names = [destination / filename.name for filename in filenames]
    simple_interface.save_contours(contours, names, options.show_progress)
Ejemplo n.º 8
0
def main(name, arguments):
    parser.prog = name
    options, args = parser.parse_args(arguments)
    args = cli_tools.glob_args(args)
    if len(args) == 0:
        raise ValueError('Some contour and image files must be specified!')
    intensity_ranges = []
    for r in options.intensity_ranges:
        try:
            low, high = r
        except:
            low = high = r
        intensity_ranges.append([low, high])
    if options.weights is None or len(options.weights) == 0:
        options.weights = [0.5]
    elif len(options.weights) != 1 and len(
            options.weights) != len(intensity_ranges):
        raise optparse.OptionValueError(
            "Either one or %d weights are required; %d sepcified." %
            (len(intensity_ranges), len(options.weights)))
    elif sum(options.weights) > 1:
        raise optparse.OptionValueError("The sum of the weights must be <= 1.")

    matches = match_files.match_contours_and_images(args,
                                                    options.match_by_name,
                                                    options.show_progress)
    contours, image_names, unmatched_contours, unmatched_image_names = matches
    filenames = [path.path(contour._filename) for contour in contours]
    contours = simple_interface.add_image_landmarks_to_contours(
        contours, image_names, intensity_ranges, options.weights,
        options.image_type, options.show_progress)
    destination = path.path(options.destination)
    if not destination.exists():
        destination.makedirs()
    # note that with path objects, the '/' operator means 'join path components.'
    names = [destination / filename.name for filename in filenames]
    simple_interface.save_contours(contours, names, options.show_progress)
Ejemplo n.º 9
0
def main(name, arguments):
    parser.prog = name
    options, args = parser.parse_args(arguments)
    args = cli_tools.glob_args(args)
    if len(args) == 0:
        raise ValueError('Some image files must be specified!')
    filenames = [path.path(arg) for arg in args]
    contours_groups = simple_interface.extract_contours(filenames, options.contour_value, 
        options.min_area, options.max_area, options.show_progress)
    contours = []
    names = []
    destination = path.path(options.destination)
    destination.makedirs_p()
    for contour_group, image_name in zip(contours_groups, filenames):
        num_contours = len(contour_group)
        if num_contours == 1:
            contours.append(contour_group[0])
            # note that with path objects, the '/' operator means 'join path components.'
            names.append(destination / image_name.namebase + '.contour')
            contour_group[0]._filename = image_name.namebase
        else:
            width = len(str(num_contours))
            for i, contour in enumerate(contour_group):
                contours.append(contour)
                names.append(destination / image_name.namebase + '-%.*d.contour'%(width, i+1))
                contour._filename = image_name.namebase + '-%.*d'%(width, i+1)
    if options.scale is not None:
        # if not rescaling, contours are already denominated in pixels, so do nothing.
        units = options.units
        if units.lower() in ('um', 'micron', 'microns'):
            units = '\N{MICRO SIGN}m'
        contours = simple_interface.transform_contours(contours, scale_factor=options.scale, 
            units=units, show_progress=options.show_progress, title='Rescaling Contours')
    if options.resample:
        contours = simple_interface.resample_contours(contours, options.resample_points, options.smoothing_factor, options.show_progress)
    simple_interface.save_contours(contours, names, options.show_progress)