ns the mixture of red, green and blue colors. In this assignment, you will be provided with an image data file, image.dat. The first line in data file contains the height (rows) and width (columns) of the image. The following lines gives the red, green and blue color inte
Part II: Image Representation
An image is an array, or a matrix, of pixels (picture elements) arranged in columns and rows.
RGB is one of the models used in color pixels. In a color image, each RGB pixel is an integer
number which contains the mixture of red, green and blue colors.
In this assignment, you will be provided with an image data file, image.dat. The first line in data
file contains the height (rows) and width (columns) of the image. The following lines gives the
red, green and blue color integer values for each pixel.
The following sample.dat is given as an example:
(The given example can be seen on the picture down)
According to this input file, the image has 4 rows and 2 columns. The pixel at [0][0] has red
value 117, green value 117 and blue value 245.
Write a Java
the given width and height. Then, it'll read red, green and blue color values for each pixel from
data file, and calculate RGB integer value using only bitwise shifting and masking operations.
This is how you'll mix the colors and express the color pixel with one single integer. After
generating RGB value for each pixel, your program will set the RGB value of each pixel with the
computed RGB value. Your program will generate a .png image file as an output.
Sample output: sample.png
(The sample output can be seen on the picture down)
HINTS
• The following Java statement create an image object with the given height, width and image
type of RGB
BufferedImage canvas = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
• The following Java statement updates the RGB value of the pixel located at row y, and
column x of the image.
canvas.setRGB(x, y, rgb);
• The following Java statement created a .png file(image.png) from a BufferedImage object.
ImageIO.write(canvas,"PNG",new File("image.png"));
Here is an image of what a file might look like and the output.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps