Beispiel #1
0
def export_slices(session_id: int):
    with application.app_context():
        label_session = sessions.get_session_by_id(db.session, session_id)
        if label_session is None:
            print('Session with id {} not found'.format(session_id))
            return

        session_slices_dir_path = os.path.join(
            EXPORTED_SLICES_DIR_PATH, label_session.session_name + ' Slices')
        session_slices_dir_path = inc_dir_name(session_slices_dir_path)

        os.makedirs(session_slices_dir_path, exist_ok=True)

        slices = sampling.get_slices_from_session(label_session)
        dataset = backend.get_dataset(label_session.dataset)

        for sl in slices:
            d_img = backend.get_image(dataset, sl.image_name)
            sl_max = backend.get_image_info(d_img)[1]
            sl_img = backend.get_slice(d_img, sl.slice_index, sl.slice_type, 0,
                                       sl_max)

            save_name = '{}_{}_{}.png'.format(sl.image_name,
                                              sl.slice_type.name,
                                              sl.slice_index)
            save_path = os.path.join(session_slices_dir_path, save_name)

            sl_img.save(save_path)
            print('Saved {}'.format(save_path))
Beispiel #2
0
def label_categorical_slice():
    label_session_id = request.args.get('label_session', type=int, default=None)
    element_index = request.args.get('i', type=int, default=None)

    if label_session_id is None or element_index is None:
        abort(400)

    label_session = sessions.get_session_by_id(db.session, label_session_id)
    if label_session is None or label_session.session_type != LabelSessionType.CATEGORICAL_SLICE.name:
        abort(400)

    dataset = backend.get_dataset(label_session.dataset)
    if dataset is None:
        abort(400)

    element = labels.get_element_by_index(db.session, label_session, element_index)
    image = backend.get_image(dataset, element.image_1_name)
    if image is None:
        abort(400)

    im_slice = backend.ImageSlice(element.image_1_name, element.slice_1_index, backend.SliceType[element.slice_1_type])

    _, max_value = backend.get_image_info(image)

    slice_label_value = element.current_label_value()
    return render_template('label_categorical_slice.html',
                           label_session=label_session,
                           dataset=dataset,
                           element_id=element.id,
                           image_slice=im_slice,
                           slice_label_value=slice_label_value,
                           image_max=max_value,
                           previous_index=max(0, element_index - 1),
                           next_index=min(label_session.element_count - 1, element_index + 1))
Beispiel #3
0
def viewer():
    dataset_name = request.args.get('dataset', type=str, default=None)
    image_name = request.args.get('image', type=str, default=None)

    if dataset_name is None or image_name is None:
        abort(400)

    dataset = backend.get_dataset(dataset_name)
    if dataset is None:
        abort(400)

    image = backend.get_image(dataset, image_name)
    if image is None:
        abort(400)

    slice_counts, max_value = backend.get_image_info(image)

    return render_template('viewer.html',
                           viewer_mode='viewer',
                           dataset=dataset,
                           image=image,
                           image_count=0,
                           image_index=0,
                           slice_counts=slice_counts,
                           image_max=max_value)
Beispiel #4
0
def label_compare():
    label_session_id = request.args.get('label_session', type=int, default=None)
    comparison_index = request.args.get('i', type=int, default=None)

    if label_session_id is None or comparison_index is None:
        abort(400)

    assert 0 <= comparison_index
    label_session = sessions.get_session_by_id(db.session, label_session_id)
    if label_session is None or label_session.session_type != LabelSessionType.COMPARISON_SLICE.name:
        abort(400)

    dataset = backend.get_dataset(label_session.dataset)
    if dataset is None:
        abort(400)

    element = labels.get_element_by_index(db.session, label_session, comparison_index)

    slice_1 = backend.ImageSlice(element.image_1_name, element.slice_1_index, backend.SliceType[element.slice_1_type])
    slice_2 = backend.ImageSlice(element.image_2_name, element.slice_2_index, backend.SliceType[element.slice_2_type])

    image_1 = backend.get_image(dataset, slice_1.image_name)
    image_2 = backend.get_image(dataset, slice_2.image_name)

    _, image_1_max = backend.get_image_info(image_1)
    _, image_2_max = backend.get_image_info(image_2)

    current_label_value = element.current_label_value()

    return render_template('label_compare.html',
                           label_session=label_session,
                           prompt=label_session.prompt,
                           dataset=dataset,
                           element_id=element.id,
                           slice_1=slice_1,
                           slice_2=slice_2,
                           image_1_max=image_1_max,
                           image_2_max=image_2_max,
                           current_label_value=current_label_value,
                           sort_mode=False,
                           previous_index=max(0, comparison_index - 1),
                           next_index=min(label_session.element_count - 1, comparison_index + 1))
Beispiel #5
0
def label_sort_compare():
    label_session_id = request.args.get('label_session')
    if label_session_id is None:
        abort(404)

    label_session = sessions.get_session_by_id(db.session, label_session_id)
    if label_session is None:
        abort(404)
    if label_session.session_type != LabelSessionType.SORT_SLICE.name:
        abort(400)

    dataset = backend.get_dataset(label_session.dataset)
    if dataset is None:
        abort(404)

    complete, comparison_el, _ = comparesort.add_next_comparison(db.session, label_session)
    if complete:
        return redirect(url_for('session_overview', session_id=label_session.id))

    comparison = sampling.get_comparison_from_element(comparison_el)
    slice_1, slice_2 = comparison

    image_1 = backend.get_image(dataset, slice_1.image_name)
    image_2 = backend.get_image(dataset, slice_2.image_name)

    _, image_1_max = backend.get_image_info(image_1)
    _, image_2_max = backend.get_image_info(image_2)

    current_label_value = None

    return render_template('label_compare.html',
                           label_session=label_session,
                           prompt=label_session.prompt,
                           dataset=dataset,
                           element_id=comparison_el.id,
                           slice_1=slice_1,
                           slice_2=slice_2,
                           image_1_max=image_1_max,
                           image_2_max=image_2_max,
                           current_label_value=current_label_value,
                           sort_mode=True)
Beispiel #6
0
def label():
    label_session_id = request.args.get('label_session', type=int, default=None)
    element_index = request.args.get('i', type=int, default=None)

    if label_session_id is None or element_index is None:
        abort(400)

    label_session = sessions.get_session_by_id(db.session, label_session_id)
    if label_session is None or label_session.session_type != LabelSessionType.CATEGORICAL_IMAGE.name:
        abort(400)

    dataset = backend.get_dataset(label_session.dataset)
    if dataset is None:
        abort(400)

    element = labels.get_element_by_index(db.session, label_session, element_index)
    image = backend.get_image(dataset, element.image_1_name)
    if image is None:
        abort(400)

    slice_counts, max_value = backend.get_image_info(image)

    image_label_value = element.current_label_value()

    return render_template('viewer.html',
                           viewer_mode='label',
                           label_session=label_session,
                           prompt=label_session.prompt,
                           dataset=dataset,
                           image=image,
                           element_id=element.id,
                           slice_counts=slice_counts,
                           image_max=max_value,
                           image_label_value=image_label_value,
                           previous_index=max(0, element_index - 1),
                           next_index=min(label_session.element_count - 1, element_index + 1))