Steve on Image Processing with MATLAB

Image processing concepts, algorithms, and MATLAB

R2013a – Looking around in MATLAB

The first MathWorks general product release of the year, R2013a, shipped a couple of months ago. I've already mentioned it once here in my 12-Mar-2013 post about the new MATLAB unit test framework.

With each new release, I peruse the release notes for MATLAB to see what things I find particularly interesting. (This helps me remember which product features have actually been released, as opposed to still being in development. My memory needs all the help it can get.)

The first thing to note is the reappearance of the table of contents for navigating in the Help Browser and in the online Documentation Center. This is a direct result of helpful feedback we received from many of you about the R2012b release.

My favorite "make-it-go-faster-without-sacrificing-accuracy" people (the MATLAB Math Team, that is) have been busy again. People with computers based on Intel or AMD chips using the AVX instruction set should see their calls to fft speed up. Anybody running permute on 3-D or higher-dimensional arrays should also get a nice boost. I've done a lot of development work related to image and scientific format support, so I know that a fast permute can be pretty useful when reading image and scientific data. That's because most of these formats store array elements in the file in a different order than MATLAB uses in memory.

In the small-but-nice category, the MATLAB Math Team also simplified a common programming pattern in my own neck of the woods (image processing). Specifically, it's a bit easier to initial an array of 0s or 1s whose type is based on existing array. Here's an example to illustrate:

clear  % Let's start with a fresh workspace.
rgb = imread('peppers.png');
imshow(rgb)
title('Obligatory image screenshot')

Now I want a 100-by-100 matrix of 0s with the same data type as rgb.

A = zeros(100,100,'like',rgb); % Make a 100-by-100 matrix that's "like" rgb.
whos
  Name        Size                Bytes  Class    Attributes

  A         100x100               10000  uint8              
  rgb       384x512x3            589824  uint8              

My developer friend Tom Bryan really "likes" this (ahem) because it enables much easier solutions to some common programming tasks for users of Fixed-Point Designer.

I have occasionally done a little web scripting in MATLAB, so it's nice to see urlread and urlwrite get a little love. These functions can now handle basic authentication via the 'Authentication', 'Username', and 'Password' parameters.

Do you use a Mac? You can now write MPEG-4 H.264 files using VideoWriter (requires Mac OS 10.7 or later).

A couple of handy new string functions have appeared, strsplit and strjoin. Based on how often users have submitted their own versions to the MATLAB Central File Exchange, I'm sure these will be popular.

out = strsplit(pwd,'\')
out = 

    'B:'    'published'    '2013'

You can now do extrapolation with both scattered and gridded interpolation. For extrapolation with scattered interpolation, use the new scatteredInterpolant. Here's an example I lifted from the doc.

Query the interpolant at a single point outside the convex hull using nearest neighbor extrapolation.

Define a matrix of 200 random points.

P = -2.5 + 5*gallery('uniformdata',[200 2],0);

Sample an exponential function. These are the sample values for the interpolant.

x = P(:,1);
y = P(:,2);
v = x.*exp(-x.^2-y.^2);

Create the interpolant, specifying linear interpolation and nearest neighbor extrapolation.

F = scatteredInterpolant(P,v,'linear','nearest')
F = 

  scatteredInterpolant with properties:

                 Points: [200x2 double]
                 Values: [200x1 double]
                 Method: 'linear'
    ExtrapolationMethod: 'nearest'

Evaluate the interpolant outside the convex hull.

vq = F(3.0,-1.5)
vq =

    0.0031

Disable extrapolation and evaluate F at the same point.

F.ExtrapolationMethod = 'none';
vq = F(3.0,-1.5)
vq =

   NaN

I encourage you to wander over to the R2013a release notes for MATLAB or any other product that you use and see what's new that might be helpful to you.

There are also lots of new things in the image processing and computer vision worlds, of course. I'll look at those next time.




Published with MATLAB® R2013a

|
  • print

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.