analysis.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:growth-profiler-align 作者: biosustain 项目源码 文件源码
def analyze_image(args):
    """Analyze all wells from all trays in one image."""
    filename, config = args
    LOGGER.debug(filename)
    rows = config["rows"]
    columns = config["columns"]
    well_names = config["well_names"]

    name = splitext(basename(filename))[0]
    if config["parse_dates"]:
        try:
            index = convert_to_datetime(fix_date(name))
        except ValueError as err:
            return {"error": str(err), "filename": filename}
    else:
        index = name

    try:
        image = rgb2grey(imread(filename))
    except OSError as err:
        return {"error": str(err), "filename": filename}

    plate_images = cut_image(image)

    data = dict()

    for i, (plate_name, plate_image) in enumerate(
            zip(config["plate_names"], plate_images)):
        plate = data[plate_name] = dict()
        plate[config["index_name"]] = index
        if i // 3 == 0:
            calibration_plate = config["left_image"]
            positions = config["left_positions"]
        else:
            calibration_plate = config["right_image"]
            positions = config["right_positions"]

        try:
            edge_image = canny(plate_image, CANNY_SIGMA)
            offset = align_plates(edge_image, calibration_plate)

            # Add the offset to get the well centers in the analyte plate
            well_centers = generate_well_centers(
                np.array(positions) + offset, config["plate_size"], rows,
                columns)
            assert len(well_centers) == rows * columns

            plate_image /= (1 - plate_image + float_info.epsilon)

            well_intensities = [find_well_intensity(plate_image, center)
                                for center in well_centers]

            for well, intensity in zip(well_names, well_intensities):
                plate[well] = intensity
        except (AttributeError, IndexError) as err:
            return {"error": str(err), "filename": filename}

    return data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号