Explorando el Archivo BioImage#
En este notebook utilizamos el proyecto bia-explorer para explorar el conjunto de datos S-BIAD634 en el Archivo Bio-image. Descargaremos algunas imágenes y las almacenaremos en un directorio local.
from bia_explorer import io, biostudies
from skimage.io import imread, imsave
from IPython.display import display, Markdown
import stackview
Accediendo a los metadatos#
Primero accedemos a los metadatos de los conjuntos de datos. Aquí podemos ver, por ejemplo, para qué se pueden utilizar los datos y bajo qué licencia se pueden usar.
accession = 'S-BIAD634'
submission = biostudies.load_submission(accession)
for a in submission.section.attributes:
name = a.name
short_value = str(a.value)
print(f"{name} : {short_value}")
Title : An annotated fluorescence image dataset for training nuclear segmentation methods
Description : This dataset contains annotated fluorescent nuclear images of normal or cancer cells from different tissue origins and sample preparation types, and can be used to train machine-learning based nuclear image segmentation algorithms. It consists of 79 expert-annotated fluorescence images of immuno and DAPI stained samples containing 7813 nuclei in total. In addition, the dataset is heterogenous in aspects such as type of preparation, imaging modality, magnification, signal-to-noise ratio and other technical aspects. Relevant parameters, e.g. diagnosis, magnification, signal-to-noise ratio and modality with respect to the type of preparation are provided in the file list. The images are derived from one Schwann cell stroma-rich tissue (from a ganglioneuroblastoma) cryosection (10 images/2773 nuclei), seven neuroblastoma (NB) patients (19 images/931 nuclei), one Wilms patient (1 image/102 nuclei), two NB cell lines (CLB-Ma, STA-NB10) (8 images/1785 nuclei) and a human keratinocyte cell line (HaCaT) (41 images/2222 nuclei).
Keywords : AI
Keywords : segmentation
Keywords : nucleus
Keywords : fluorescence
License : CC0
Funding statement : This work was facilitated by an EraSME grant (project TisQuant) under the grant no. 844198 and by a COIN grant (project VISIOMICS) under the grant no. 861750, both grants kindly provided by the Austrian Research Promotion Agency (FFG), and the St. Anna Kinderkrebsforschung. Partial funding was further provided by BMK, BMDW, and the Province of Upper Austria in the frame of the COMET Programme managed by FFG.
También podemos ver cuántas imágenes hay en el conjunto de datos.
study = io.load_bia_study(accession)
len(study.images)
388
Visualizando imágenes#
Una sola imagen puede ser cargada y mostrada de esta manera (Ver también).
image = study.images[0]
image
BIAImage(uri='https://www.ebi.ac.uk/biostudies/files/S-BIAD634/dataset\\groundtruth\\Ganglioneuroblastoma_0.tif', size=2239668, fpath=WindowsPath('dataset/groundtruth/Ganglioneuroblastoma_0.tif'))
uri = image.uri.replace("\\", "/")
image_data = imread(uri)
stackview.insight(image_data)
|
|
|
Para tener una idea de la estructura de carpetas dentro de los conjuntos de datos, podemos imprimir las rutas en el servidor.
# imprimir los nombres de archivo de algunas imágenes
for image in study.images[:5] + study.images[-5:]:
print(str(image.fpath))
dataset\groundtruth\Ganglioneuroblastoma_0.tif
dataset\groundtruth\Ganglioneuroblastoma_1.tif
dataset\groundtruth\Ganglioneuroblastoma_10.tif
dataset\groundtruth\Ganglioneuroblastoma_2.tif
dataset\groundtruth\Ganglioneuroblastoma_3.tif
dataset\rawimages\otherspecimen_5.tif
dataset\rawimages\otherspecimen_6.tif
dataset\rawimages\otherspecimen_7.tif
dataset\rawimages\otherspecimen_8.tif
dataset\rawimages\otherspecimen_9.tif
Descargando datos#
Antes de descargar las imágenes seleccionadas, necesitamos asegurarnos de que existe la carpeta donde queremos almacenar los datos.
import os
def ensure_folder_exists(folder_path):
if not os.path.exists(folder_path):
os.makedirs(folder_path)
base_folder = f"../../data/{accession}"
raw_folder = f"../../data/{accession}/images"
groundtruth_folder = f"../../data/{accession}/groundtruth"
ensure_folder_exists(base_folder)
ensure_folder_exists(raw_folder)
ensure_folder_exists(groundtruth_folder)
A continuación, descargamos todas las imágenes sin procesar y las anotaciones de verdad fundamental de todos los conjuntos de datos que contienen “Ganglioneuroblastoma” en su nombre. También solo descargamos los archivos en caso de que aún no se hayan descargado.
for image in study.images:
if "Ganglioneuroblastoma" in str(image.fpath):
uri = image.uri.replace("\\", "/")
filename = uri.split("/")[-1]
if "\\rawimages\\" in str(image.fpath):
target_file = raw_folder + "/" + filename
if not os.path.exists(target_file):
image_data = imread(uri)
imsave(target_file, image_data)
if "\\groundtruth\\" in str(image.fpath):
target_file = groundtruth_folder + "/" + filename
if not os.path.exists(target_file):
image_data = imread(uri)
imsave(target_file, image_data)
C:\Users\haase\AppData\Local\Temp\ipykernel_26092\2091960599.py:14: UserWarning: ../../data/S-BIAD634/groundtruth/Ganglioneuroblastoma_0.tif is a low contrast image
imsave(target_file, image_data)
C:\Users\haase\AppData\Local\Temp\ipykernel_26092\2091960599.py:14: UserWarning: ../../data/S-BIAD634/groundtruth/Ganglioneuroblastoma_1.tif is a low contrast image
imsave(target_file, image_data)
C:\Users\haase\AppData\Local\Temp\ipykernel_26092\2091960599.py:14: UserWarning: ../../data/S-BIAD634/groundtruth/Ganglioneuroblastoma_10.tif is a low contrast image
imsave(target_file, image_data)
C:\Users\haase\AppData\Local\Temp\ipykernel_26092\2091960599.py:14: UserWarning: ../../data/S-BIAD634/groundtruth/Ganglioneuroblastoma_2.tif is a low contrast image
imsave(target_file, image_data)
C:\Users\haase\AppData\Local\Temp\ipykernel_26092\2091960599.py:14: UserWarning: ../../data/S-BIAD634/groundtruth/Ganglioneuroblastoma_3.tif is a low contrast image
imsave(target_file, image_data)
C:\Users\haase\AppData\Local\Temp\ipykernel_26092\2091960599.py:14: UserWarning: ../../data/S-BIAD634/groundtruth/Ganglioneuroblastoma_4.tif is a low contrast image
imsave(target_file, image_data)
C:\Users\haase\AppData\Local\Temp\ipykernel_26092\2091960599.py:14: UserWarning: ../../data/S-BIAD634/groundtruth/Ganglioneuroblastoma_6.tif is a low contrast image
imsave(target_file, image_data)
C:\Users\haase\AppData\Local\Temp\ipykernel_26092\2091960599.py:14: UserWarning: ../../data/S-BIAD634/groundtruth/Ganglioneuroblastoma_7.tif is a low contrast image
imsave(target_file, image_data)
C:\Users\haase\AppData\Local\Temp\ipykernel_26092\2091960599.py:14: UserWarning: ../../data/S-BIAD634/groundtruth/Ganglioneuroblastoma_8.tif is a low contrast image
imsave(target_file, image_data)
C:\Users\haase\AppData\Local\Temp\ipykernel_26092\2091960599.py:14: UserWarning: ../../data/S-BIAD634/groundtruth/Ganglioneuroblastoma_9.tif is a low contrast image
imsave(target_file, image_data)
Luego podemos verificar qué archivos llegaron.
for f in os.listdir(raw_folder):
print(f)
Ganglioneuroblastoma_0.tif
Ganglioneuroblastoma_1.tif
Ganglioneuroblastoma_10.tif
Ganglioneuroblastoma_2.tif
Ganglioneuroblastoma_3.tif
Ganglioneuroblastoma_4.tif
Ganglioneuroblastoma_6.tif
Ganglioneuroblastoma_7.tif
Ganglioneuroblastoma_8.tif
Ganglioneuroblastoma_9.tif
for f in os.listdir(groundtruth_folder):
print(f)
Ganglioneuroblastoma_0.tif
Ganglioneuroblastoma_1.tif
Ganglioneuroblastoma_10.tif
Ganglioneuroblastoma_2.tif
Ganglioneuroblastoma_3.tif
Ganglioneuroblastoma_4.tif
Ganglioneuroblastoma_6.tif
Ganglioneuroblastoma_7.tif
Ganglioneuroblastoma_8.tif
Ganglioneuroblastoma_9.tif
Ejercicio#
Descarga todas las imágenes con “Neuroblastoma” en su nombre y súbelas a una carpeta en la owncloud. No descargues ni subas archivos que ya existan.