Update helper functions
Browse files- NuCLS_dataset.py +8 -6
NuCLS_dataset.py
CHANGED
@@ -115,11 +115,12 @@ class NuCLSDataset(GeneratorBasedBuilder):
|
|
115 |
data_dir = dl_manager.download_and_extract(_URL)
|
116 |
|
117 |
# Directory paths
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
123 |
# Generate a list of unique filenames (without extensions)
|
124 |
unique_filenames = [os.path.splitext(f)[0] for f in os.listdir(rgb_dir)]
|
125 |
|
@@ -176,7 +177,8 @@ class NuCLSDataset(GeneratorBasedBuilder):
|
|
176 |
"""Reads an image file and returns it as a PIL Image object."""
|
177 |
try:
|
178 |
with open(file_path, 'rb') as f:
|
179 |
-
|
|
|
180 |
except Exception as e:
|
181 |
print(f"Error reading image file {file_path}: {e}")
|
182 |
return None
|
|
|
115 |
data_dir = dl_manager.download_and_extract(_URL)
|
116 |
|
117 |
# Directory paths
|
118 |
+
base_dir = os.path.join(data_dir, "NuCLS_dataset")
|
119 |
+
rgb_dir = os.path.join(base_dir, "rgb")
|
120 |
+
visualization_dir = os.path.join(base_dir, "visualization")
|
121 |
+
mask_dir = os.path.join(base_dir, "mask")
|
122 |
+
csv_dir = os.path.join(base_dir, "csv")
|
123 |
+
|
124 |
# Generate a list of unique filenames (without extensions)
|
125 |
unique_filenames = [os.path.splitext(f)[0] for f in os.listdir(rgb_dir)]
|
126 |
|
|
|
177 |
"""Reads an image file and returns it as a PIL Image object."""
|
178 |
try:
|
179 |
with open(file_path, 'rb') as f:
|
180 |
+
image = PilImage.open(f)
|
181 |
+
return np.array(image)
|
182 |
except Exception as e:
|
183 |
print(f"Error reading image file {file_path}: {e}")
|
184 |
return None
|