Steve on Image Processing

July 20th, 2009

A new look for connected component labeling in R2009a - Part 3

I wrote last week about new features in R2009a related to connected component labeling. There are two new functions, bwconncomp and labelmatrix, as well as additional syntaxes for an existing function, regionprops. The features were designed to reduce the amount of memory required to measure geometric properties of connected components (objects) in binary images. In many cases the computational speed is improved as well.

We were concerned that existing users would not discover and use the new features. If users did not change their code, then they would not benefit from the memory and speed improvements.

So we asked the MATLAB M-Lint team for help. M-Lint is the MATLAB code analysis tool that is behind those helpful suggestions that the MATLAB Editor makes about your code. We asked the team to detect the code pattern where the output of bwlabel is passed as the first input argument to regionprops. I showed this coding pattern in Part 1. Here's what the MATLAB Editor now shows for the script is used to create Part 1:

If you hover over the underlined "L" with your mouse, a short message pops up:

And if you click on the short message, you get a full explanation of how to change your code:

As I mentioned in Part 1, the feedback of blog readers was influential in increasing the priority of this issue. I thank you for your many comments on my previous blogs about bwlabel and regionprops.

If you get a chance to use the new features, let us know what you think by commenting on this post.


Get the MATLAB code

Published with MATLAB® 7.8

3 Responses to “A new look for connected component labeling in R2009a - Part 3”

  1. Ken Orr replied on :

    M-Lint is a wonderful thing! We have a whole bunch more articles on M-Lint over at the Desktop blog:

    Click for more information
    Finding the right M-Lint message
    Sharing your M-Lint settings

    -Ken

  2. Sven replied on :

    I am probably one of the target audiences for this change, and yes, I’d say at least 50% of the time I calculate L, it’s simply to send to regionprops.
    When I first upgraded to 2009, I encountered the M-Lint message during an instance where I actually wanted to keep the L matrix. I remember being a little confused about the message - mostly because I was used to the old method. Therefore, I left things as they were, and accepted that my once ‘all green’ functions had some specs of ‘lint-orange’ in them.
    When my data sets grew and I started getting out of memory errors however, I was thankful that the seed was planted by the M-lint messages, so it didn’t take much time to fully understand the new usage, and just browse through my functions updating where necessary.
    Now, my more data-rich (ie, larger) data sets can be processed without memory errors.
    Thanks for the update!

    Cheers,
    Sven.

  3. Steve replied on :

    Sven—Glad to hear it’s working for you. For those cases when you need L, you might consider consider computing it with L = labelmatrix(bwconncomp(BW)). That way you’ll get L with a more memory efficient data type.

    And I’ll make a note to ask the M-Lint team if they can refine the pattern detection so the message won’t be issued if L is used elsewhere in your code.

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.