Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the method lightenImage that modifies the image by changing the values in the instance variable pixels according to the following conditions: The value at

Write the method lightenImage that modifies the image by changing the values in the instance variable pixels according to the following conditions:
The value at position (row, col) is increased by the value at (row +2, col +2), if the position is valid.
If the new value is greater than the value WHITE, the pixel is assigned the value WHITE.
If there is no pixel at position (row +2, col +2), the value is unchanged.
The following shows the contents of the instance variable pixels before and after a call to lightenImage. The bolded values represent the values that could be modified in the image.
Before lightenImage
After lightenImage
0
1
2
3
4
0
1
2
3
4
0
52
203
75
4
0
0
52
255
136
4
0
1
113
255
183
29
73
1
113
255
255
29
73
2
0
125
0
201
61
2
220
160
0
201
61
3
18
48
0
216
181
3
18
48
0
216
181
4
94
0
220
35
0
4
94
0
220
35
0
Complete the method lightenImage below.
/* Increases the value of each pixel at (row, col)
* by the value of the pixel at (row +2, col +2) if
* the position is valid. If the value is greater
* than WHITE, the pixel value is set to WHITE.
* If there is no pixel at (row +2, col +2), the
* value is unchanged.
*/
public void lightenImage() The method must do the following: Accesses all necessary elements in at least one row or one column of pixels
Accesses all necessary elements of pixels (no bounds errors)
Increases the value at index [row][col] by the value found at index [row+2][col+2]
Modifies all appropriate elements of pixels
Assigns WHITE or 255 to elements of pixels that would otherwise have a value greater than WHITE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions