Advertisement

Rescaling images and pixel (an)isotropy

Posted by , on 2 March 2023

This blog post shows the importance of rescaling 3D image data and what anisotropy of pixels/voxels has to do with it. We will see which different options exist to rescale an image as well as their advantages and limitations. We will also apply a commonly used segmentation algorithm, Voronoi-Otsu-Labeling, on the original and the rescaled data to see the difference.

Voxel isotropy as a precondition for many algorithms

During Image Acquisition, physical limitations and the configuration of the microscope typically lead to a different voxel size in x and y compared to z. The voxels are anisotropic. However, some filtering and segmentation algorithms, like Voronoi-Otsu-Labeling, and also quantitative measurement methods may have isotropic voxel size as precondition. If these preconditions are violated, the results can be misleading or even wrong.
For this reason, the proper scaling of your 3D dataset is an important preprocessing step for the development of your image analysis workflow.

Often you can already see that your voxels are anisotropic when opening your dataset. In this blog post we will explore a dataset from Ozpolat, B. et al licensed CC BY 4.0.

It shows cells with marked membranes and nuclei of the marine annelid Platynereis dumerilii, but here we only use a single channel.
For image visualization and scaling, we use napari in this blog post.

x-y-planey-z-plane
This image has an empty alt attribute; its file name is 20230216_original_unrescaled1-1024x549.pngThis image has an empty alt attribute; its file name is 20230216_original_unrescaled2-1024x549.png
The napari graphical user interface when opening the tif-file of a single timepoint and channel of the “Platynereis dumerilii” dataset in 3D view.

In the image on the right, the y-z-plane is visualised but in a squeezed way.

Note: You can follow the demonstrated workflow in the related jupyter notebook here.

The voxel size of the image data is

voxelsize_x = 0.1596665040315075
voxelsize_y = 0.1596665040315075
voxelsize_z = 1.5

This information was derived from the czi-file and can also be found in our jupyter notebook.

As you can see, the voxels are nearly 10x bigger in z than in x & y.

Requirements

In this blogpost the following napari-plugins are used/mentioned:

Note: I would recommend to install devbio-napari. It is a collection of Python libraries and Napari plugins maintained by the BiAPoL team, that are useful for processing fluorescent microscopy image data. It contains all of the mentioned napari-plugins. If you need help with the installation, check out this blogpost.

Layer Details and Visualisation adjustment in napari

We can see our image shape when going to Tools/Utilities and selecting Layer Details:

In this case, our image shape is displayed in the top right corner

We can easily fix the visualization by going to Tools/Utilities selecting Set_voxel size like this:

and then typing in the voxel size in x, y and z:

We receive the following change in displaying of our data:

x-y-planey-z-plane
This image has an empty alt attribute; its file name is 20230216_original_displaying_changed1-1024x547.pngThis image has an empty alt attribute; its file name is 20230216_original_displaying_changed2-1024x547.png
With the adjustment of the displaying of the image to its voxel size, the y-z-plane looks more reasonable.

Hereby, we only modified the visualisation and did not actually adjust the voxel sizes. The image has still the same shape which we can check again in Layer Details:

In fact, if you open a proprietary image file using a napari-plugin, like napari-aicsimageio, this change of displaying is often already automatically applied.

When we rescale the image, we are also changing the image shape and we can do this by down- or upscaling.

The difference between down- and upscaling

During downscaling, information is reduced and the image shape is reduced, whereas during upscaling new voxels interpolated from the existing ones are added to reconstruct the image. Hereby no new information is created, but the image shape is increased.

For down- and upscaling, we need to use scaling factors.

Schematic explaining the difference between down- and upscaling.

Scaling in napari using clesperanto

We will see in this section one example of scaling in napari using clesperanto. In the jupyter notebook you can also see other possible ways.

First, we open under Plugins the clEsperanto: Assistant. Now you can find under Transform the clesperantoscale function

Scaling using the image voxel size

First, we have a look at rescaling using the image voxel size.Here, we are doing both down- and upscaling at the same time: downscaling in x and y (voxelsize < 1), while upscaling in z (voxelsize > 1)

The rescaled image looks like this:

x-y-planey-z-plane
This image has an empty alt attribute; its file name is 20230222_rescaled1-1024x547.pngThis image has an empty alt attribute; its file name is 20230222_rescaled2-1024x550.png
When we rescale the image using its voxel size, we are downscaling in x and y. This results in an information loss.

Basically, you can see that rescaling leads to an adjustment of the image to better fit the size of the object being observed. Nevertheless, during rescaling using the voxel size, there is an information loss because of the downscaling in x and y.

To illustrate this information loss better, you can see here one slice of the dataset (2D) which was rescaled with the following scaling factors

Progressive loss of information with further downscaling in x and y. Here, one x-y-plane of the “Platynereis dumerilii” dataset is used.

To sum this up, if you scale an image with its voxel size, the resulting image has a voxel size of 1 (µm). And if you scale an image with voxel size/2, the resulting image will have a voxel size of 2 (µm). And with larger voxel size, we loose more and more information.

Upscaling

If we don’t want to loose any information, we can also upscale our image. One reasonable idea would be using the voxel size of x & y as a reference like this:

  • scalingx = x/x = 1
  • scalingy = y/x = 1
  • scalingz = z/x = 9.43

The result looks like this:

x-y-planey-z-plane
This image has an empty alt attribute; its file name is 20230223_upscaling1-1024x534.pngThis image has an empty alt attribute; its file name is 20230223_upscaling2-1024x534.png
When we upscale the image, voxels interpolated from the already existing ones are added (see y-z-plane).

Demonstration of how anisotropic voxels can manipulate measurements

As already mentioned, some algorithms need isotropic voxels in order to perform correctly. One example of a segmentation algorithm is Voronoi-Otsu-Labeling. Now we will investigate which time is needed to apply Voronoi-Otsu-Labeling on the anisotropic, the voxel size-scaled and the upscaled image and look at differences of the output.

Voronoi-Otsu-Labeling

We select under Label Voronoi-Otsu-labeling(nsbatwm) and can now modify the spot_sigma and the outline_sigma. I chose spot_sigma = 10 and outline_sigma = 5 (the unit for this library is voxels):

And depending on if we apply this algorithm to the anisotropic, the voxel size-scaled and the upscaled image, the time differs:

ImageTime for Voronoi-Otsu-Labeling [in seconds]
Anisotropic 13
Rescaled using voxel size0.4
Upscaled144
Overview on needed time for Voronoi-Otsu-Labeling on different images (computation see jupyter notebook)

You can see why upscaling can lead to memory and storage problems and why downscaling is the more often used method.

Now lets have a look on the segmentation result of the anisotropic and the upscaled image:

Voronoi-Otsu-Labeling on the original anisotropic (left)and the upscaled isotropic image (right)

If we compare the result of Voronoi-Otsu-Labeling on the anisotropic and the upscaled image, we can see that the scaling has an influence on the performance of the algorithm.

Summary

In summary, when choosing between up- and downscaling there are advantages and limitations to both of them:

scalingdownup
advantagefaster,
less storage needed
no information lost
disadvantageinformation is reduced which could be important,
less details visible (which are maybe not needed for cell segmentation anyway),
the amount of information does not increase through interpolation,
slower,
might not fit into RAM or GPU memory
Advantages and disadvantages of up- and downscaling.

Which one to choose depends on the individual usecase.

Feedback welcome

Some of the napari-plugins used above aim to make intuitive tools available which are commonly used by bioinformaticians and Python developers. Moreover, the idea is to make those accessible to people who are no hardcore-coders, but want to dive deeper into Bio-image Analysis. Therefore, the feedback from the community is important for the development and improvement of these tools. Hence, if there are questions or feature requests using the above explained tools, please comment below, in the related github-repo or open a thread on image.sc. Thank you!

Acknowledgements

I want to thank Dr. Robert Haase as the developer behind the tools shown in this blogpost. This project has been made possible by grant number 2022-252520 from the Chan Zuckerberg Initiative  DAF, an advised fund of the Silicon Valley Community Foundation. This project was supported by the Deutsche Forschungsgemeinschaft under Germany’s Excellence Strategy – EXC2068 – Cluster of Excellence “Physics of Life” of TU Dresden. 

Reusing this material

This blog post is open-access, figures and text can be rused under the terms of the CC BY 4.0 license unless mentioned otherwise.

1 Star (3 votes, average: 1.00 out of 1)

doi: https://doi.org/10.1242/focalplane.13308

Tags: , , , ,
Categories: Bio-image Analysis with Napari, How to, Blog series

Leave a Reply

Your email address will not be published. Required fields are marked *

Get involved

Create an account or log in to post your story on FocalPlane.

More posts like this

How to
Blog series

Filter by