Convert image array to original svs format

2024/10/12 1:23:48

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

Answer

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

https://en.xdnf.cn/q/118255.html

Related Q&A

Printing bytestring via variable

I have the following Unicode text stored in variable:myvariable = Gen\xe8veWhat I want to do is to print myvariable and show this:GenveI tried this but failed:print myvariable.decode(utf-8)Whats the ri…

Loop and arrays of strings in python

I have the following data set:column1HL111 PG3939HL11 HL339PG RC--HL--PGI am attempting to write a function that does the following:Loop through each row of column1 Pull only the alphabet and put into…

2 Dendrograms + Heatmap from condensed correlationmatrix with scipy

I try to create something like this: plotting results of hierarchical clustering ontop of a matrix of data in pythonUnfortunatelly when I try to execute the code, I get the following warnings:Warning (…

Iterator example from Dive Into Python 3

Im learning Python as my 1st language from http://www.diveintopython3.net/. On Chp 7, http://www.diveintopython3.net/iterators.html, there is an example of how to use an iterator.import redef build_mat…

Getting a 500 Internal Server Error using render_template and Flask [duplicate]

This question already has answers here:How to debug a Flask app(13 answers)Comments not working in jinja2(2 answers)Closed 5 years ago.I am trying to use Flask to render an HTML template. I had it work…

Bokeh use of Column Data Source and Box_Select

Im lost as to how to set up a Column Data Source so that I can select points from one graph and have the corresponding points highlighted in another graph. I am trying to learn more about how this work…

How Does a Pyqtgraph Export for Three Subplots Look Like?

Using PyQtGraph, I would like to generate three sub plots in one chart and export this chart to a file.As I will repeat this a lot of times, it is quite performance sensitive. Therefore I do not need t…

Use class variables as instance vars?

What I would like to do there is declaring class variables, but actually use them as vars of the instance. I have a class Field and a class Thing, like this:class Field(object):def __set__(self, instan…

Get amount from django-paypal

I am using django-paypal to receive payment. I am currently paying as well as receiving payment using sandbox accounts. The payment procedure seems to be working fine. My problem is once I get back the…

Python get file regardless of upper or lower

Im trying to use this on my program to get an mp3 file regardless of case, and Ive this code:import glob import fnmatch, redef custom_song(name):for song in re.compile(fnmatch.translate(glob.glob("…