33from pathlib import Path
44from typing import List
55
6+ import numpy as np
7+
68
79def skan_skeleton () -> List ["LayerData" ]: # noqa: F821
810 import pandas as pd
@@ -106,7 +108,6 @@ def tgmm_mini_dataset() -> List["LayerData"]: # noqa: F821
106108
107109
108110def bbbc_1_dataset () -> List ["LayerData" ]: # noqa: F821
109- import napari
110111 import pandas as pd
111112 from skimage import io
112113
@@ -117,41 +118,56 @@ def bbbc_1_dataset() -> List["LayerData"]: # noqa: F821
117118 os .path .join (str (path ), "**" , "*.tif" ), recursive = True
118119 )
119120 raw_images = [f for f in tif_files if "labels" not in f ]
121+
122+ n_rows = np .ceil (np .sqrt (len (raw_images )))
123+ n_cols = np .ceil (len (raw_images ) / n_rows )
124+
120125 layers = []
121126
122- for raw_image_filename in raw_images :
127+ images = [io .imread (f ) for f in raw_images ]
128+ labels = [io .imread (f .replace (".tif" , "_labels.tif" )) for f in raw_images ]
129+ features = [
130+ pd .read_csv (f .replace (".tif" , "_features.csv" )) for f in raw_images
131+ ]
123132
124- label_filename = raw_image_filename .replace (".tif" , "_labels.tif" )
125- feature_filename = raw_image_filename .replace (".tif" , "_features.csv" )
126- image = io .imread (raw_image_filename )
127- labels = io .imread (label_filename )
133+ max_size = max ([image .shape [0 ] for image in images ])
128134
129- features = pd .read_csv (feature_filename )
135+ for idx , (image , label , feature ) in enumerate (
136+ zip (images , labels , features )
137+ ):
138+
139+ translate_img_x = image .shape [0 ] / 2
140+ translate_img_y = image .shape [1 ] / 2
141+
142+ # calculate translate in grid
143+ margin = 0.1 * image .shape [0 ] # 10% margin
144+ i_row = idx // n_cols
145+ i_col = idx % n_cols
146+ translate_x = i_row * (max_size + margin ) - translate_img_x
147+ translate_y = i_col * (max_size + margin ) - translate_img_y
130148
131149 ldtuple_image = (
132150 image ,
133151 {
134- "name" : Path (raw_image_filename ).stem ,
152+ "name" : Path (raw_images [idx ]).stem ,
153+ "translate" : (translate_x , translate_y ),
135154 },
136155 "image" ,
137156 )
138157
139158 ldtuple_labels = (
140- labels ,
159+ label ,
141160 {
142- "name" : Path (raw_image_filename ).stem + "_labels" ,
143- "features" : features ,
161+ "name" : Path (raw_images [idx ]).stem + "_labels" ,
162+ "translate" : (translate_x , translate_y ),
163+ "features" : feature ,
144164 },
145165 "labels" ,
146166 )
147167
148168 layers .append (ldtuple_image )
149169 layers .append (ldtuple_labels )
150170
151- viewer = napari .current_viewer ()
152- viewer .grid .enabled = True
153- viewer .grid .stride = 2
154-
155171 return layers
156172
157173
0 commit comments