Steve on Image Processing

May 29th, 2009

Locating the US continental divide, part 6 - Final computation and visualization

Today's post in my continental divide series demonstrates the final computational step and shows one procedure for visualizing the Pacific and Atlantic catchment basins.

In my previous post, I modified the DEM (digital elevation model) data set so that its only regional minima were the two oceans.

s = load('continental_divide');
dem_modified = s.dem_modified;
imshow(dem_modified, [-500 3000], 'InitialMagnification', 'fit');

Since the modified DEM has only two regional minima, we expect to get only two catchment basins when we compute the watershed transform.

L = watershed(dem_modified);
max(L(:))
ans =

     2

I'll use label2rgb to display the Pacific catchment basin in green, the Atlantic catchment basin in blue, and the watershed ridge pixels (the continental divide) in red.

pacific = [0.2 1 0.2];
atlantic = [0.3 0.3 1];
ridge = [1 0 0];
rgb = label2rgb(L, [pacific; atlantic], ridge);
imshow(rgb, 'InitialMagnification', 'fit')

In a February blog post, I showed how to overlay one image transparently over another. We can use that technique here to achieve an effect similar to the visualization that Brian Hayes used in his blog post on the continental divide, where the ocean catchment basins are shown shaded with two different colors.

imshow(dem, [-500 3000], 'InitialMagnification', 'fit')
hold on
h = imshow(rgb);
set(h, 'AlphaData', 0.2);

It would be nice if we could make the watershed ridge line itself more visible. For example, if we could use plot, then we could use a thick line. But right now we just have the ridge line represented as zero-valued elements of a raster, instead of the x and y vectors we would need to pass to plot. We could use find to get the coordinates of the ridge pixels, but we wouldn't get them in the right order. One solution is to use bwboundaries to "trace" the zero-valued ridge pixels. Note that I specify 4-connectivity in the call to bwboundaries below. I've found that I get better results using 4-connectivity when tracing a single-pixel-wide stroke that's not a closed loop.

b = bwboundaries(L == 0, 4);
b1 = b{1};  % There's only 1 boundary found here - the ridge line.
x = b1(:,2);
y = b1(:,1);
plot(x, y, 'r', 'LineWidth', 2);

I have one more post planned for this series. Next time I'll gather together all the computational steps in a single, short script.

About this Series

This series explores the problem of computing the location of the continental divide for the United States. The divide separates the Atlantic and Pacific Ocean catchment basins for the North American continent.

As an algorithm development problem, computing the divide lets us explore aspects of data import and visualization, manipulating binary image masks, label matrices, regional minima, and the watershed transform.

  • Part 1 - Introduction. Data import and display. multibandread, imshow.
  • Part 2 - Watershed transform. watershed, label2rgb.
  • Part 3 - Regional minima. imerode, imregionalmin.
  • Part 4 - Ocean masks. binary image manipulation, bwselect.
  • Part 5 - Minima imposition. imimposemin.
  • Part 6 - Computing and visualizing the divide. watershed, label2rgb, bwboundaries.
  • Part 7 - Putting it all together. One script that does everything, from data import through computation and visualization of the divide.

Data credit: GLOBE Task Team and others (Hastings, David A., Paula K. Dunbar, Gerald M. Elphingstone, Mark Bootz, Hiroshi Murakami, Hiroshi Maruyama, Hiroshi Masaharu, Peter Holland, John Payne, Nevin A. Bryant, Thomas L. Logan, J.-P. Muller, Gunter Schreier, and John S. MacDonald), eds., 1999. The Global Land One-kilometer Base Elevation (GLOBE) Digital Elevation Model, Version 1.0. National Oceanic and Atmospheric Administration, National Geophysical Data Center, 325 Broadway, Boulder, Colorado 80305-3328, U.S.A. Digital data base on the World Wide Web (URL: http://www.ngdc.noaa.gov/mgg/topo/globe.html) and CD-ROMs.


Get the MATLAB code

Published with MATLAB® 7.8

2 Responses to “Locating the US continental divide, part 6 - Final computation and visualization”

  1. zhenghui hu replied on :

    Dear Steve

    could you tell me how can construct with the image overlay, which is widely
    used, e.g. in fMRI. Please have a look at these examples,

    http://www.sph.sc.edu/comd/rorden/overlay.html

    The color areas are the activated areas determined from other images
    acquired during activation and these areas are overlaid to gray
    images (background).

    thank you very much.

  2. Steve replied on :

    Zhenghui—I’ve written about image display using transparency at least a couple of times. See my 18-Feb-2009 post and my 20-Aug-2008 post. I also noticed that the “Statistical Overlays” page you explains that its overlay method is based Matthew Brett’s “Slice Overlay” MATLAB routines, and it gives a link.

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.

  • Steve: Kezia—Try imrotate.
  • kezia: steve, how to perform rotation of structuring element by 15 degrees. kindly answer my question. thank u kezia...
  • Steve: Tasha—I only accept comments that are relevant to the particular blog post or are questions or comments...
  • Tasha: Steve,I send you a comment here but still didn’t get any reply yet.I did not see my comment posted here...
  • Steve: Carsten—Thanks for your input.
  • Carsten: Another vote for either imtranslate.m, or at least a blurb in the imtransform help why pure translation...
  • Loren Shure: If you look towards the end of the fftfilt program, you will see that there’s a check to see if...
  • Steve: Sonja—My imwritesize submission on the MATLAB Central File Exchange might be helpful. It was posted...
  • Steve: Grant—Sorry, but it won’t be for R2010a. That development deadline has already passed.
  • Sonja: My publisher is wanting images for a new book to be 300 dpi. Only 5 of the 19 images are 300, the rest are...

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