Read a PGM image, store it in an array, and output it. (There is a zip file of sample_images on the course materials page.) Once you get that working, see if you can get any of the following working:
· Flip an image left-to-right (and write it out)
· Flip and image top-to-bottom (and write it out)
· Do a horizontal derivative (i.e., subtract each pixel from the previous one)
o add 128 (1/2 maxval) to each difference to make it a positive number (remember...pixels should be between 0 and maxval)
(The last one, an image which is a derivate of an image, produces some very interesting results, and is a fundamental process in locating objects in images, as it helps identify all the edges.)
Note 1: because we’re not doing dynamic memory allocation yet, you’ll need to declare an array large enough to hold “any” image. Assume a max size of 512x512 pixels, and simply output an error message if the user gives you an image larger than that. Easiest to have 2 arrays, one for reading into, and one to put the result in.
Note 2: I want you to use a 1-dimensional array for this.
Note 3: VERY IMPORTANT: For very obscure reasons, don't create more than 2 arrays of size 512x512. Otherwise you'll run out of stack space (explanation is very obscure...). If you want more than 2 arrays to work with, put the following at the top of your program:
It's purpose is to make you learn, so it is homework.
The course must have said something about that "PGM" format, i.e. what it has. That should suffice to make it possible for you to write the file input.
You have been told where to store the values; an array.
You have been told to make a function that writes an array to a file in "PGM" format.
You have three "transformations". Each iterates over the "input" array and writes to "output" array. The first two are all about indexing. You can do the addition on the same pass as difference calculation on the third transformation. Make a "int clamp(int)" helper function to ensure that result is in valid range.
You have a logical 2D array implemented with a 1D array. Part of implementation is how you map element (x,y) of 2D into an element z in 1D.
You will reserve 512 elements per "line", but the input may have less. Remember that when you map and iterate.