Steve on Image Processing

May 31st, 2007

Upslope area - Plateau detection

In my previous upslope area post, I showed this graphic of pixel flow around North Pond in Milford, Massachusetts:

Notice that pixels in the pond have no arrows. In fact, the pixelFlow M-file I showed previously is unable to compute a pixel flow direction or magnitude for these pixels because they are in a flat region, or plateau. More specifically, pixelFlow returns a flow direction of NaN for any pixel that has no downhill neighbor.

There is a simple way to find all such pixels using morphological erosion. Erosion with a flat structuring element is equivalent to a local minimum operator. If the minimum value of a pixel and its neighbors equals the pixel itself, then we'll call it a plateau pixel.

s = load('upslope_sample_dem');
pond = s.Zm(140:280, 160:230);
plateaus = imerode(pond, ones(3,3)) == pond;
imshow(plateaus, 'InitialMagnification', 'fit')
title('Plateaus')

I'd like to classify plateaus into three types:

  • plateaus with downhill but no uphill neighbors; these are called regional maxima
  • plateaus with uphill but no downhill neighbors; these are called regional minima
  • plateaus with both uphill and downhill neighbors

The Image Processing Toolbox has functions that find regional maxima and regional minima:

max_plateaus = imregionalmax(pond);
imshow(max_plateaus, 'InitialMagnification', 'fit')
title('Max plateaus')
min_plateaus = imregionalmin(pond);
imshow(min_plateaus, 'InitialMagnification', 'fit')
title('Min plateaus')

We can now identify pixels in plateaus with both uphill and downhill neighbors by using logical operators:

mid_plateaus = plateaus & ~(max_plateaus | min_plateaus);
imshow(mid_plateaus, 'InitialMagnification', 'fit')
title('Mid plateaus')

Next time I'll work on a procedure for calculating flow directions for these different kinds of plateau pixels.


Get the MATLAB code

Published with MATLAB® 7.4

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.

  • murat: Hi Steve, I have an rgb image of a kind of cream and it contains some small black particles (black dots). In...
  • Steve: Ernest—Look at setting the FaceColor property. The code for setting that is shown on the page you asked...
  • Ernest Miller: Hi Steve, Understood. However, can you explain how to change the colors? Thanks, Ernest
  • Jan: Hi Steve Very useful code, yet what if I parts of my rotated+translated object are outside the original...
  • Steve: MoHDa—It might be possible. You’ll need to use one of the options that produces closed edge...
  • MoHDa: I have one question about the ROIPOLY: I have an image with stripes, I use the “edge” command for...
  • Steve: Shahn—My November 17, 2006 post shows you how to do it.
  • Steve: Kay-Uwe—Thanks for following up. I am planning to make it easier to use test directories in a package....
  • shahn: Hello Steve Instead of superimposing a star on the image to show the centroide. How would you superimpose a...
  • Kay-Uwe: Having TestSuite.fromPackag e() would be nice to have, but so far using simple “test” subdirs...

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