0

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

vftw
  • 1,547
  • 3
  • 22
  • 51
  • Looking at the documentation of the Python bindings of OpenSlide, it seems that library is only good for reading the files. That means you have to find another library that can write them and use that (unfortunately asking for one is off-topic here, maybe try https://softwarerecs.stackexchange.com/). There might not be any for Python while there are some for a different language -- then you can perhaps wrap that to be usable in Python. Otherwise you'll have to grok the file format and write some code to implement writing it. That is probably way too broad for a StackOverflow question, TBH. – Dan Mašek Nov 10 '18 at 23:22
  • When I said I wanted to use OpenSlide, I didn't mean that I want to use that library exclusively. Perhaps there is a more appropriated library to do that. I only want to do the reverse of `np.asarray` and convert my array of bytes to a .SVS image again. Tiff format would be good as well. – vftw Nov 11 '18 at 02:38

1 Answers1

0

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

Callum
  • 65
  • 1
  • 7