Java Reference
In-Depth Information
2. The file named humphrey-img.txt contained with the website for this topic holds
raw image data 3 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.
*
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:
3
0 255 255
255 0 255
255 255 0
For example, the following data describes a 3
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:
* 1
2 -
255
OriginalShade
1
i , j
MinOriginalShade
2
N e w S h a d e
1
i , j
2 =
MaxOriginalShade
-
MinOriginalShade
2
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.
3. Write a GUI program that uses the methods in the Graphics class to draw a
smiley face when the window is activated, and a frowny face when the window is
deactivated. This will require use of a WindowListener to detect the activation or
deactivation events.
3 The original raw image data has been cropped and converted to a textual format for purposes of
this project.
1
 
Search WWH ::




Custom Search