コード例 #1
0
ファイル: factory.py プロジェクト: StrokaLab/JAnaP
    def __init__(self, project):
        self.__project_variant = project.get_variant()
        self.__project_dimensions = project.get_dimensions()
        self.__images_directory = project.get_input_image_directory()
        self.__waypoints_directory = project.get_artifacts_directory(
            "waypoints")

        self.jobs = cli.jobs.get_job_types()
        #{
        #    "trace": cli.jobs.trace.Trace(project),
        #    "imdata": cli.jobs.imdata.ImageData(project),
        #    "shapes": cli.jobs.shapes.Shapes(project),
        #    "classedge": cli.jobs.classify.ClassifyEdges(project),
        #    "jclass": cli.jobs.jclass.JunctionClassify(project),
        #    "jclasssum": cli.jobs.jclasssum.JunctionClassSummarize(project),
        #    "fastclass": cli.jobs.edgeseg.FastSegClassify(project),
        #}

        # Use this for an ordered list of the jobs in the chain
        job_keys = []
        priortized_jobs = sorted(self.jobs.values(), key=lambda x: x.priority)
        for pj in priortized_jobs:
            job_keys.append(pj.job_name)

        self.job_types = job_keys
コード例 #2
0
ファイル: projects.py プロジェクト: StrokaLab/JAnaP
def getProject(project_hash):
    import cells.images
    import cli.operations

    project = get_project(project_hash)

    project_name = get_project_name(project_hash)

    project_dto = {"hash": project_hash, "name": project_name}

    input_image_directory = project.get_input_image_directory()

    variant = project.get_variant()
    dimensions = project.get_dimensions()

    image_data = cells.images.get_image_collection(input_image_directory,
                                                   variant, dimensions)

    # Get input image count
    total_images = 0
    stain_image_counts = {}

    for image_data_row in image_data:
        file_name = image_data_row["file_name"]

        image_stain = None
        for test_stain in variant.get("values", []):
            if test_stain in file_name:
                stain_image_counts[test_stain] = stain_image_counts.get(
                    test_stain, 0) + 1
                image_stain = test_stain
                break

        if image_stain is None:
            stain_image_counts["None"] = stain_image_counts.get("None", 0) + 1

        total_images = total_images + 1

    # Task Data
    waypoint_tasks, waypoint_tasks_data = get_waypoint_tasks(project)

    # Cell Data
    cell_collection = cli.operations.get_cell_collection(project, image_data)

    project_data_dto = {
        "image_count": total_images,
        "variant_data": stain_image_counts,
        "task_data": waypoint_tasks_data,
        "cell_count": len(cell_collection)
    }

    print project.get_project_hash()

    return render_template('projects/overview.html',
                           project=project_dto,
                           project_data=project_data_dto)
コード例 #3
0
def get_waypoint_tasks(project):
    import cells.waypoints.seeding
    import cells.images

    input_image_directory = project.get_input_image_directory()
    variant = project.get_variant()
    dimensions = project.get_dimensions()

    image_data = cells.images.get_image_collection(input_image_directory,
                                                   variant, dimensions)

    counter = 0
    for image_data_row in image_data:
        if image_data_row.get("stain") == "TxRed":
            # print image_data_row
            counter += 1
            if counter > 5:
                break

    input_waypoints_directory = project.get_artifacts_directory("waypoints")

    waypoint_files = glob.glob(input_waypoints_directory + os.sep + "*")
    waypoint_tasks = cells.waypoints.seeding.get_waypoints_tasks(
        waypoint_files, image_data)

    # Calculate task status data
    waypoint_tasks_data = {}

    tasks_total = 0
    tasks_done = 0
    tasks_wip = 0
    tasks_open = 0
    tasks_progress = 0.0

    tasks_total = len(waypoint_tasks)

    for waypoint_task in waypoint_tasks:
        if waypoint_task.get("status") == "open":
            tasks_open = tasks_open + 1
        elif waypoint_task.get("status") == "in-progress":
            tasks_wip = tasks_wip + 1
        elif waypoint_task.get("status") == "complete":
            tasks_done = tasks_done + 1

    if tasks_total > 0:
        tasks_progress = round(100.0 * float(tasks_done) / tasks_total, 2)

    waypoint_tasks_data["total"] = tasks_total
    waypoint_tasks_data["done"] = tasks_done
    waypoint_tasks_data["wip"] = tasks_wip
    waypoint_tasks_data["open"] = tasks_open
    waypoint_tasks_data["progress"] = tasks_progress

    return waypoint_tasks, waypoint_tasks_data
コード例 #4
0
def getCachedWaypointImage(project, image_name):
    import cv2
    import cells.waypoints.seeding

    cache_root = os.path.join(app.static_folder, "tmp")
    image_cache = os.path.join(cache_root, "images")

    if not os.path.isdir(cache_root):
        os.makedirs(cache_root)
    if not os.path.isdir(image_cache):
        os.makedirs(image_cache)

    input_waypoints_directory = project.get_artifacts_directory("waypoints")

    working_file_name = image_name + ".tsv-working"
    working_file = os.path.join(input_waypoints_directory, working_file_name)

    if not os.path.isfile(working_file):
        return getCachedImage(project, image_name)

    image_file = os.path.join(project.get_input_image_directory(), image_name)
    task_image_name = "task-wp-" + image_name + ".png"

    working_temp_image_name = "temp-" + image_name
    working_temp_file = os.path.join(image_cache, working_temp_image_name)

    image = cv2.imread(image_file)

    image_waypoints = cells.waypoints.seeding.load_waypoints(working_file)

    for waypoints_row in image_waypoints:
        waypoints = waypoints_row.get("waypoints")

        for idx in range(0, len(waypoints)):
            r, c = waypoints[idx]

            r_next, c_next = waypoints[(idx + 1) % len(waypoints)]
            x, y = c, r
            x_next, y_next = c_next, r_next

            cv2.line(image, (x, y), (x_next, y_next), (244, 238, 66), 1)

    cv2.imwrite(working_temp_file, image)

    image = Image.open(working_temp_file)
    output_image = image.convert("RGB")
    output_image.save(image_cache + os.sep + task_image_name, "PNG")

    image_relative_url = "/static/tmp/images/" + task_image_name
    # Cache bust
    image_relative_url = image_relative_url + "?cachev=" + str(time.time())
    return image_relative_url
コード例 #5
0
def postGetPath():
    import cv2
    import numpy
    from skimage import graph

    import cells.images.filter

    project_hash = request.form['project_hash']
    project = get_project(project_hash)

    task_hash = request.form['task_hash']
    task_hash_decoded = base64.urlsafe_b64decode(task_hash.encode("ascii"))
    task_type = task_hash_decoded.split("::")[0]
    task_key = task_hash_decoded.split("::")[1]

    image_name = task_key
    image_file = os.path.join(project.get_input_image_directory(), image_name)

    point_1_x = int(request.form['point_1_x'])
    point_1_y = int(request.form['point_1_y'])
    point_2_x = int(request.form['point_2_x'])
    point_2_y = int(request.form['point_2_y'])

    start_r, start_c = point_1_y, point_1_x
    end_r, end_c = point_2_y, point_2_x

    start_point = point_1_y, point_1_x
    end_point = point_2_y, point_2_x

    input_image = cv2.imread(image_file)

    cost_image = cells.images.filter.generate_cost_image_perimeter(input_image)
    # image_intensity = cv2.cvtColor(input_image, cv2.COLOR_BGR2GRAY)

    #cost_image = image_intensity.copy()
    #cost_image = (numpy.max(cost_image) - cost_image)

    print start_point, end_point

    path_segment, cost = graph.route_through_array(cost_image, start_point,
                                                   end_point)

    path = []
    x_y_path = []

    for e in path_segment:
        path.append(e)
        x_y_path.append([e[1], e[0]])

    return jsonify(x_y_path)
コード例 #6
0
ファイル: projects.py プロジェクト: StrokaLab/JAnaP
def getSizedImage(project_hash, width, height, image_name):
    import cv2
    width, height = int(width), int(height)
    project = get_project(project_hash)
    input_image_directory = project.get_input_image_directory()

    image_path = os.path.join(input_image_directory, image_name)
    input_image = cv2.imread(image_path)

    resized_image = cv2.resize(input_image, (width, height))

    retval, buffer = cv2.imencode('.png', resized_image)

    response = make_response(buffer.tobytes())
    response.headers['Content-Type'] = 'image/png'

    return response
コード例 #7
0
def getCachedImage(project, image_name):
    cache_root = os.path.join(app.static_folder, "tmp")
    image_cache = os.path.join(cache_root, "images")

    if not os.path.isdir(cache_root):
        os.makedirs(cache_root)
    if not os.path.isdir(image_cache):
        os.makedirs(image_cache)

    image_file = os.path.join(project.get_input_image_directory(), image_name)
    cache_image_name = image_name + ".png"

    cache_image_file = os.path.join(image_cache, cache_image_name)

    if not os.path.isfile(cache_image_file):
        image = Image.open(image_file)
        output_image = image.convert("RGB")
        output_image.save(image_cache + os.sep + cache_image_name, "PNG")

    image_relative_url = "/static/tmp/images/" + cache_image_name
    return image_relative_url
コード例 #8
0
def getTask(project_hash, task_hash):
    if request.method == 'POST':
        return postTask(project_hash, task_hash)
    else:
        import cells.waypoints.seeding
        import cli.project
        import cv2

        project = get_project(project_hash)
        # waypoint_tasks, waypoint_tasks_data = getWaypointTasks(project)

        project_header = {"hash": project_hash}

        task_hash_decoded = base64.urlsafe_b64decode(task_hash.encode("ascii"))
        task_type = task_hash_decoded.split("::")[0]
        task_key = task_hash_decoded.split("::")[1]

        image_name = task_key

        # Load Image Data
        image_file = os.path.join(project.get_input_image_directory(),
                                  image_name)
        input_image = cv2.imread(image_file)
        height, width, channels = input_image.shape

        input_waypoints_directory = project.get_artifacts_directory(
            "waypoints")
        working_file_name = image_name + ".tsv-working"
        working_file = os.path.join(input_waypoints_directory,
                                    working_file_name)
        completed_file_name = image_name + ".tsv"
        completed_file = os.path.join(input_waypoints_directory,
                                      completed_file_name)

        task_status = "open"

        if os.path.isfile(working_file):
            task_status = "in-progress"
        elif os.path.isfile(completed_file):
            task_status = "complete"

        # Load waypoints
        if task_status == "complete":
            image_waypoints = cells.waypoints.seeding.load_waypoints(
                completed_file)
        elif task_status == "in-progress":
            image_waypoints = cells.waypoints.seeding.load_waypoints(
                working_file)
        else:
            image_waypoints = []

        row = 1
        for waypoints_row in image_waypoints:
            waypoints_row["row"] = row
            row += 1

        # Get png versions of images
        working_image_wp_url = getCachedWaypointImage_v2(
            input_image, image_waypoints, image_name)
        working_image_url = getCachedImage(project, image_name)

        view_type_parameter = request.args.get('vt')

        if view_type_parameter == "review":
            view_type = "review"
        else:
            view_type = "waypoints"

        task_data = {
            "hash": task_hash,
            "status": task_status,
            "image_name": task_key,
            "image_width": height,
            "image_height": width,
            "image_wp_url": working_image_wp_url,
            "image_url": working_image_url
        }

        return render_template('tasks/task.html',
                               project=project_header,
                               task=task_data,
                               image_url=working_image_url,
                               image_waypoints=image_waypoints,
                               view_type=view_type)
コード例 #9
0
ファイル: projects.py プロジェクト: StrokaLab/JAnaP
def getProjectProblems(project_hash):
    import cells.images

    project = get_project(project_hash)

    project_name = get_project_name(project_hash)

    project_dto = {"hash": project_hash, "name": project_name}

    problems = []

    input_image_directory = project.get_input_image_directory()

    variant = project.get_variant()
    dimensions = project.get_dimensions()

    if variant.get("name") is None or variant.get("name") == "":
        problems.append({
            "level":
            "info",
            "css":
            "info",
            "summary":
            "You have not configured a variant (stain) and values for this project"
        })

    image_data = cells.images.get_image_collection(input_image_directory,
                                                   variant, dimensions)

    # TODO: A variant value is not found in any images
    stain_image_counts = {}

    missing_variant_images = []

    for image_data_row in image_data:
        file_name = image_data_row["file_name"]

        image_stain = None
        for test_stain in variant.get("values", []):
            if test_stain in file_name:
                stain_image_counts[test_stain] = stain_image_counts.get(
                    test_stain, 0) + 1
                image_stain = test_stain
                break

        if image_stain is None:
            missing_variant_images.append(file_name)

    for variant_value in variant.get("values", []):
        if stain_image_counts.get(variant_value, 0) == 0:
            problems.append({
                "level":
                "warning",
                "css":
                "warning",
                "summary":
                "The variant/stain '%s' did not match any images." %
                variant_value
            })

    # Image has no variant
    for missing_variant_image in missing_variant_images:
        problems.append({
            "level":
            "warning",
            "css":
            "warning",
            "summary":
            "Image '%s' does not have a variant." % missing_variant_image
        })

    # Image has missing related variant image(s)
    for image_data_row in image_data:
        file_name = image_data_row["file_name"]

        image_stain = None
        for test_stain in variant.get("values", []):
            if test_stain in file_name:
                stain_image_counts[test_stain] = stain_image_counts.get(
                    test_stain, 0) + 1
                image_stain = test_stain
                break

        missing_variants = []
        if image_stain is not None:
            for variant_value in variant.get("values", []):
                related_file_name = file_name.replace(image_stain,
                                                      variant_value)
                related_file = os.path.join(input_image_directory,
                                            related_file_name)
                if not os.path.isfile(related_file):
                    missing_variants.append(variant_value)

        for missing_variant in missing_variants:
            if missing_variant == variant.get("primary_value"):
                problems.append({
                    "level":
                    "error",
                    "css":
                    "danger",
                    "summary":
                    "Missing variant with value '%s' for image '%s'. No output will be generated for this file."
                    % (missing_variant, file_name),
                })
            else:
                problems.append({
                    "level":
                    "warning",
                    "css":
                    "warning",
                    "summary":
                    "Missing variant with value '%s' for image '%s'." %
                    (missing_variant, file_name)
                })

    page_data = {"title": "", "active_nav_tab": "problems"}

    return render_template('projects/problems.html',
                           project=project_dto,
                           problems=problems,
                           page_data=page_data)
コード例 #10
0
ファイル: projects.py プロジェクト: StrokaLab/JAnaP
def getProjectDataSummary(project_hash):
    import cells.images
    import cli.operations

    project = get_project(project_hash)

    project_name = get_project_name(project_hash)

    project_dto = {"hash": project_hash, "name": project_name}

    input_image_directory = project.get_input_image_directory()

    variant = project.get_variant()

    dimensions = project.get_dimensions()

    image_data = cells.images.get_image_collection(input_image_directory,
                                                   variant, dimensions)

    # Get input image count
    total_images = 0
    variant_counts = {}

    for image_data_row in image_data:
        file_name = image_data_row["file_name"]

        image_stain = None
        for test_stain in variant.get("values", []):
            if test_stain in file_name:
                variant_counts[test_stain] = variant_counts.get(test_stain,
                                                                0) + 1
                image_stain = test_stain
                break

        if image_stain is None:
            variant_counts["None"] = variant_counts.get("None", 0) + 1

        total_images = total_images + 1

    dimension_counts = {}

    for key, value in dimensions.iteritems():
        dimension_counts[key] = {}

    for image_data_row in image_data:
        for key in dimensions.keys():
            dimension_value = image_data_row.get("dimensions", {}).get(key)
            dimension_counts[key][dimension_value] = \
                dimension_counts[key].get(dimension_value, 0) + 1

    # Get counts for cells
    cell_collection = cli.operations.get_cell_collection(project, image_data)

    cell_variant_counts = {}
    for key in variant_counts.keys():
        cell_variant_counts[key] = 0

    cell_dimension_counts = {}
    for key, value in dimensions.iteritems():
        cell_dimension_counts[key] = {}

    for cell_data_row in cell_collection:
        variant_value = cell_data_row.get("variant")
        cell_variant_counts[variant_value] = cell_variant_counts.get(
            variant_value, 0) + 1

        for key in dimensions.keys():
            dimension_value = cell_data_row.get("dimensions", {}).get(key)
            cell_dimension_counts[key][dimension_value] = \
                cell_dimension_counts[key].get(dimension_value, 0) + 1

    variant_name = project.get_variant()["name"]

    project_data_dto = {
        "image_count": total_images,
        "variant_name": variant_name,
        "variant_data": variant_counts,
        "cell_variant_data": cell_variant_counts,
        "dimension_counts": dimension_counts,
        "cell_dimension_counts": cell_dimension_counts
    }

    page_data = {"title": "", "active_nav_tab": "data"}

    return render_template('projects/data.html',
                           project=project_dto,
                           project_data=project_data_dto,
                           page_data=page_data)