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

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question

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 program that reads from the given input file and creates an RGB image object with 
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.

Page
2
of 5
ZOOM
+
Part Il: 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:
4 2
01110101,01110101,11110101 01110101,01010111,11110101
01110101,11010101,01010101 11010101,01010101,01010101
11000101,00011101,01110101 01100101,11110111,00100101
11110101,01110101,11010101 11110101,01111101,11110001
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 program that reads from the given input file and creates an RGB image object with
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
Transcribed Image Text:Page 2 of 5 ZOOM + Part Il: 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: 4 2 01110101,01110101,11110101 01110101,01010111,11110101 01110101,11010101,01010101 11010101,01010101,01010101 11000101,00011101,01110101 01100101,11110111,00100101 11110101,01110101,11010101 11110101,01111101,11110001 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 program that reads from the given input file and creates an RGB image object with 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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning