Skip to content

Commit 8194026

Browse files
author
Nikolas Schmitz
committed
Small changes
1 parent feac0dc commit 8194026

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

monai/data/wsi_reader.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ def get_img_at_mpp(self, wsi, mpp: tuple, atol: float = 0.00, rtol: float = 0.05
790790
# -> Should not throw ValueError, instead just return the closest value; how to select tolerances?
791791

792792
mpp_closest_lvl = mpp_list[closest_lvl]
793-
closest_lvl_dim = wsi.resolutions['level_dimensions'][closest_lvl] # x,y notation
793+
closest_lvl_dim = wsi.resolutions['level_dimensions'][closest_lvl]
794794

795795
print(f'Closest Level: {closest_lvl} with MPP: {mpp_closest_lvl}')
796796
mpp_closest_lvl_x, mpp_closest_lvl_y = mpp_closest_lvl
@@ -809,7 +809,7 @@ def get_img_at_mpp(self, wsi, mpp: tuple, atol: float = 0.00, rtol: float = 0.05
809809
if within_tolerance:
810810
# Take closest_level and continue with returning img at level
811811
print(f'User-provided MPP lies within tolerance of level {closest_lvl}, returning wsi at this level.')
812-
closest_lvl_wsi = wsi.read_region((0, 0), level=closest_lvl, size=closest_lvl_dim, num_workers=self.num_workers) # size in x,y notation
812+
closest_lvl_wsi = wsi.read_region((0, 0), level=closest_lvl, size=closest_lvl_dim, num_workers=self.num_workers)
813813

814814
else:
815815
# If mpp_closest_level < mpp -> closest_level has higher res than img at mpp => downscale from closest_level to mpp
@@ -827,13 +827,13 @@ def get_img_at_mpp(self, wsi, mpp: tuple, atol: float = 0.00, rtol: float = 0.05
827827
target_res_x = int(np.round(closest_lvl_dim[1] * ds_factor_x))
828828
target_res_y = int(np.round(closest_lvl_dim[0] * ds_factor_y))
829829

830-
closest_lvl_wsi = cucim_resize(wsi_arr, (target_res_x, target_res_y), order=0) # output_shape in row, col notation
830+
closest_lvl_wsi = cucim_resize(wsi_arr, (target_res_x, target_res_y), order=0)
831831
print(f'Case 1: Downscaling using factor {(ds_factor_x, ds_factor_y)}')
832832

833833
else:
834834
# Else: increase resolution (ie, decrement level) and then downsample
835835
closest_lvl = closest_lvl - 1
836-
mpp_closest_lvl = mpp_list[closest_lvl] # Update MPP
836+
mpp_closest_lvl = mpp_list[closest_lvl]
837837
mpp_closest_lvl_x, mpp_closest_lvl_y = mpp_closest_lvl
838838

839839
ds_factor_x = mpp_closest_lvl_x / user_mpp_x
@@ -1115,7 +1115,7 @@ def get_img_at_mpp(self, wsi, mpp: tuple, atol: float = 0.00, rtol: float = 0.05
11151115
else:
11161116
# Else: increase resolution (ie, decrement level) and then downsample
11171117
closest_lvl = closest_lvl - 1
1118-
mpp_closest_lvl = mpp_list[closest_lvl] # Update MPP
1118+
mpp_closest_lvl = mpp_list[closest_lvl]
11191119
mpp_closest_lvl_x, mpp_closest_lvl_y = mpp_closest_lvl
11201120

11211121
ds_factor_x = mpp_closest_lvl_x / user_mpp_x
@@ -1127,7 +1127,7 @@ def get_img_at_mpp(self, wsi, mpp: tuple, atol: float = 0.00, rtol: float = 0.05
11271127
target_res_x = int(np.round(closest_lvl_dim[0] * ds_factor_x))
11281128
target_res_y = int(np.round(closest_lvl_dim[1] * ds_factor_y))
11291129

1130-
closest_lvl_wsi = closest_lvl_wsi.resize((target_res_x, target_res_y), pil_image.BILINEAR) # Output size in x,y notation
1130+
closest_lvl_wsi = closest_lvl_wsi.resize((target_res_x, target_res_y), pil_image.BILINEAR)
11311131
print(f'Case 2: Downscaling using factor {(ds_factor_x, ds_factor_y)}, now from level {closest_lvl}')
11321132

11331133
wsi_arr = np.array(closest_lvl_wsi)
@@ -1289,9 +1289,9 @@ def get_mpp(self, wsi, level: int) -> tuple[float, float]:
12891289
and wsi.pages[level].tags["YResolution"].value
12901290
):
12911291
unit = wsi.pages[level].tags.get("ResolutionUnit")
1292-
if unit is not None: # Needs to be extended
1293-
# unit = str(unit.value)[8:]
1294-
unit = str(unit.value.name).lower() # TODO: Merge both methods
1292+
if unit is not None: # Needs to be improved
1293+
unit = str(unit.value)[8:]
1294+
# unit = str(unit.value.name).lower() # TODO: Merge both methods
12951295

12961296
else:
12971297
warnings.warn("The resolution unit is missing. `micrometer` will be used as default.")
@@ -1309,8 +1309,10 @@ def get_img_at_mpp(self, wsi, mpp: tuple, atol: float = 0.00, rtol: float = 0.05
13091309
"""
13101310
Returns the representation of the whole slide image at a given micro-per-pixel (mpp) resolution.
13111311
The optional tolerance parameters are considered at the level whose mpp value is closest to the one provided by the user.
1312-
If the user-provided mpp is larger than the mpp of the closest level the image is downscaled to a resolution that matches the user-provided mpp.
1313-
Otherwise, if the closest level's resolution is not sufficient to meet the user's requested resolution, the next lower level (which has a higher resolution) is chosen.
1312+
If the user-provided mpp is larger than the mpp of the closest level,
1313+
the image is downscaled to a resolution that matches the user-provided mpp.
1314+
Otherwise, if the closest level's resolution is not sufficient to meet the user's requested resolution,
1315+
the next lower level (which has a higher resolution) is chosen.
13141316
The image from this level is then down-scaled to achieve a resolution at the user-provided mpp value.
13151317
13161318
Args:
@@ -1329,7 +1331,7 @@ def get_img_at_mpp(self, wsi, mpp: tuple, atol: float = 0.00, rtol: float = 0.05
13291331

13301332
mpp_closest_lvl = mpp_list[closest_lvl]
13311333

1332-
lvl_dims = [self.get_size(wsi, lvl) for lvl in range(len(wsi.pages))] # Returns size in (height, width)
1334+
lvl_dims = [self.get_size(wsi, lvl) for lvl in range(len(wsi.pages))]
13331335
closest_lvl_dim = lvl_dims[closest_lvl]
13341336
closest_lvl_dim = (closest_lvl_dim[1], closest_lvl_dim[0])
13351337

0 commit comments

Comments
 (0)