File Exchange Pick of the Week

November 20th, 2009

Regular Expressions…a Cheat Sheet!

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!

Comments?


Get the MATLAB code

Published with MATLAB® 7.8

November 13th, 2009

This “Peaks” My Interest

Jiro's pick this week is PeakFinder by Nate Yoder.

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


Get the MATLAB code

Published with MATLAB® 7.9

November 6th, 2009

Segmenting Coins…a Tutorial on Blob Analysis

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.

Nice work, Image Analyst!

Comments?


Get the MATLAB code

Published with MATLAB® 7.9

October 30th, 2009

allstats

Bob's pick this week is Allstats by Francisco de Castro.

The file is simple enough. Given a data set,

x = randn(1000,1);
hist(x,100)

allstats returns a list of statistical values.

myStats = allstats(x)
myStats = 
      min: -3.1289
      max: 2.9371
     mean: -0.06815
      std: 1.0019
     mode: -3.1289
     q2p5: -1.9519
       q5: -1.7128
      q25: -0.73464
      q50: -0.072006
      q75: 0.55077
      q95: 1.6351
    q97p5: 1.8844

The mean should be close to zero,

myStats.mean
ans =
     -0.06815

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)

Comments?


Get the MATLAB code

Published with MATLAB® 7.9

October 23rd, 2009

Object Oriented Programming (MATLAB vs others)

Jiro's pick this week is "Comparison of object oriented code" by our very own Stuart McGarrity.

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.

Comments?


Get the MATLAB code

Published with MATLAB® 7.9

October 16th, 2009

Circular Statistics Toolbox (Directional Statistics)

Bob's pick this week is Circular Statistics Toolbox (Directional Statistics) by Philipp Berens.

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.

Comments?


Get the MATLAB code

Published with MATLAB® 7.9

October 9th, 2009

Colored Area on a Curved Surface

Bob's pick this week is Colored Area on a Curved Surface by Michael Wunder.

This is a nice example of quantitative image analysis. Given a heat map and region of interest based on elevation,

compute the surface area.

See Michael's published example for the step by step details.

Comments?


Get the MATLAB code

Published with MATLAB® 7.10

October 2nd, 2009

Integrating the File Exchange with the MATLAB Desktop

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.

Also, be sure to check out this mini video tutorial demonstrating these new capabilities. And be sure to tell us what you think!


Get the MATLAB code

Published with MATLAB® 7.9

September 25th, 2009

lasso.m

Bob's pick this week is lasso.m by Thomas Rutten.

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.

load sunspot.dat
[x,y,i] = lasso(sunspot(:,1),sunspot(:,2))
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.

Comments?


Get the MATLAB code

Published with MATLAB® 7.9

September 18th, 2009

Easier (and less error-prone) creation of Zip files

Brett's Pick this week is exportToZip, by fellow MathWorker Malcolm Wood.

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!

You gotta love the File Exchange!

Comments?


Get the MATLAB code

Published with MATLAB® 7.8


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • Zach: Hi Doug and Les, I didn’t have a lot of time to mess with this, but I did find a work-around. I plotted...
  • hamed: k
  • Les: @Zach This isn’t exactly what you are looking for but at least it puts all three parameters on the same...
  • Zach: Thanks for your suggestions Doug. I’ll give that a shot and see what happens. I’ve seen many of...
  • Doug: @Zach, I would say to use plotYYY, because that is close to what you want, but using depth as Y makes sense....
  • Doug: @Teja, I think this will work: http://www.mathworks .com/access/helpdesk /help/techdoc/ref...
  • Gify: merry christmas :) nice christmas tree! Regards, Janet Gify
  • Teja: Dear Doug Is there anyway to plot a surface from nonuniform data without meshgrid and griddata? Basically i...
  • Zach: I’m working with geophysical data, so I’d like to produce a depth profile. The y-axis would be...
  • Doug: @Ashok First, please do not use variable names that are MATLAB commands (std and mean). Second, p(j) should be...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.