Steve on Image Processing

April 24th, 2008

Visualizing the output of bwlabel

I often find myself writing small functions that help visualize certain image processing algorithms. For example, my last three posts on bwlabel included identical snippets of code that performed the following steps on a label matrix:

1. Display a binary image using two light shades of gray.

2. Use regionprops to find the location of each labeled object.

3. Superimpose object text labels over each labeled object.

The visualization code, although not complicated, was longer than the algorithm code I was trying to explain. That can obscure the key points of the discussion. It would be nice if there were a single visualization function to call.

In the past, we haven't put algorithm visualization functions into the Image Processing Toolbox. They don't really increase what you can do with the toolbox, and there are many different visualization techniques that might be useful for any given algorithm. Even within a single basic technique, such as my bwlabel visualization, there are many possible variations.

Still, algorithm visualizations can be very useful. We've been talking recently about including "example" visualizations in the toolbox. My idea is that each example visualization should have simple code and a simple syntax. We shouldn't succumb to the temptation to overdesign these examples by supporting lots of options and variations, or by overoptimizing them. The primary purpose of the examples would be to provide inspiration and a starting point for our users to create their own visualizations.

This week I captured the visualization code from my recent posts into a function called VISLABELS, which I uploaded to the MATLAB Central File Exchange. Here's how to use it:

help vislabels
 VISLABELS Visualize labels of connected components
    VISLABELS is used to visualize the output of BWLABEL.
 
    VISLABELS(L), where L is a label matrix returned by BWLABEL,
    displays each object's label number on top of the object itself.
 
    Note: VISLABELS requires the Image Processing Toolbox.
 
    Example
    -------
        bw = imread('text.png');
        L = bwlabel(bw);
        vislabels(L)
        axis([1 70 1 70])

And here's what the example does:

bw = imread('text.png');
L = bwlabel(bw);
vislabels(L)
axis([1 70 1 70])

Do you have your own favorite ways of visualizing algorithms? I encourage you to share them on the File Exchange.


Get the MATLAB code

Published with MATLAB® 7.6

4 Responses to “Visualizing the output of bwlabel”

  1. Brett Shoelson replied on :

    Steve, you inspired me.

    Quite often when I’m analyzing RGB images, I like to look at the color planes individually, and side-by-side with the original and the RGB2GRAY version. (This helps me decide how to segment the image, for instance.) IMTOOL helps with the decision, but there’s no substitute for seeing the images all at once. A while back, I wrote a little function (exploreRGB) to wrap up the visualization. I just posted my utility to the File Exchange.

    Thanks!

  2. Steve replied on :

    Brett—Great!

  3. M Nayan replied on :

    I tried to use “vislabels” function for image visualization. but it coming the following error:
    ??? Undefined function or method ‘vislabels’ for input arguments of type ‘double’.

    I am using Matlab 7.70(R2008)

  4. Steve replied on :

    Nayan—Try downloading the function from the MATLAB Central File Exchange using the link given in the post.


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.