Problem

Visit www.myprogramminglab.com to complete select exercises online and get instant feedbac...

Visit www.myprogramminglab.com to complete select exercises online and get instant feedback.

Exercise

The file named humphrey-img.txt contained with the website for this book holds raw image data3 of a Martian rock called “Humphrey” that was taken by the Mars Exploration Rover Spirit. The format of this text file is as follows:

First line: single number indicating the height and width of the image (in this case, 461).

Lines 2-462: A row of 461 numbers each separated by a space. Each number represents a pixel in grayscale and ranges from 0 to 255 where 0 is black and 255 is white.

For example, the following data describes a 3 × 3 square where every pixel is white except for a black line along the diagonal from the upper-left corner to the bottom-right corner:

30	255	255255	0	255255	255	0

a) Write a program to read in the data from the file and display it in a JFrame window. To draw a single pixel at coordinate (X,Y), use the drawLine method where the start and endpoints are both (X,Y). For speed, the contents of the file should be read into an array once and the array data used in the paint() method to draw the image.


b) In this particular image, only about 2/3 of the shades of gray are used. For example, if the image consists entirely of shades in the range from 150-160, then the entire image would appear to be almost the same shade of gray. One method to enhance such an image is to scale the shade of each pixel to the entire range from 0 to 255. Pixels that were originally at value 150 would be drawn with the value 0, pixels that were originally 151 would be drawn with the value 25, and so on up to pixels of the shade 160, which would be drawn with the value 255. This technique spaces out the shading so the details are easier to see.

To compute the new shade for a pixel at coordinate (i, j), do the following:

MinOriginalShade is the smallest scale of gray in the original image and MaxOriginalShade is the largest scale of gray in the original image.

Modify your program so that the image is drawn using the scaling technique described above. The brightness and details in the resulting image should be a little bit easier to distinguish.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 18