Convert image array to original svs format

1.5k views Asked by At

I'm trying to apply a foreground extraction to a SVS image (Whole Slide Image) usign OpenSlide library.

First, I converted my image to an array to work on my foreground extraction:

image = np.asarray(oslIm.read_region((0, 0), level, oslIm.level_dimensions[level]), dtype=np.uint8)[:, :, 0:3]

After that I generated my mask, which I applied to my converted image:

plt.imshow(image * final_mask[:, :, np.newaxis])
plt.xticks([])
plt.yticks([])
plt.savefig("./masks/ResultingImage.png", format='png', dpi=90, pad_inches=0.1, bbox_inches='tight');
plt.close()

What I want is to convert my image to svs again so I can work on the foreground of the original image and apply my patch extractor (tile the image in patches for annotation ease)

def sample_and_store_patches_by_row(
        file_name,
        pixel_overlap,
        patch_size=512,
        level=17,
):

How can I do that?

Regards

1

There are 1 answers

0
Callum On

Unfortunately openslide does not support writing to WSI files. The best thing I have come across for writing large files is pyvips.

Correct me if I am wrong but I don't think that there is any way to save a specific svs file as it's a proprietary format.

There is an example of how to make a WSI type file in this answer