Question: Write the method countBlackPixels that returns the number of pixels in the image that contain the value BLACK. For example, if pixels contains the following

Write the method countBlackPixels that returns the number of pixels in the image that contain the value BLACK. For example, if pixels contains the following image:
0
1
2
3
4
0
52
203
75
4
0
1
113
255
183
29
73
2
0
125
0
201
61
3
18
48
0
216
181
4
94
0
220
35
0
The call to countBlackPixels would return 6 because there are 6 pixels that have the value BLACK.
Complete the method countBlackPixels below.
/* Returns the total number of black pixels in the image.
*/
public int countBlackPixels() The method must do the following: Accesses all entries in pixels (no bounds errors)
Compares an element in the array with BLACK or with 0 during traversal
Initializes and increments a counter
Returns the correct count of the number of black pixels in pixels

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!