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

15 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.

  8. Roman replied on :

    Steve, two years after Mark’s post about bwmorph in 3D I am also wondering the same thing… I have a 3D matrix of BW objects that I would like to clean up using ‘clean’ and ‘spur’ in 3D. I guess it wouldn’t be too hard to write this myself by labeling objects and counting how many voxels belong to each one, but it seems so basic that I was expecting Matlab to have it.

  9. Steve replied on :

    Roman—bwmorph is a very old function that dates back to version 1 in 1993. There are aspects of its original interface (parts of which are no longer documented) and implementation (heavily lookup-table based) that force 2-D operation. It also supports operations that aren’t well defined in 3-D. (I would include ‘spur’ in that set.)

    I think we should take a fresh look at this function and modernize it, possibly by providing parts of its functionality as new functions that support multidimensional operation.

    Regarding your desire to use ‘clean’ in three dimensions, you can get this effect by calling bwareaopen.

  10. Roman replied on :

    thanks… can i also suggest a largest inscribed box in addition to the smallest inscribing box, to the regionprops function? seems like another basic and useful thing that is missing.

  11. Steve replied on :

    Roman—Thanks for the suggestion. Do you have a specific use case in mind for the smallest incribed box measurement?

  12. Roman replied on :

    Steve,

    I also wanted to ask you, is there some good way to ensure 3D connectivity between my objects? For example, my 3D BW matrix is a collection of cells that make up a thrombus. I don’t want anything just floating in free space, so I would like to impose a constraint that everything must be connected (no disconnected objects). Any advice? Thanks

  13. Roman replied on :

    if you mean an application for the *largest* inscribed box, yes I have several:
    1) when i was working on my phd, i received Xray scans of a sample that was contained within a circular holder. i needed to do a flow dynamics simulation through the geometry obtained from the xray. my simulation uses periodic boundary conditions, and i wanted to model an “infinite” sample in an directions. so pretty much I needed to cut out the largest usable rectangular piece of the image that was contained within the circular holder… in that case the problem was simpler, because you could solve it analytically, and then just fit the circle to the holder, find its radius and apply the formula

    2)my project now, as i said before, involves imaging a thrombus that is forming a blood vessel of a mouse. so after i do my image filtering and segmentation, i am left with an odd shaped porous object. i am interested in measuring its porosity. the mask that i have for the *whole* object is a signal that comes from a florescent marker in the blood, but the problem is that it encompasses a pocket of fluid under the thrombus (which i don’t want to include in my calculation of porosity).

    so my solution is again, fitting a largest box that fits inside of the bw objects (cells), and measuring the porosity inside of that box. maybe there is some way to isolate to draw a perimeter around all of my bw objects, and then filling in the holes to make a new mask, but i don’t know how to do the former part.

    in any case, later on in my project, if i want to do flow through an ‘infinite’ thrombus, to get its permeability for example, i will again need the largest 3d rectangular cutout from inside of the thrombus. so the largest inscribed box is very useful for people like me, who use the results of image processing for simulation.

  14. Roman replied on :

    i’ve seen files on matlab central that will fit the smallest triangle/circle/rectangle about a group of objects or points, but they are always set mathematical shapes. whereas, if i was going to make a new mask for my thrombus, i need a free shape of minimal area, that will envelope all of my bw objects… and that seems like a project within itself. so the easier solution to do the maximum inscribed box inside of the not so accurate mask that i already have.

  15. Steve replied on :

    Roman—Thank for your input on uses for the largest incribed box.


MathWorks
Steve Eddins is a software development manager in the MATLAB and image processing areas at MathWorks. Steve coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.

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