Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20 magnification #2

Open
Polycoriander opened this issue Jul 31, 2024 · 1 comment
Open

20 magnification #2

Polycoriander opened this issue Jul 31, 2024 · 1 comment

Comments

@Polycoriander
Copy link

Hi,
How can we ensure that the Whole Slide Images (WSIs) are at a 20x magnification? If they are not at 20x magnification, how should they be handled? Is there corresponding code available for this?
Thank you!

@titizheng
Copy link
Owner

You can obtain the corresponding magnification from the slide scanning metadata properties using the code below. The slide contain the magnification and other related metadata properties, which can be accessed through slide.properties using the openslide library. This includes:

Magnification (e.g., aperio.AppMag or openslide.mpp-x)
Dimensions of the slide (e.g., width and height)
Size information for different levels (e.g., slide.level_dimensions)

**
def display_wsi_info_and_level(wsi_path, level):
# Open the WSI file
slide = openslide.open_slide(wsi_path)
# Get the dimensions of the WSI
width, height = slide.dimensions
print("WSI Dimensions: {}x{}".format(width, height))
# Get the number of levels in the WSI
num_levels = slide.level_count
dimensions = slide.level_dimensions
print("WSI Level Count:", num_levels)
print("WSI Level Details:", dimensions)
# Get WSI metadata and read related information
if 'aperio.AppMag' in slide.properties.keys():
level_0_magnification = int(slide.properties['aperio.AppMag'])
elif 'openslide.mpp-x' in slide.properties.keys():
level_0_magnification = 40 if int(np.floor(float(slide.properties['openslide.mpp-x']) * 10)) == 2 else 20
else:
level_0_magnification = 40
# Output the magnification corresponding to level 0
print("Magnification for level_0:", level_0_magnification)
magnification = 10
# Calculate the downsampling rate based on the level 0 magnification and the desired magnification,
# e.g., if level 0 has a magnification of 40, and we want 5x, then the downsampling rate is 40/5=8
downsample = level_0_magnification / 5
# Get the level corresponding to the closest magnification for this downsampling rate
level = slide.get_best_level_for_downsample(downsample)
print("{}x magnification corresponds to Level_{}".format(magnification, level))
wsi_path = r'./dataset/BRCA/BRCA-slides/TCGA-5L-AAT1-01Z-00-DX1.F3449A5B-2AC4-4ED7-BF44-4C8946CDB47D.svs'
selected_level = 2
display_wsi_info_and_level(wsi_path, selected_level)

**

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants