Slice viewing

Prerequisites

Before starting this lesson, you should be familiar with:

Learning Objectives

After completing this lesson, learners should be able to:
  • Describe the different dimensions image data can have.

  • View and slice images in different dimensions.

Motivation

Apart from the X and Y dimensions, visible in the width and height of an image, image data can have additional dimensions. The most common additional dimensions include:

When viewing the data, different dimensions can be included or excluded, to visualize different aspects of the data. Furthermore, multidimensional image data processes can be applied to one or more dimensions. When doing so, it is important to keep in mind that the different spatial dimensions are not necessarily isotropic. This means that the pixel sizes can be different in X, Y, or Z.

Concept map

graph TD ND("N-Dimensional image") --> S("Show on") S --> M("2D monitor")

Figure


Schematic representation of 2D, 3D, and 5D image data. 2D images are made up of tiny squares called pixels, whereas 3D images are made up of cubes called voxels. Pixels and voxels are not necessarily isotropic, as shown here by squares versus rectangles. In order to see a different part of the image data on a 2D monitor, the image has to be sliced and sometimes rotated.



The word ‘slice’ is often used in different ways. The different ‘layers’ in the z-dimension are referred to as z-slices. Slicing (or subsetting) image data means that part of the image data is selected and ‘sliced out’ to form a new image. This can include selecting one or more dimensions, or just part of a dimension, for example selecting slice 6-12 of the Z-dimension. You can also rotate the data in one of the spatial dimensions and resample the data set to see that data from a different angle, which is sometimes referred to as ‘reslicing’.

Activities


Show activity for:

ImageJ GUI

  • Open the 3D image xyz_8bit_sphere_calibrated.tif.
  • Go to [ Image > Stacks > Orthogonal Views ] or [Ctrl-Shift-H] to see the orthogonal views of the image.
  • Go to [ Image > Properties… ] or [Ctrl-Shift-P] to open the properties window to view the voxel dimensions. If you change all dimensions to 1 pixel, you will see that the ball appears as an oval in the ‘Orthogonal Views’ option.
  • Open the multidimensional image xyzc_8bit_beads_p_open.tif.
  • Use the sliders to explore different dimensions in the data.
  • Use [ Image > Color > Channels Tool… ] or [Ctrl-Shift-Z] to toggle different channels.
  • Go to [ Image > Properties… ] or [Ctrl-Shift-P] to open the properties window to view the voxel dimensions. In this image the voxel dimensions are anisotropic (voxel width and height are not equal to voxel depth).
  • Select the rectangular selection tool and draw an ROI around the green bead.
  • Go to [ Image > Duplicate ] or [Ctrl-Shift-D]. Tick ‘Duplicate hyperstack’, select channel 1 and slice 15-25 to crop out the green bead.
  • With the cropped out green bead as the active image, go to [ Image > Stacks > Reslice] or press / to open the reslice menu. Select ‘Top’ and click OK.

Since the voxels dimensions are anisotropic in this data set, reslicing it would yield rectangular pixels. However, on your screen pixels always appear as squares. Therefore there are two options:

  • new pixels are added by interpolation to keep the proportions such that they follow the calibration of the image.
  • the pixels are kept the same, but we keep in mind that the voxel size is larger in one dimension than in the other (this is stored in the calibration metadata)

With the ‘avoid interpolation’ box NOT selected, the resliced output of a calibrated image will contain new pixels (calculated by interpolation), such that the XYZ proportions in the image follow the image XYZ calibration. However, the resliced output image no longer contains the exact same pixels as the input image, and reslicing it back will give you a slightly different image than the input image that you started with. If you select the ‘avoid interpolation’ box, the output image will have the same number of pixels as the input image. In this case, reslicing it back again will return the exact same input image that you started with. However, the proportions that you see on your screen do not reflect the ‘real’ physical proportions that the original object had.

ImageJ Macro

// Close other open images
run("Close All");

// open image
openImage("https://github.com/NEUBIAS/training-resources/raw/master/image_data/xyzc_8bit_beads_p_open.tif")

// crop out the green bead
makeRectangle(118,142,37,37);
run("Duplicate...", "duplicate channels=1 slices=15-25");
rename("Green bead");

// Reslice green bead from the top, WITH interpolation
run("Reslice [/]...", "output=0.100 start=Top");
rename("Green bead viewed from the top, WITH interpolation")

// Reslice green bead from the top, WITHOUT interpolation
selectWindow("Green bead")
run("Reslice [/]...", "output=0.100 start=Top avoid");
rename("Green bead viewed from the top, WITHOUT interpolation")

run("Tile")

ImageJ Jython

""" Open a multidimensional image and crop out the green bead. Then reslice it from the top """

# import packages
from ij import IJ
from ij.plugin import Duplicator

# Close other open images
IJ.run("Close All")

# open image
beads = IJ.openImage("https://github.com/NEUBIAS/training-resources/raw/master/image_data/xyzc_8bit_beads_p_open.tif")
beads.show()

# crop out the green bead
beads.setRoi(118,142,37,37)
green_bead = Duplicator().run(beads, 1, 1, 15, 25, 1, 1) # int firstC, int lastC, int firstZ, int lastZ, int firstT, int lastT)
green_bead.setTitle("Green bead")
green_bead.show()

# Reslice green bead from the top, WITH interpolation
IJ.run(green_bead, "Reslice [/]...", "output=0.100 start=Top");
green_bead_top = IJ.getImage()
green_bead_top.setTitle("Green bead viewed from the top, WITH interpolation")

# Reslice green bead from the top, WITHOUT interpolation
green_bead_top2 = IJ.run(green_bead, "Reslice [/]...", "output=0.100 start=Top avoid")
green_bead_top2 = IJ.getImage()
green_bead_top2.setTitle("Green bead viewed from the top, WITHOUT interpolation")

IJ.run("Tile")

Exercises

Show exercise/solution for:

ImageJ GUI

Open the multidimensional image xyz_16bit_t1-head.tif.

  • Are the voxels in this data isotropic or anisotropic?
  • Reslice the image from different directions, such that you can view the image stack from the side, from the top, and from the front.
  • How do you think one could see the head from 3/4 view? Tip: there is a function called ‘rotate’ in ImageJ ([Image > Transform > Rotate]).

Solution

  • [File > Open…] xyz_16bit_t1-head.tif
  • Use [Image > Properties ] to view the voxel dimensions. In this case the voxels are isotropic (pixel width = pixel height = voxel depth).
  • [Image > Stacks > Reslice [/]…] or press / opens the Reslice menu.
  • Select ‘Top’ in the ‘Start at:’ drop-down menu to reslice the image from the top and view the head from above.
  • Select ‘Left’ in the ‘Start at:’ drop-down menu to reslice the image from the left and view the head from the front.
  • Tick the ‘Rotate 90 degrees’ button to rotate the output image (you can use this when reslicing from the left, so that the top of the head remains pointing upwards.)
  • When viewing the head from the top, you can select [Image > Transform > Rotate]. Select 45 degrees and ‘Enlarge Image’ and say yes to ‘Process Stack?” question. If you now reslice again from the top, you will see the head in 3/4 view.

ImageJ Macro

  • Open the multidimensional image xyz_16bit_t1-head.tif.
  • Reslice the image from different directions, such that you can view the image stack from the side, from the top, and from the front.
  • How do you think one could see the head from 3/4 view? Tip: there is a function called ‘rotate’ in ImageJ ([Image > Transform > Rotate]).

Solution

// This macro opens the head image stack and reslices it to view it from different angles (side, top, front, and 3/4 view)
// Close other open images
run("Close All");

// open head image stack
open("http://imagej.net/images/t1-head.zip");
rename("Head viewed from the side");

// Reslice the head image stack to view the head from the top and from the side
run("Reslice [/]...", "output=1.500 start=Top"); // view head from the top
rename("Head viewed from the top");
run("Reslice [/]...", "output=1.500 start=Left"); // view head from the front
rename("Head viewed from the front");

// Rotate the head stack that is viewed from the top and reslice to obtain 3/4 view
selectWindow("Head viewed from the top");
run("Duplicate...", "duplicate");
run("Rotate... ", "angle=45 grid=1 interpolation=Bilinear enlarge stack"); // rotate the stack
run("Reslice [/]...", "output=1.500 start=Top");
rename("Head in 3/4 view");

run("Tile");

ImageJ Jython

  • Open the multidimensional image xyz_16bit_t1-head.tif.
  • Reslice the image from different directions, such that you can view the image stack from the side, from the top, and from the front.
  • How do you think one could see the head from 3/4 view? Tip: there is a function called ‘rotate’ in ImageJ ([Image > Transform > Rotate]).

Solution

# This jython script opens the head image stack and reslices it to view it from different angles (side, top, front, and 3/4 view)

# import classes
from ij import IJ
from ij.plugin import Slicer

# Close other open images
IJ.run("Close All")

# open head image stack
head = IJ.openImage("http://imagej.net/images/t1-head.zip")
head.show() # shows head from the side
head.setTitle("Head viewed from the side")

# Reslice the head image stack to view the head from the top and from the side
IJ.run(head, "Reslice [/]...", "output=1.500 start=Top") # view head from the top
head_top = IJ.getImage()
head_top.setTitle("Head viewed from the top")
IJ.run(head, "Reslice [/]...", "output=1.500 start=Left rotate") # view head from the front
head_front = IJ.getImage()
head_front.setTitle("Head viewed from the front")

# Rotate the head stack that is viewed from the top and reslice to obtain 3/4 view
head_top2 = head_top.duplicate()
IJ.run(head_top2, "Rotate... ", "angle=45 grid=1 interpolation=None enlarge stack") # rotate the stack
IJ.run(head_top2, "Reslice [/]...", "output=1.500 start=Top")
head_three_quarter = IJ.getImage()
head_three_quarter.setTitle("Head in 3/4 view")
head_three_quarter.show()

IJ.run("Tile")

Assessment

Fill in the blanks

Solution

  • 2D slices placed on top of each other from a 3D stack.

Choose the correct answer

Solution

  • In a non-calibrated image, a spherical object will appear compressed in the z-dimension when the sampling in Z is lower than in XY.
  • In a calibrated image, a spherical object will appear round in the z-dimension when the sampling in Z is lower than in XY. However, keep in mind that this may depend on the settings of the software that you are using to view the data. In ImageJ, using the ‘orthogonal views’ command will scale and interpolate the data according to the calibration, thereby stretching the z-dimension to match with the true proportions of the object.

True or False

Solution

  • Isotropic image data has voxels of equal XYZ dimensions. True
  • Slicing is the process in which a multidimensional image is divided in smaller images. True
  • Reslicing is a term used to indicate repeated slicing. False. Typically, the term reslicing refers to resampling volumetric data from a different direction, such that the resulting image stack is a rotated version of the original stack.
  • Images are characterised by 2 dimensions or more. True, if we note width by x, height by y, depth by z, time by t and channel by c, we could have images characterised by [xy -> 2D] dimensions, or [xyz -> 3D/Z-stack, xyt -> a time-lapse, xyc -> multiple channels], or [xyzt -> 3D time-lapse, xyzc -> 3D with multiple channels], or [xyztc -> 3D time-lapse with multiple channels]

Follow-up material

Recommended follow-up modules:

Learn more: