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

Assignment Help:

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

imagesc(map);

axis equal;

colormap gray;

 

(-1,-1)

(-1,0)

(-1,1)

(0,-1)

(0, 0)

P

(0,1)

(1,-1)

(1,0)

(1,1)

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.


Related Discussions:- Experiment with the small test matrix

Private member functions, P r i va t e Member Functions: A private...

P r i va t e Member Functions: A private member functions can be called by the members of the same class.  Consider the following example.   c l a ss sample

#program, Ask question #Minimum 100 words accepted program for polishin...

Ask question #Minimum 100 words accepted program for polishing jewels#

There are ''''n'''' ants on a ''''n+1'''' leng n, There are ''''n'''' ants ...

There are ''''n'''' ants on a ''''n+1'''' length rod. The ants are numbered from 1 to n and are initially placed at positions starting from position 1 till position n. They are mov

Pointer to an array, Write a method (belonging to the TermStructure class) ...

Write a method (belonging to the TermStructure class) that takes a pointer to an array of bonds and an integer, representing the number of bonds in the array as arguments, and esti

Super ansii prgm, Ask quIn the Byteland country a string "s" is said to sup...

Ask quIn the Byteland country a string "s" is said to super ascii string if and only if count of each charecter in the string is equal to its ascci value in the byteland country as

Procedure-oriented programming, E v o l u t i o n of Software: ...

E v o l u t i o n of Software: In the past stage of programming the software's were developed in Machine language Using binary numbers 1's and 0's.  Later it convert

Program for read a formal expression from standard input, Your program will...

Your program will read two kinds of data from two files: names and predicates. It will read a formal expression from standard input and check whether that expression is syntactical

Stack and queues, Using Figure 10.2 as a model, illustrate the result of ea...

Using Figure 10.2 as a model, illustrate the result of each operation in the sequence ENQUEUE.Q; 4/, ENQUEUE.Q; 1/, ENQUEUE.Q; 3/, DEQUEUE.Q/, ENQUEUE.Q; 8/, and DEQUEUE.Q/ on an i

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd