Experiment with the small test matrix, C/C++ Programming

For this assignment, I've provided a data file called 'elevation.mat', which contains the elevation data you'll be working with.  

Type load elevation.mat to get the variable map, which is a matrix of heights (in meters) for a region near Springfield.  You also get a small matrix test that is 10x10, on which you can experiment to make sure your code is behaving sensibly.

As a first step, display the map as a shaded image with


axis equal;

colormap gray;






(0, 0)






Now, here's the function you'll be implementing for this first part.  Every pixel P that is not on the boundary of the image has eight neighbors (above, below, left, right, and four diagonal neighbours).  Let's denote P as the pixel at row r and column c - I'll use (r, c) as shorthand for this. Water follows the path of steepest descent, so we would like to know, for each non-boundary pixel, the direction to the lowest height of the 9 cells around P, including P itself. One way to do that is to store, for each map point (r, c), both the row and the column offsets to its lowest neighbor. We can record these offsets in two matrices (one for rows, one for columns), each containing only the numbers  -1, 0, and +1. Look at the figure to see how these numbers map to the neighbours of a given pixel. As an example, if the lowest neighbour for pixel (r, c) is the pixel directly above, you would store the corresponding offsets of -1 and 0 at location (r, c) in the two offset matrices.

Since border pixels don't have all neighbours defined, let's assign boundary pixels to have both offsets zero.

Thus, for this first part, write and turn in a function that looks like:

function [roffset, coffset] = findLowNhbr(map)

This functions returns two matrices of the same size as map, so that pixel (r,c) in the map has pixel (r+roffset(r,c), c+coffset(r,c)) in the map as its lowest neighbour. 

What to submit: For this part, you do not need to turn in any output -include your m-file in the zip file, and also place the code for the function into the published html, as follows:

type findLowNhbr;   % put this line into the cell for Part 1 in solutionWatersheds.m

You may want to experiment with the small test matrix to check if your code is giving you reasonable results (for this small 10x10 test matrix, you should be able to calculate the offsets by hand).

A note on coding: Try to be as general as possible in your code. One example of this is to use statements such as [nrows,ncols] = size(map); to assign the numbers of rows and columns to variables nrows and ncols.  If you use nrows and ncols instead of the numbers, then you can run your code on any size maps without modification.

Posted Date: 3/29/2013 2:54:04 AM | Location : United States

Related Discussions:- Experiment with the small test matrix, Assignment Help, Ask Question on Experiment with the small test matrix, Get Answer, Expert's Help, Experiment with the small test matrix Discussions

Write discussion on Experiment with the small test matrix
Your posts are moderated
Related Questions
This is what I need help with. "Create a program creates an interface allowing the user to select from some other programs I have made one being a money converter and the other ca

Op e r a t o r O v e r l o a d i n g : W h e n   a n   o p e r a t o r   i s   u s e d   f o r   d i ff e r e n t   op e r a

/*  THIS PROGRAM IS TO ASK USER TO INPUT TWO DATE & PRODUCE A NEW DATE  */ #include #include struct date  {   int dd;   int yy;   int mm;  }; date add(date d1,date d2)    {

Program is to define a class as teacher: Program is to define a class as teacher and collect information about them by using classes and object class teacher   {   pr

Within software languages we have the ability to store information in mail boxes i.e. memory slots which are given names to represent the box. The naming rules are governed by the

Aim: To implement a program to add two polar coordinates using operator overloading. Code:                       #define PI 3.14 class polar {             double

Define the Double Data Type of c Language? The double is used to define BIG floating point numbers and it reserves twice the storage for the number. When the accuracy provided

What if I wish a local to "die" before the close} of the scope wherein it was created? Can I call a destructor on a local if I want to?

Q: But MFC appear to encourage the employ of catch-by-pointer; should I do the similar? A: Depends. If you're utilizing MFC and catching one of their exceptions, by all means, d