Question: Challenge Write a routine to rotate an image by 90 degrees. Copy your part III program, and replace the call to negatePGM with a call

Challenge

Write a routine to rotate an image by 90 degrees. Copy your part III program, and replace the call to negatePGM with a call to your rotate90PGM(...) function. Note that the #cols & #rows will change, although the actual pixel array will not. So, you'll need to pass #cols & #rows by reference, so the function can change them. Rotating in place is actually rather complex, so it is simpler to allocate a temporary array, copy the pixels to the temporary array, then move them back to their new locations.

Super Challenge

Modify your rotate90PGM function to rotatePGM, so it can rotate by 90, 180 or 270 degrees. You'll obviously need to pass in the degrees to rotate by, and have it do something sensible if the degrees passed is not evenly divisible by 90.

UberChallenge

Modify your rotatePGM to rotate the image to any arbitrary angle. A few helpful hints. First, you'll either need to write the results to a new, larger PGM image buffer, or else drop any pixels that are rotated to outside the original image size. Second, regardless of whether you expand the image or keep the same size, whenever the image is rotated by anything other than a multiple of 90 degrees, you'll have some pixels at the corners of the output image which do not come from any pixel in the input image; Set these either to black, white, or medium gray. Third, output pixels will generally come from non-integer pixel locations, and you'll have to decide how you want to handle that. An arbitrary-rotator will typically do a weighted average of the nearest pixels to create the output pixels, but you could also simply use either the nearest pixel or some other choice.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!