简体   繁体   中英

How can I visualize a large file read in numpy memmap format?

I am trying to read czi format images, But because they need a lot of memmory I tried reading them in memmap file.

Here is the code I used>

import czifile as czi
fileName = "Zimt3.czi"
# read file to binary
file = czi.CziFile(fileName)
imageArr = file.asarray(out="/media/my drive/Temp/temp.bin")

Now imageArr is a variable with dimensons of (9,3,29584,68084,1) in memmap. These are high resolution microscopic images from Carl Zeiss device.

Here is an screenshot of more specifications. ImageArr 规格

I think this means that imageArr contains 9 images with the dimention of (29584,68084,3) But I cant extract this kind of numpy array to visualize as an image. Can you please help me convert (9,3,29584,68084,1) in memmap to (29584,68084,3) images please.

It looks like a very large file. If you just want to visualize it, you can use slideio python package ( http://slideio.com ). It makes use of internal image pyramids. You can read the image partially with high resolution or the whole image with low resolution. The code below rescales the image so that the width of the delivered raster will be 500 pixels (the height is computed to keep the image size ratio).

import slideio
import matplotlib.pyplot as plt

slide = slideio.open_slidei(file_path="Zimt3.czi",driver_id="CZI")
scene = slide.get_scene(0)
block = scene.read_block(size=(500,0))

plt.imshow(scene.read_block())

Be aware that matplotlib can display images if they have 1 or 3 channels. A CZI file can have an arbitrary number of channels. In this case you have to select what channels you want to display:

block = scene.read_block(size=(500,0), channel_indices=[0,2,5])

Another problem with visualization can be if your file is a 3 or 4D image. In this case, slideio returns 3d or 4d numpy array. Matplotlib cannot display 3d or 4d images. You will need to look for a specific visualization package or select a z-slice and/or time-frame:

block = scene.read_block(size=(500,0), channel_indices=[0,2,5], slices=(0,1), frames=(1,2))

For more details see the package documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM