Help me write my program!

I need help writing this, it is due very soon and I'm very confused!

An image is represented as a two-dimensional array of characters. Elements of the array, called pixels, (picture elements) have values ‘.’ (white) and ‘x’ (black). An image may have a number of arbitrary shaped blobs, contours, isolated pixels, etc. With each white pixel in an image we can associate a certain white area called the connectivity component of that pixel. This is defined as the set of all white pixels that can be connected to the given pixel with a continuous chain of white pixels.

The AreaFill(...) function takes a
specified white pixel in an image and fills
the connectivity component of that pixel with black, as illustrated at right. A pixel is said to be connected to pixels that are adjacent horizontally or vertically.

BEFORE
.....xx........
....x..xx......
....x....xxxx..
....x.......xxx
..x...*........
...X.......xx..
...x..xxx...x.x
...x..x..x.x...
...xxxx...x....
...............


AFTER
.....xx........
....xxxxx......
....xxxxxxxxx..
....xxxxxxxxxxx
..xxxxxxxxxxxxx
...xxxxxxxxxxxx
...xxxxxxxxxx.x
...xxxx..xxx...
...xxxx...x....
...............

1. Write a program using a minimum of three functions that will perform the following tasks:

1)Prompt the user for the name of the image file.
2)Read in the matrix (using a vector of vectors) from the text file of unknown size.
3)Display it to the screen.
4)Ask for the location of the starting pixel.
5)Display the new image to the screen.

2. The function AreaFill(...) that will change the matrix must be recursive. In writing your recursive function, be sure you remain within the image boundaries and do not refill pixels that are already black.
you ask for help, but i looks like you want someone to write it all for you?
The key to defining a recursive function is to define your terminating conditions (otherwise you'd just call the same function over and over again until your program overflowed its stack and crashed.) The terminating conditions here are that you've filled all the way to the edge of the matrix, or you run into a character that is already black. From here, the algorithm looks like this:

//Assume the matrix uses 0-based indexes, [0 to (size-1)]
AreaFill(matrix m, row r, column c)
    //check boundary conditions
    if r < 0 OR r > (height - 1)
        return
    if c < 0 OR c > (width - 1)
       return

    //check if this pixel is already black
    if m[r][c] == 'x'
        return

    //color this pixel back, then do the same operation to all neighbors
    m[r][c] = 'x'
    AreaFill(m, r + 1, c)
    AreaFill(m, r - 1, c)
    AreaFill(m, r, c + 1)
    AreaFill(m, r, c - 1)


Last edited on
thank you!
Topic archived. No new replies allowed.