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



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