Skip to content

Commit 5168a12

Browse files
Nikolas SchmitzNikolasSchmitz
authored andcommitted
Small changes
1 parent 5b988a2 commit 5168a12

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

monai/data/wsi_reader.py

Lines changed: 11 additions & 9 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)
@@ -1307,8 +1307,10 @@ def get_img_at_mpp(self, wsi, mpp: tuple, atol: float = 0.00, rtol: float = 0.05
13071307
"""
13081308
Returns the representation of the whole slide image at a given micro-per-pixel (mpp) resolution.
13091309
The optional tolerance parameters are considered at the level whose mpp value is closest to the one provided by the user.
1310-
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.
1311-
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.
1310+
If the user-provided mpp is larger than the mpp of the closest level,
1311+
the image is downscaled to a resolution that matches the user-provided mpp.
1312+
Otherwise, if the closest level's resolution is not sufficient to meet the user's requested resolution,
1313+
the next lower level (which has a higher resolution) is chosen.
13121314
The image from this level is then down-scaled to achieve a resolution at the user-provided mpp value.
13131315
13141316
Args:
@@ -1327,7 +1329,7 @@ def get_img_at_mpp(self, wsi, mpp: tuple, atol: float = 0.00, rtol: float = 0.05
13271329

13281330
mpp_closest_lvl = mpp_list[closest_lvl]
13291331

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

0 commit comments

Comments
 (0)