svs format for medical image processing

What is the SVS data format?

TIFF (Tagged Image File Format) is a file format for storing images. TIFF files support multiple "pages" or images and a variety of storage formats and compression methods. One such storage format is called the Tiled TIFF storage format.

        Tiled TIFF: A Tiled TIFF image consists of many square tiles of the same size (usually 256×256 pixels). The advantage of the Tiled format is that it can efficiently load and display very large images by loading only those images that are absolutely necessary, rather than loading a single, large (huge), monolithic image.

        SVS: An SVS file is a Tiled TIFF image that has some additional pages (images) that include a slide label, overview image, and a few smaller, scaled copies of the scanned slide.

We use the term "Whole Scan Image" (WSI) to refer to any image format that contains a region of interest (ROI) scanned from a microscope slide. Full scan images are usually very large. The image pixels are about 100,000×100,000, and the size of the picture is generally between 60M-1.5G . These files are too large to fit into the memory of most computers. Therefore, traditional image formats such as jpg, png, and bmp cannot be used to store such pictures. Tiled TIFF file proposes to divide these images into small square "tiles".

There are online pictures in the OpenSlide Demo .

Three different file formats may be created for whole scan images(WSI).

  • Deep Zoom
  • Tiled TIFF (SVS)
  • Easy Zoom (SZI)

  Convert SVS to common format

1. OpenCV attempt failed: svs file size out of range ×

“ cv2.error: OpenCV(3.4.2) /io/opencv/modules/imgcodecs/src/loadsave.cpp:74: error: (-215:Assertion failed) pixels <= (1<<30) in function 'validateInputImageSize' ”,

 2. OpenSlide(openslide-python) : https://openslide.org/
OpenSlide is an open source C library with a python interface, which is very easy to use. For the specific use of openslide, you can use Baidu yourself. Here is a good link: https://blog.csdn.net/weixin_41787032/article/details/79817926

# 将.svs转化成.tif
import openslide
import numpy as np
import scipy.misc
 
test = openslide.open_slide('test.svs')
 
img = np.array(test.read_region((0, 0), 0, test.dimensions))
scipy.misc.imsave('test.tif', img)

 Disadvantages: When saving the entire high-resolution image, the size of the image will increase by multiples (it is stored in tiff format, which is about ten times larger, but if it is in jpg format, the image will indeed be small, but it is a lossy compression, consider PNG is also a good choice), because the dimensions under level=0 are taken, so that the maximum resolution of the picture can be maintained, but at the same time, if the picture is larger or the performance of the computer is slightly lower, the computer may Stuck, or reported a MemoryError error.

3. libvips(pyvips) : http://jcupitt.github.io/libvips/API/current/Examples.md.html
libvips is also a C library, but it also has a python interface called pyvips, please refer to the official documentation for usage: https ://libvips.github.io/pyvips/.

Here is the code:

import pyvips
 
img = pyvips.Image.new_from_file('test.svs', access='sequential')
img.write_to_file('test.tif')

        Pros: Direct read and then store. There will be no failure to store, that is, there will be no phenomenon such as a memory error that will cause storage failure.

        Disadvantage: The size of the picture after storage still becomes very large.

 Display of SVS

1. Use the pyvips library to convert the svs file into a dzi file format and save it:

import pyvips
 
img = pyvips.Image.new_from_file('test.svs', access='sequential')
img.dzsave('test')

After executing the above code, two files will be generated, namely: test.dzi, test_files, the former is a single file, the latter is a folder, which stores slices of svs files at different resolutions, and the files in test.dzi The content is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<Image xmlns="http://schemas.microsoft.com/deepzoom/2008"
  Format="jpeg"
  Overlap="1"
  TileSize="254"
  >
  <Size 
    Height="32893"
    Width="46000"
  />
</Image>

2. Download the OpenSeaDragon library and generate html files

① To display the dzi file, there is a java library called OpenSeaDragon (https://openseadragon.github.io/examples/tilesource-dzi/), download OpenSeaDragon and unzip it in any local folder you like , renamed to: openseadragon.

②An html file is also needed (source: https://blog.csdn.net/qianqianyixiao1/article/details/50420398), named test.html here, the content is as follows:

 
<!DOCTYPE html>
<html lang='en'>
 
<head>
    <meta charset='UTF-8'>
    <title>OpenSeadragon_Demo0</title>
    <script src='../openseadragon.min.js'></script>
</head>
 
<body>
    <div id='openSeadragon1' style='width:1850px; height:960px;'></div>
</body>
 
 
<script type='text/javascript'>
    OpenSeadragon({
        id: 'openSeadragon1',
        prefixUrl: '../images/',
        tileSources: {
            Image: {
                xmlns: 'http://schemas.microsoft.com/deepzoom/2008',
                Url: './test_files/',
                Overlap: '1',
                TileSize: '254',
                Format: 'jpeg',
                Size: {
                    Height: '32893',
                    Width: '46000'
                }
            }
        }
    });
</script>
 
</html>

Remember to replace the data inside with the data in the dzi file, and then you can delete the test.dzi file.

3. Put the test.html and test_files folders in the same directory (here my directory is named: zoomFiles), and then put them into the openseadragon folder, and then you can click the test.html file, and click on the webpage The corresponding result can be displayed.

Guess you like

Origin blog.csdn.net/weixin_45958695/article/details/127769773