filmov
tv
Python Tutorial: N-dimensional images
Показать описание
----
Now that you can load and plot two-dimensional images let's discuss higher-dimensional datasets.
Images come in all shapes and sizes. This makes them versatile, but also complex.
A standard grayscale image is the simplest type: it's an array that can be indexed by rows and columns.
3D images cover a volume of space rather than just a single plane. This volumetric data is useful because it can better capture the complexities of the human body, but it can be difficult to visualize because it can't be summarized in a single plot.
Color images are also three dimensional. RGB images, for example, have three color channels that, when rendered by matplotlib or other image viewers, express a wide range of colors.
Movies, or time-series data, include a temporal dimension, showing how each element changes over time. Like the planar dimension for 3D volumes, the temporal dimension is put first by convention.
Just as a 2D image is a stack of 1-dimensional vectors, 3D, 4D, and even higher-dimensional images can be thought of as stacks of simpler ones. Let's illustrate this by creating a 3D volume from a few 2D images.
First, we'll load ImageIO and NumPy.
Then, we'll read in three slices of a chest CT scan.
Each of these slices is an array with 512-row elements by 512 column elements.
Now, we can feed a list of these three images into NumPy's stack() function to create a 3D volume.
If we look at our new "vol" array, we see that it contains the third dimension with three elements along with it, but the row and column dimensions are the same as before.
ImageIO's volread() function is capable of reading volumes directly from disk, whether your images are stored in their own folder, or if the dataset is already multi-dimensional.
In this example, we have a folder named "chest data," which contains 50 slices of a 3D volume.
We simply have to pass the folder name to volread(), and it will assemble the volume for us. Since these are DICOM images, the function actually checks the available metadata to make sure that the images are placed in the correct order. Otherwise, it will default to alphabetical order.
Displaying the shape attribute shows us that we have 50 images stacked together.
When analyzing images, keep in mind that the data is only a representation of real, physical space.
The information in your images is limited to the number of elements in it. This is known as the array shape in NumPy and is always available as an attribute.
The amount of space covered by each element is the sampling rate, and it can vary along each dimension. For DICOM images, the sampling rate is usually encoded in the metadata. For other types of image formats, such as JPEG and PNG, you may need to find it elsewhere.
The field of view is the total amount of space covered along each axis. It is the product of the shape and sampling rate. Understanding the difference between these concepts is important, and we'll return to it throughout this course.
Now let's start exploring some 3D volumes!