Untitled

mail@pastecode.io avatar
unknown
plain_text
6 days ago
1.1 kB
2
Indexable
Never
import glob
import os
import matplotlib.pyplot as plt
import numpy as np
import pytesseract
import easyocr
#%%
imgDir = '/project/shared/kapur_rajaram_phi/Staging/From_Dinesh_20240703_part4'
svsPaths = glob.glob(os.path.join(imgDir, '*.svs'))
#%%
for svsPath in svsPaths:
    slide = openslide.open_slide(svsPath)


    label_img = slide.associated_images.get('label')

    if label_img:
        
        for angle in [0, 90, 180, 270]:
            rotated_img = label_img.rotate(angle, expand=True)  
            extracted_text = pytesseract.image_to_string(rotated_img)  

            print(f"Extracted Text from {os.path.basename(svsPath)} at {angle} degrees:")
            print(extracted_text)
            print("-" * 50)
            plt.imshow(rotated_img)
            plt.title(f"Label Image (Rotated {angle} degrees) from {os.path.basename(svsPath)}")
            plt.show()

    nLevels = slide.level_count  
    lowres_img = np.array(slide.read_region((0, 0), nLevels-1, slide.level_dimensions[nLevels-1]))[:, :, :3]

    plt.imshow(lowres_img)
    plt.title(f"Low-Resolution Image from {os.path.basename(svsPath)}")
    plt.show()
Leave a Comment