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:

Concept map

graph TD ND("N-dimensional image") --> S("Slice") S --> M("2D image")

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__chromosomes.tif.
    • Slice the data in along x, y or z using [ Image > Stacks > Orthogonal Views ] or [Ctrl-Shift-H].
    • Explore the effect of wrong calibration:
      • Open image properties: [ Image > Properties… ] or [Ctrl-Shift-P].
      • Change all dimensions to 1 pixel.
      • Observe that the cell now appears as an oval in the Orthogonal Views.
    • Reopen the image in order to have the correct calibration.
    • Slice the data at arbitrary angles using [Plugins > BigDataViewer > Open Current Image]
      • Shift-X/Y/Z: slice along x,y,z.
      • Left button drag: slice along arbitray plane
      • I: toggle interpolation
  • Open the 3D multi-channel image xyzc_8bit_beads_p_open.tif.
    • Use the sliders to explore different dimensions in the data.
    • Use [ Image > Adjust > Brightness/Contrast…] to adjust the display settings of the individual channels.
    • Explore different viewing modes, using [ Image > Color > Channels Tool… ].
    • Explore the voxel dimensions, using [ Image > Properties… ] or [Ctrl-Shift-P].
      • Observe that the voxel dimensions are anisotropic.
    • Crop out the green bead (i.e. “subset” the data).
      • Select the rectangular selection tool and draw an ROI around the green bead.
      • Duplicate the selection, using [ Image > Duplicate ] or [Ctrl-Shift-D].
        • Duplicate hyperstack
        • Channels: 1
        • Slices: 15-25
      • Create a side view of the green bead:
        • [ Image > Stacks > Reslice] or press / to open the reslice menu.
          • Select Top
          • Click OK.
        • Explore and understand the different parameters:
          • Left/Right/Top/Bottom… as if looking from that direction onto the stack on your screen (e.g., Top does not mean to look on the stack from the top as in along the z-direction).
          • Output spacing: the spacing of the pixels along the slicing direction.
          • avoid interpolation
            • uncheck this in order to apply the output spacing and create new pixel by interpolation.
            • check this to ignore the output spacing argument and keep the original pixels.

Additional information (move to main text?)

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.

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.

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

  1. A set of 2D ____ placed on top of each other form a 3D ____.
  2. An ____ voxel size can cause the image to appear ____ when viewing it at an angle.

Solution

  1. 2D slices placed on top of each other from a 3D stack.
  2. An anisotropic voxel size can cause the image to appear deformed when viewing at a certain angle.

True or False

  1. Isotropic image data has voxels of equal XYZ dimensions.
  2. Slicing is the process of sectioning the data, that has more than two dimensions, along defined axes and dimensions.
  3. Reslicing is a term used to indicate repeated slicing.
  4. Images can have 5 dimensions.

Solution

  1. True
  2. True
  3. 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.
  4. True - If we denote width by x, height by y, depth by z, time by t and channel by c, we could have images with dimensions such as: [xy -> 2D], [xyz -> 3D, xyt -> 3D: 2D time-lapse, xyc -> 3D: 2D multi-channel], or [xyzt -> 4D: 3D time-lapse, xyzc -> 4D: 3D multi-channel], or [xyztc -> 5D: 3D time-lapse multi-channel]

Follow-up material

Recommended follow-up modules:

Learn more: