The two dimensional array shown below represents the pixel values of a greyscale
ID: 3839238 • Letter: T
Question
The two dimensional array shown below represents the pixel values of a greyscale image. Write a Visual Basic program to calculate the total number of pixels that have value greater than or equal to 128 and also modify the 2D array by replacing all the pixels that have value greater than equal to 128 by 1 and the rest of the 0. class-level two-dimensional array Private intPixels (, ) As Integer = {{15, 18, 30, 200, 234, 37}, {12, 134, 128, 190, 111, 124}, {77, 177, 130, 35, 64, 120, 127}, {123, 234, 228, 190, 211, 12}, {78, 77, 13, 35, 164, 220, 121}}Explanation / Answer
VB Program:
Imports System
Public Class TwoDArray
Public Sub Main()
Dim i,j As Integer
Private Dim intPixels(,) As Integer = {{15,18,30,200,234,37},
{12,134,128,190,111,124},
{77,177,130,35,64,120,127},
{123,234,228,190,211,12},
{78,77,13,35,164,220,121}}
Private Dim count As Integer = 0
For i = 0 To 4
For j = 0 To 6
If intPixels(i,j)>=128 then
count++
intPixels(i,j) = 1
Else
intPixels(i,j) = 0
End If
Next
Next
For i = 0 To 4
For j = 0 To 6
Console.Write(intPixels(i,j)&" ")
Next
Console.WriteLine()
Next
Console.WriteLine("pixels that have value greater than or equal to 128 is:"&count)
End Sub
End Class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.