how to convert .SVS to .JPEG with python using tifffile

94 Views Asked by At

How do you convert a .SVS file into a single large JPEG file in python using tifffile. From what i have read a .SVS file is just basically a .TIFF file but with something added to it. My images are from a cell imaging machine

Google search led me to tifffile and i already like it because i dont have to install anything else on my computer in order for it to work, its all contained in python. so i can easily bring the script to another machine without having to install something complicated

According to tifffile documentation it converts the .svs into a numpy array which i then thought i could use another library to convert it back to JPEG. Problem is i don't see an example code wherein it loads up a .svs and stores it as a NumPy Array. I could not find documentation also for its class/functions.

Can anyone help me make the specific line of code for loading up the .svs and saving it as JPEG in the highest quality possible

I'm also open to suggestion to other libraries that can do similar to what i want that you have tried, so i can try them out

Here was my attempt at it

import numpy as np 
import tifffile
from PIL import Image as im 

x = tifffile.imread('Sample.svs', key=0)

# check type of array 
print(type(x)) 

print(x.shape) 
    
# creating image object of 
# above array 
data = im.fromarray(x) 

print("Saving")

# saving the final output  
# as a PNG file 
data.save('pic.png')  #Gets stuck here

print("Done")

Terminal Output:

<class 'numpy.ndarray'>
(25088, 36864, 3)
Saving

So the code gets stuck at the data.save line, its not really that its stuck there, because i can see that pic.png file size is increasing. The original .svs file is 73MB while pic.png is now at 500MB (at this point i terminated the script).

EDIT: I actually let it run for as long as it wanted to, the file size is around 670MB. Both windows photo and VS code cannot open the image generated. I also noticed i saved it in a PNG format, so i replaced it with .jpg it was a bit quicker only 50MB file size, but unfortunately still the image cannot be viewed.

Here is a sample .SVS file, its a different file than what im working (only 23MB in size) but this one is available to the public so its okay to share this one

0

There are 0 best solutions below