Steve on Image Processing

March 17th, 2008

Multidimensional Image Processing

Every so often someone asks in comp.soft-sys.matlab for a "function like Image Processing Toolbox function foobar that works in 3-D." If I happen to see the post, I will follow up, explaining that foobar itself works just fine in 3-D.

So in case some blog readers have been looking for a "3-D version of foobar," I thought I'd mention it here.

In the late 1990s we started hearing about requests for three-dimensional image processing support. Then on some customer visits in 2000 we heard some demand for four-dimensional support! As a result, the major Image Processing Toolbox upgrade in 2001 (version 3.0) added arbitrary dimension support to the toolbox.

Many Image Processing Toolbox functions implement mathematical operations (such as convolution) that are perfectly well defined in multidimensional spaces. So our strategy was to go ahead and implement multidimensional support for all such functions.

The meaning of the higher dimensions varies with the application and the data. With volumetric data (pixels become "voxels"), the 3rd dimension is spatial, just like the first two. Sometimes a higher dimension is time, or sequence number. And sometimes a higher dimension is spectral, as in color images or multispectral imagery.

At some point after 2001, we began to realize that users weren't discovering the multidimensional capability of the toolbox. Our first attempt to rectify that problem came when we added documentation sections explaining how to use toolbox functions to process sequences. (See "Working with Sequences" in the Users Guide.) Through a kind of happy mathematical coincidence, it turns out that image processing operators working in higher dimensions often just do "the right thing" when you have an image sequence represented in MATLAB as a three-dimensional array.

Let me explain that statement. Suppose you have a 640-by-480-by-100 array, representing 100 images in a sequence. And suppose you want to filter each image in the sequence with the same filter. Well, it turns out that multidimensional convolution of a 640-by-480-by-100 input with a "flat" filter (that is, an M-by-N-by-1 filter) is exactly equivalent to filtering each image in the sequence independently.

For many users, though, this wasn't at all obvious, even if they did discover the multidimensional capability of many of the functions. So that's what led to the "Working with Sequences" section in the doc. But the multidimensional functions can also handle volumetric processing, or other multidimensional applications.

Still, multidimensional support remains somewhat "hidden" in the doc. Here's where you can almost always find it: Look in the "Class Support" section of a function's reference page. For example, here's what the Class Support section for watershed says:

"A can be a numeric or logical array of any dimension, and it must be nonsparse."

Whenever you see that "of any dimension" phrase, you'll know that the function offers multidimensional support.

PS. Don't ask me to send you the code for foobar. I lost it.


Get the MATLAB code

Published with MATLAB® 7.6

7 Responses to “Multidimensional Image Processing”

  1. David Schoppik replied on :

    Good post. It is worth mentioning that many of the operations that “just work” in 3D actually depend on passing things in the appropriate orientation. Further, it can be fairly difficult to troubleshoot whether the output of “foobar” (or, say, fft) when passed a multidimensional array is actually what you wanted — unless you’re lucky enough that all you want to do is smooth/filter each frame of a movie, and you know what a smoothed frame ought to look like.
    I believe the problem is not so much the fact that multidimensional support remains hidden, but rather that it is fairly difficult to think about things in 4D, particularly when what you’d like to happen to your data isn’t entirely obvious.

  2. Steve replied on :

    David—Thanks for your observations.

  3. Shalin replied on :

    Thanks for the post, Steve. I would like to use MATLAB’s deconvblind for 3D deconvoluton of microscopy datasets and had been wondering how to do it. I have few specific questions: a) Could the initial PSF be 3D or of dimension same as image dimension? The help mentions that image can be N-dimensional and what can be data types of image and PSF.

    b) Since the size and shape of PSF are more important then the actual values contained in it, will specifying particular shape as a pattern of 1’s work. e.g. in microscopy the PSFs look like hour-glass or egg-shaped for widefield and confocal imaging, respectively. If I were to represent 3D hour-glass or egg-shape as consisting of 1’s in a cube of zeros, should it work?

  4. Steve replied on :

    Shalin—Yes, the PSF can be three-dimensional in deconvblind. I think it would be fine to start with a pattern of 1s as the initial estimate.

  5. Mark Hayworth replied on :

    Steve:
    When will bwmorph be generalized to 3D? Currently it says “The input image BW can be numeric or logical. It must be 2-D, real and nonsparse.” I have an x-ray CT volume image of a bottle that I would like to thin down to a single sheet using the ’skel’ option of bwmorph. (Normally the bottle wall is thick, like a slab, with a thickness of several voxels and I want just a single voxel thickness). Any workarounds until we get a 3D version of bwmorph? imerode says it works in 3D but it apparently doesn’t have an option to not break apart structures so some parts of the slab could erode away to zero while others would still have a thickness, if the thickness varied from point to point. (BTW Likewise, imdilate apparently lacks a method to prevent two separate blobs from joining - bummer.)

  6. Steve replied on :

    Mark—I don’t know. It won’t happen for R2008b. imdilate and imerode do work in three (or higher) dimensions, but they implement dilation and erosion, which are different from the 2-D ‘thicken’ and ‘thin’ operations offered by bwmorph.

  7. Steve replied on :

    Mark—There is a 3-D skeletonization routine available on the MATLAB Central File Exchange you could try. But now I see from the reviews of that submission that you already found it. I would be very interested to know if the method works for your problem.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Steve Eddins manages the Image & Geospatial development team at The MathWorks and coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.

  • Sana: hi steve, could you explain to me how i would be able to use the dir function, to do a loop through a directory...
  • Nishtha: Sir, I have preprocessed the image in following steps: [1] adaptive histogram equalization [2] thresholding...
  • Kristof: I also strongly support the idea. I have just recently bumped into the problem that im2single was not...
  • Steve: David—I’ m glad you found it useful!
  • David Lalejini: I found your example very useful for finding connected nodes in a large set of input pairs. I start...
  • tommy: Dear Steve, I have a question,please if you are kind to help me regarding the accumulator array dimensions of...
  • Steve: Abc—I don’t know how to distinguish the faces. You might try posting your question in the MATLAB...
  • Manju: well if we have a few ovals within each other like in a cell how do we measure the distance from the center...
  • Steve: Manju—What do you mean? How is each region defined?
  • Manju: if we have 2-3 regions within each other how do we measure the regions of each one?

These postings are the author's and don't necessarily represent the opinions of The MathWorks.