Export .vsi images to PNG using Python

Hello everyone!

I am looking for a way to be able to transform .vsi images (CellSens Olympus) to PNG in a Python script, because later we plan to analyze it in that same language.

We don’t have much idea how to deal with this image format, since what we have seen is a kind of large file with different images inside.

What interests us is to be able to divide these different images, and export them to PNG.

To explain myself better, what we are specifically looking for is to export the following images:

Expr

In Windows’ File Explorer, the file looks like this:
expr2

expr3

Inside each folder, there is a file like this one:
expr4

I tried different ways to make this, for example, using Microscoper (GitHub - pskeshu/microscoper: A simple wrapper for python-bioformats to convert .vsi CellSense format to TIFF.) and also python-bioformats (GitHub - CellProfiler/python-bioformats: Read and write life sciences file formats), but the first one doesn’t work and the second has a short documentation.

I hope someone can help me.

Thank you very much in advance!

EDIT: I have said PNG, but any common format (TIFF, JPEG, etc.) will work for me, as long as it is lossless.

What particular issues did you see with the 2 methods you listed? Are you getting errors or are the converted files not correct?

Is it an absolute requirement to use python? If not the Bio-Formats command line tools would be a quick solution for converting the files (available from Bio-Formats Downloads | Open Microscopy Environment (OME)).

1 Like

Hello David,

Using the first method that I listed, I don’t receive the expected results. It returns me a copy of “label” image.
Here you have some screenshots:

imagen

Regarding python-bioformats, I have not been able to use it since I could not fully understand the documentation of the library, and I have only succeeded in creating a “reader” object.

In answer to the question of whether Python is essential, the answer is no, we could try to adapt to using other options if we are forced to.

Finally, I have tried to use the tool you mention, and the results are similar to those I get with the “Microscoper” library (A “label” image). Here is also a screenshot:

PS: I have not said it in the previous message, but using QuPath, I can read the separated images without problem and export them separately, the idea would be to obtain these images in PNG without going through this tool .

Thank you in advance!

From the second screenshot it looks as though all of the series have been converted, so the first series in you tiff will be the label, then the overview and after you should have the images. If you run the below command (from the same tools as bfconvert) it should hopefully show the whole dataset has been converted:
showinf -nopix path/to/myConvertedFile.tiff

Or to view one of the later series:
showinf -series 2 path/to/myConvertedFile.tiff

If that is showing that the full dataset is converted then it may be that the Microscoper converted files are the same also.

1 Like

Hello again,

Looking from Windows File Explorer, the files look like copies of it. After executing the command you tell me, I can confirm my theory. Here are more screenshots:

imagen

I may have misunderstood you and you mean another TIFF, these are the ones from the output that “Microscoper” gives me.

Sorry for the disturbances :slight_smile:

Yeah, those appear to be just the label, if you run microscoper --list does it show all of the files?

Also, do you see the same thing with the file you converted with the bfconvert tool?

If I run microscoper --list, it only shows me one file.
imagen

The info of the converted file using bfconvert is similar to the other ones.

If this is useful, here you have the output when I run showinf -nopix with the .vsi file as input:
PasteBin

Ok, I think the issue was trying to convert the entire dataset to a png. If you use the bfconvert tool to convert to a tiff (or .ome.tiff) then you will get the same results as you are seeing with QuPath.

If you really need to use png then you can convert each series to its own png using:
bfconvert path/to/input/Image_01_02.vsi /path/to/output/Image_01_02_%s.png

1 Like

Hello again,

I tried to do what you told me (PNG), and this were the results:

The result was a single image with the label

Also, I tried the same with .ome.tiff and the result was similar:

When I use showinf -nopix, I can see all the series, and checking the different series that appear in the file, I have found that series 11, 20, 29 and 38 are the series I was looking for in first instance.

PasteBin

imagen

The problem now is that it is still not divided into files, and there are more series than I really need, although I could filter the series by dimension, I would need to have them in separate files.
(And I have used the %s modifier, as seen in screenshot 3)

If you are on Windows then then the % character will need to be doubled so it should be %%s instead. You can see the full list of options at Converting a file to different format — Bio-Formats 6.6.1 documentation

1 Like

It works! I think that this way of doing it, although it deviates a bit from what I was initially looking for, can serve us.

Thank you very much David for your support and patience!

1 Like

No worries, glad to hear you got it sorted :grinning:

1 Like

Hello David, sorry for reopening this again :sweat_smile:

I am trying to transform only the first level (which is the one with the highest resolution), but I am not succeeding.

If I separate all the levels, identifying the ID of that series I can do it without problems. But this is not the way that I would like to follow since it would be necessary to check how many levels each image has.

Looking in the different options of bfconvert, I have found the option -noflat, which does something similar to what I am looking for, the only thing that unifies all the levels of an image in a single file.

What I would like is to be able to choose, using the -noflat option, to choose only the first level. (I tried -pyramid-resolutions but it seems it is not the option)

I attach screenshots of what I did:


(In fact, in this screenshot you can see an error that there are more levels than allowed, I would only be interested in the first one)


(What I’m looking for is something like this (just yellow))

The error you are seeing is rather odd, having done some quick tests I think that may be a bug when using noflat when there are multiple pyramids with different resolution levels. I will have to do some further tests but it looks as though that would require a fix. Adding an option to select only a single specific resolution level may be something that I can add at the same time but is not available at the moment.

At the minute using the specific series may be the best way to achieve this, though as you said that does require you having to figure out the correct series index.

1 Like

Oh :frowning:. Thank you anyway! I hope to find the way! :slight_smile: