def create_thumbnails(label_session: LabelSession): dataset = backend.get_dataset(label_session.dataset) slices = sampling.get_slices_from_session(label_session) session_thumbs_dir_path = get_session_thumbnails_dir_path(label_session) os.makedirs(session_thumbs_dir_path, exist_ok=True) for sl in slices: d_img = backend.get_image(dataset, sl.image_name) slice_thumb_path = os.path.join(session_thumbs_dir_path, backend.slice_name(sl) + '.jpg') backend.get_slice(d_img, sl.slice_index, sl.slice_type, 0, None).save(slice_thumb_path) print('Created {} thumbnails for session {}'.format( len(slices), label_session.session_name))
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))
def thumbnail(dataset_name: str, image_name: str): dataset = backend.get_dataset(dataset_name) d_img = backend.get_image(dataset, image_name) slice_index = request.args.get('slice_index', default=0, type=int) slice_type_name = request.args.get('slice_type', default='AXIAL', type=str) intensity_min = request.args.get('min', default=0, type=int) intensity_max = request.args.get('max', default=0, type=int) slice_type = backend.SliceType[slice_type_name] slice_image = backend.get_slice(d_img, slice_index, slice_type, intensity_min, intensity_max) img_io = BytesIO() slice_image.save(img_io, 'PNG') img_io.seek(0) return send_file(img_io, mimetype='image/png')
def create_thumbnails(label_session: LabelSession): dataset = backend.get_dataset(label_session.dataset) slices = sampling.get_slices_from_session(label_session) dataset_thumbs_path = get_dataset_thumbnails_path(dataset) os.makedirs(dataset_thumbs_path, exist_ok=True) created = 0 for sl in slices: d_img = backend.get_image(dataset, sl.image_name) slice_thumb_path = os.path.join(dataset_thumbs_path, get_thumbnail_name(sl)) if not os.path.exists(slice_thumb_path): img = backend.get_slice(d_img, sl.slice_index, sl.slice_type, 0, None, THUMB_MAX_PERCENTILE) img.save(slice_thumb_path) created += 1 print('Created {} thumbnails for session {} (skipped {}, total {})'.format( created, label_session.session_name, len(slices) - created, len(slices)))