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

2 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!

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.