In my last Pick, I singled out someone who has contributed widely to image-processing discussions on the CSSM newsgroup. Today, I want to recognize a stalwart contributor to the MATLAB community, both through CSSM and through his numerous submissions
to the MATLAB Central File Exchange. Anyone who has spent time posing or answering questions on CSSM knows of us. And though he has labeled all of his 41 submissions as "pedestrian," most are anything but.
Today's Pick comes to us from us. (Sounds circular, but power-user us apparently doesn't like capitals--or three-letter names!).
In rex: a pedestrian regular expression operator synopsis generator, us has provided a very handy cheat sheet, of sorts, for creating Regular Expressions. For those of you who haven't yet delved the mysteries of regular expressions, they are powerful devices for searching or
manipulating strings. But they can be cryptic to create or to decipher. Us's rex is a single-page reference for writing regular
expressions. The commands can be written to the Command Window, or displayed in a listbox:
Many of us's files are Pickworthy. His functions are broadly useful, and his code is powerful, concise, and well-written.
Give his files a browse--there's something there for everyone!
"What? Another peak finder?" you might say. Some of you may classify this as one of those utilities that has been created by many people over the years,
like sudoku and waitbar. Well, peak finding happens to be something dear to my heart.
I have been using MATLAB for almost 10 years since my first year of graduate school. I initially learned by trying to decipher
my advisor's code. One day, I was struggling to write some code for finding peaks in my data.
% Sample data
t = 0:0.01:10;
x = sin(2*t) - 3*cos(3.8*t);
That's when my advisor showed me his code:
dx = diff(x); % get differences between consecutive points
pkIDX = (dx(1:end-1) >= 0) & (dx(2:end) < 0); % look for slope changes
pkIDX = [dx(1)<0, pkIDX, dx(end)>=0]; % deal with edges
plot(t, x, t(pkIDX), x(pkIDX), 'ro');
This was an eye-opener and was the moment I experienced the power of vector operation for the first time. The way I code in
MATLAB had changed from that point on. ... So when I see "peak finding", it brings back memories.
There are quite a few File Exchange entries for finding peaks (and valleys), including two previous POTW selections: FPEAK and EXTREMA. But I really like peakfinder by Nate. Not only does his code deal with noisy data (my algorithm above will be useless if the signal is noisy), but also
his coding practice is quite solid. He has a great help section, robust error-checking of input arguments, and variable input
and output arguments for ease of use.
xNoise = x + 0.3*sin(40*t); % add a few more bumps
peakfinder(xNoise);
I looked through a few peak finding entries, but I'm sure I may have missed some. Feel free to let me know of others you really
like here.
Many of us who have used or participated in comp.soft-sys.matlab over the years--particularly those of us who have had occasion to solve image processing problems--have come to appreciate
Image Analyst's thoughts on relevant matters.
Recently, Image Analyst had occasion to share his first file through the File Exchange--a demo tutorial on blob analysis. In a nice, well-documented bit of code, IA steps us through an approach to segmenting, and determining the properties of,
some objects in an image. In this case, the image is a sample ('coins.png') that ships with the Image Processing Toolbox.
IA's code shows how one might segment objects of interest (coins) from the background, then use regionprops (my favorite IPT function!) to differentiate nickels from dimes, and dull dimes from shiny ones:
This is a nice demo--very informative, and certainly worth a read. Two thoughts: 1) IA's code uses bwlabel to calculate a connected components matrix of the image as a precursor to calling regionprops. As of R2009a, the new IPT function bwconncomp replaces bwlabel as the preferred approach; it uses significantly less memory, and can be markedly faster! Also, 2) IA shows how one can extract
the specific pixels (PixelIdxList) associated with each object of interest, then calculate statistics on those pixel intensities
to differentiate shiny from dull objects. Note that the fourth syntax of regionprops in the documentation enables one to avoid this step, and instead to operate directly on the original intensity image. Using
this syntax, one can calculate directly the MIN, MAX, or MEAN intensitities--or even the weighted centroids-- of each blob
in the image.
and the standard deviation should be close to one.
myStats.std
ans =
1.0019
How convenient.
As it turns out, this month the File Exchange recently celebrated a major milestone. Allstats has the honor of being the official 10,000-th submission. Congratulations to Francisco and every contributor who made this
possible! Growth of the File Exchange has been absolutely amazing.
If only my retirement account was that impressive! (sigh)
To some of you, this may be old news, but I know that not everyone is up to date on newer features. The new Object Oriented
Programming capability that was introduced in R2008a has been highlighted several times by Loren, Doug, and Steve.
This entry by Stuart provides a nice syntax comparisons between MATLAB and a few of the common object oriented languages (C++,
Java, Python, Ruby). Take a look at the published HTML to read about it and get a quick side-by-side comparison of these languages.
Note: as Stuart mentions in the comments, this is a syntax comparison, and it is not meant for showcasing best practices.
The documentation is a good place to get such info.
I remember lots of A-ha moments in college when I realized the significance of yet another application for Fourier transforms.
For example, calculation of power spectral density in signal processing. The central limit theorem was another pleasant surprise.
This submission stirred those memories: not unlike bumping into an old friend you haven't seen for a long time. Now all I
need is a compelling problem that requires circular or directional statistics so I can truly internalize the value of these
tools for myself.
Philipp first submitted this file in January 2007. There have been a number of review comments over the years. It is currently
rated 4.4 (on the 5 point scale).
Downloads have averaged almost 9 per day over the past month as well. So others clearly appreciate it. I also appreciate that
Philipp recently updated the submission in response to feedback from others. In addition, follow the Acknowledgements trail
to see that Circular Statistics Toolbox (Directional Statistics) was inspired by Circular Cross Correlation which also inspired Fast Circular (Periodic) Cross Correlation. That's social computing. Keep up the great work, everyone.
This week's Pick of the Week takes a turn "out of the box"; rather than select a file, I'd like to highlight new functionality
in MATLAB that allows one to interface with the MATLAB Central File Exchange directly from one's MATLAB Desktop.
As of the current release of MATLAB (R2009b), the Desktop includes a new tool called, appropriately, the File Exchange Desktop Tool. To access the tool, simply browse from the MATLAB 'Start' button to 'Desktop Tools,' and then to 'File Exchange':
From there, you'll be presented with a standard MATLAB window that will allow you to find and grab files from the Exchange.
Suppose you have a set of XY points. You plot them to see how they spread out. You decide a certain clump of points is special.
How do you get MATLAB to know which points you care about? With lasso you can select them with your mouse!
To demonstrate I will use the sunspot example data that ships with MATLAB.
press a KEY to start selection by mouse, LEFT mouse button for selection, RIGHT button closes loop
x =
1836
1837
1848
1870
y =
121.5
138.3
124.7
139
i =
137
138
149
171
centroid = [mean(x) mean(y)]
centroid =
1847.8 130.88
The program prompted me how to start and stop the selection. I left off the semicolon to show the values returned for further
analysis (ie, centroid calculation). The first plot shows the polygon region I selected. The second plot shows the selected
points with a free legend and point counter. Nice!
Note: if you like graphically interacting with your XY points be sure to check out Data Brushing introduced with R2008a.
I recently received an email from a File Exchange user informing me that a GUI I had shared for morphologically processing
images (i.e., morphTool) didn't work. As it turns out, I had neglected to include in the Zip file that I uploaded a couple of functions that were
called internally by morphTool.
I've made the same mistake before, and I've also downloaded File Exchange files that were missing some key functionality.
This email exchange had me thinking about writing a bit of code to automatically create my Zip files, making sure to include
all necessary supporting function files. MATLAB has a depfun command that will thoroughly analyze a function and determine its dependencies, including, by default, functions in MATLAB Toolboxes. It can take a little
while to generate a report, though, and does a lot more work than is necessary just to create a comprehensive Zip file. Alternatively,
one can easily create a dependency report for the current file active in the MATLAB editor by using "Save and Show Dependency Report" from the Tools menu. That approach
is much faster than using depfun (with its default options), but leaves you then to manually evaluate one-by-one each function that your top-level function
calls. As you might guess, it's easy to miss a necessary file when you create your Zip.
Before I started coding, I thought I'd check the File Exchange (wouldn't you?), and I quickly found Malcolm's exportToZip. Malcolm's file uses his own version of depfun (called mydepfun), that smartly uses non-default behavior of depfun to automatically skip files in MATLAB Toolboxes; mydepfun returns the paths to just those files needed for the target Zip file, which is then automatically created.
I tried exportToZip on morphTool; it worked flawlessly--and quickly! And syntactically, it couldn't be easier to use:
zipfilename = exportToZip(funcname,zipfilename)
Oh, and incidentally, a new version of morphTool will go live soon. Thanks, Malcolm--you saved me a lot of time and effort!
Recent Comments