Write a static method blur (double [] [] picture) that you could use on a part of a picture file to obscure a detail such as a person's face or a license plate number. This method computes the weighted averages of the values in picture and returns them in a new two-dimensional array. To find a weighted average of a group of numbers, you count some of them more than others. Thus, you multiply each item by its weight, add these products together, and divide the result by the sum of the weights.
For each element in picture, compute the weighted average of the element and its immediate neighbors. Store the result in a new two-dimensional array in the same position that the element occupies in picture. This new array is the one the method returns.
The neighbors of an element in picture can be above, below, to the left of, and to the right of it, either vertically, horizontally, or diagonally. So each weighted average in the new array will be a combination of up to nine values from the array picture. A corner value will use only four values: itself and three neighbors. An edge value will use only six values: itself and five neighbors. But an interior value will use nine values: itself and eight neighbors. So you will need to treat the corners and edges separately from the other cells.
The weights to use are:
The element itself has the highest weight of 4, the horizontal and vertical neighbors have a weight of 2, and the diagonal neighbors have a weight of 1.
For example, suppose the values in picture are
and the new array is called result. In assigning weights, we will arbitrarily start with an element and consider neighbors in a clockwise direction. Thus, the interior value in result [1] [1] is equal to
To arrive at this equation, we started with the element at picture [1] [1] and then, beginning with the neighbor to the right, we considered neighbors in a clockwise direction. The corner value in result [0] [0] is equal to
Note that picture [0] [0] has fewer neighbors than an interior value such as picture [1] [1]. The same is true for an edge value such as picture [0] [1]. Thus, the edge value in result [0] [1] is equal to
The final array, result, would be
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Java: Intro. to Prob. Solv... (Looseleaf)
Additional Engineering Textbook Solutions
Starting Out with Java: Early Objects (6th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Problem Solving with C++ (9th Edition)
Digital Fundamentals (11th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
- Write a static method blur(double[][]picture) that you could use on a part of a picture file to obscure a detail such as a person’s face or a license plate number. This method computes the weighted averages of the values in picture and returns them in a new two-dimensional array. To find a weighted average of a group of numbers, you count some of them more than others. Thus, you multiply each item by its weight, add these products together, and divide the result by the sum of the weights. For each element in picture, compute the weighted average of the element and its immediate neighbors. Store the result in a new two dimensional array in the same position that the element occupies in picture. This new array is the one the method returns. The neighbors of an element in picture can be above, below, to the left of, and to the right of it, either vertically, horizontally, or diagonally. So each weighted average in the new array will be a combination of up to nine values from the array…arrow_forwardjava Write a method that takes rows and columns as a parameter, and returns a 2D array of the designated size, filled with empty Strings. I currently have public static String[][] createArray(int row, int col) { String[][]arr=new String[row][col]; return arr; } but it returns the 2d array filled with null?arrow_forwardWrite the method printTail() method that accepts an array of integers and an integer index as parameters and prints all the array elements starting from the index passed. For example if printTail(x,5) is invoked, it should print all the elements of the array x starting at x[5].arrow_forward
- Write a helper method, with the signature eliminateZerosinArray[int[]): int[], that takes a single dimensional int array as an argument, and returns a new array that only contains the original values that are not equal to 0. The returned array may be the same size or smaller depending on whether there are values that are equal to 0 in the original array. You may only use standard intl| arrays to solve this.arrow_forwardWrite a static method: public static double intersectionSum(double[] a, double[] b) that takes two double arrays as arguments and returns the sum of the elements the two arrays have in common. In other words, the result should be the sum of every element in the two arrays where a[i] is equal to b[i] for some index i. Note that the two arrays may not be the same length. In these cases, you should only consider the indices that the arrays have in common (the indices of the shorter array). If either (or both) arrays are empty or null, the result should be 0.0. Example 1: intersectionSum({3.0, -4.0, 5.8, 6.75}, {3.0, 2.5, 5.8, 4.95}) è 8.8, since a[0] == b[0] and a[2] == b[2] and 3.0 + 5.8 = 8.8 Example 2: intersectionSum({8.5, 9.75, 1.25}, {3.5, 9.75, 1.25, 8.5, -2.34}) è11.0, since a[1] == b[1] and a[2] == b[2] and 9.75 + 1.25 = 11.0arrow_forwardFOR JAVA Write a method that takes a one dimensional integer array and an integer, and returns the index of the integer in the array. If the integer is not in the array, your program must return -1. If there are multiple occurrences of that number, your program must return the smallest index.arrow_forward
- Write a void method selectionSortDescendTrace() that takes an integer array, and sorts the array into descending order. The method should use nested loops and output the array after each iteration of the outer loop, thus outputting the array N-1 times (where N is the size). Complete main() to read in a list of up to 10 positive integers (ending in -1) and then call the selectionSortDescendTrace() method. If the input is: 20 10 30 40 -1 then the output is: 40 10 30 20 40 30 10 20 40 30 20 10arrow_forwardFOR JAVA Write a method that takes a one dimensional integer array and an integer, and returns the index of the integer in the array. If the integer is not in the array, your program must return -1. If there are multiple occurrences of that number, your program must return the smallest index. Repeat the second question, but if there are multiple occurrences of the number, your program must return the largest index instead of the small- est.arrow_forwardFOR JAVA Write a method that takes an integer array and returns the difference between the sum of even indexed elements and the sum of odd indexed elements in that array.arrow_forward
- Write a program that first reads an integer for the array size, then reads numbers intothe array, and finally outputs how many numbers have values that are greater than theaverage. For practice reasons, try not to use the index notation of arrays (e.g. myarray[i])at all. Use pointers instead.arrow_forwardWrite the method sum2D() which accepts a two dimensional integer array and returns the sum of all the elements of the array.arrow_forwardYou are given an int variable k, an int array zipcodeList that has been declared and initialized, an int variable nZips that contains the number of elements in zipcodeList, and a bool variable duplicates. Write some code that assigns true to duplicates if there are two adjacent elements in the array that have the same value, and that assigns false to duplicates otherwise. Use only k, zipcodeList, nZips, and duplicates. duplicates = false; for (k=0; !duplicates && k<nZips-1; k++)if (zipcodeList[k] == zipcodeList[k+1]) duplicates = true;arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education