Question: ( Name this program StuPreE 3 Select ) Image processing relies on multi - dimensional arrays. Write a method selectRect that simulates selecting and returning
Name this program StuPreESelect Image processing relies on multidimensional arrays. Write
a method selectRect that simulates selecting and returning a rectangular area of a D image.
Returns a full d int array with data from the rectangular area
specified by startRow, startCol, endRow, and endCol assume
startRowendRow and startColendCol if those four indexes are
valid.
Return null if image is null or has zero rows or zero cols.
Also return null if any rowcol index is invalid.
public static int selectRectint image,
int startRow, int startCol,
int endRow, int endCol
ADD code
Your method should return null on invalid or bad parameters as explained in the given method
prolog comment. It should also test for invalid startingending rowcol values outside of valid
index ranges of the D array parameter and return null. Other than those, assume
startRowendRow and startCol endCol, that is your method only needs to handle a start
position of a top left corner to an end position of a bottom righ corner, if they are within the
ranges.
For example, given this d image array rows and cols:
A start position to an end position would be a valid selection:
from top left corner to bottom right corner
For the example D array, a startend position of or would be invalid.
CS ObjectOriented Programming
Page of
Be aware that an area formed by the same start position and end position, such as ~
covers one single pixel and is still valid. That would lead to a d array with one single row and
one single column.
Your main should test the method following the example below. Include at least two additional
valid cases besides the one shown below and one invalid case in your main
int image new int
;
System.out.printlnArraysdeepToStringimage; original
int startRow startCol endRow endCol ;
int select; store selected area
valid ~
select selectRectimage startRow, startCol, endRow, endCol;
System.out.printfdddd: s
startRow, startCol,
endRow, endCol, Arrays.deepToStringselect;
reuse variables to add additional testing cases
The above segment of code will produce this output:
:
Arrays.deepToString is similar to Arrays.toString but works with D arrays and
higher dimension arrays You need: import java.util.Arrays;
A downside of Arrays.deepToString is that it always returns the content in one long string. Feel
free to replace it with a method of your own to print a D array in a nicer format
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
