COMP1006/1406 Assignment #4 Due Monday, December 6 at 11:59 pm COMP 1006/1406 – Fall 2021 Submit your MyBlobs.java file to Brightspace. This assignment has 20 marks. Images, Pixels and Blobs An Image...

1 answer below »
I want you to complete this assignment properly and make sure the code runs properly. Solve them correctly.


COMP1006/1406 Assignment #4 Due Monday, December 6 at 11:59 pm COMP 1006/1406 – Fall 2021 Submit your MyBlobs.java file to Brightspace. This assignment has 20 marks. Images, Pixels and Blobs An Image is a 2-dimensional grid of Pixels. A pixel’s location in the image is specified by its row and column in the image and either has ink (i.e., you can see it) or does not. A blob of ink is one more pixels that have ink and are neighbours in the image. Two pixels at positions (r1, c1) and (r2, c2), respectively, are immediate neighbours if one of the following is satisfied: • r1 = r2 and c1 = c2 ± 1 • r1 = r2 ± 1 and c1 = c2 Here ri is the row of pixel i and ci is the column of pixel i. Notice that you can move from one pixel to one of its immediate neighbours by either moving exactly one position up, down, left or right in the image grid. Diagonals are not allowed for immediate neighbours. Two pixels are neighbours if there is a sequence of immediate neighbours connecting them. For example, in the image below, there are THREE (3) blobs. The blob on the left is made up of 9 pixels (coloured green), the middle blob as 3 pixels (coloured orange), and the last blob, furthest to the right, consists of a single pixel (coloured blue). In this assignment, you will implement several algorithms that explore an image to identify all the pixels in a given blob of ink. The needed methods are defined as abstract in the provided Blobs.java file. You will create a concrete class called MyBlobs.java that overrides these methods with a concrete implementation. A skeleton version of MyBlobs.java is provided with the other needed classed (Blobs.java, Image.java, and Pixel.java). Note: in this assignment, the pixels in a given blob will be stored in a Deque (that stores Pixels) instead of a List. Recall that the Deque ADT (double-ended queue) is a restricted list that has fast access (adding/removing) from both the front and back of the list. For this assignment, you should NOT need to use any other methods than the addLast(), addFirst(), removeFirst() and size() methods of the ArrayDeque you will use. The ArrayDeque is a concrete class that implements the Deque interface. The provided java files have already imported the needed classes/interfaces. COMP 1006/1406 - Fall 2021 1 Assignment #4 Due Monday, December 6 at 11:59 pm 1 Recursive Approach [10 marks] You will use recursion to to find all pixels in a given blob. In particular, you will implement a method called blobRecursiveHelper() that uses accumulative recursion. Recall that in accumulative recursion, you have an extra input parameter that builds up the solution to the problem. When the recursion ends, the final answer is contained in that parameter. blobRecursiveHelper(int row, int col, Deque blobSoFar) In this method, a list of pixels that you have already determined to be in the blob is passed as input (blobSoFar). If the current pixel (specified by the input row and column) has not yet been visited and has ink, you add this pixel to blobSoFar and then recursively visit all four of this pixel’s neighbours. If the pixel has been visited before, then you do nothing (just return). You’ll need to take that your code doesn’t crash by trying to process pixels that are outside of the image. You’ll know if there is a problem if your code crashes with an ArrayIndexOutOfBoundsException. The provided blobRecursive(int row, int col) method will call your helper method. It returns a list (a Deque) of all pixels in the blob that contains the pixel at the initial specified row and column. If the initial pixel does not have any ink then the list should be empty. As you discover a new pixel that hasn’t been visited yet, be sure to add it to the back of the list blobSoFar. This will ensure that the ordering of the pixels will match their discovery ordering. Marking will depend on this ordering being correct. When making recursive calls to immediate neighbours, always visit them in the following order: up, right, down, left. Note that up means decreasing the row value, and left means decreasing the column value. As always, row and column values start with value 0. 2 Iterative Approach [10 marks] A problem with the recursive approach to solving this problem is that you will run out of stack space if the blob is too large (and your program will crash). Instead of using recursion, we can also discover all pixels in a blob using iteration. Here is pseudocode for the basic algorithm: 1 blobIterative(row,col) -> List of Pixels 2 blobList <- empty="" list="" 3="" workinglist=""><- empty="" list="" 4="" add="" pixel="" to="" workinglist="" 5="" while="" workinglist="" is="" not="" empty="" do="" 6="" p=""><- some pixel removed from workinglist 7 if p has ink and has not been visited then 8 mark p as visited 9 add p to back of bloblist 10 for each immediate neighbour q of p do 11 add q to workinglist 12 output bloblist the order of the pixels in the output list will depend on the data structure used for the workinglist list and implementation details. if you use a stack (recall the stack adt) and the order you select immediate neighbours (in line 10 of the pseudocode) is opposite to the order in which you make the recursive calls to immediate comp 1006/1406 - fall 2021 2 assignment #4 due monday, december 6 at 11:59 pm neighbours, then the output list will be in the same order as your recursive implementation. this is a depth-first approach to discovering the pixels. if you use a queue (recall the queue adt), then the order of the output list will start with the initial pixel and then move outwards like the ripple of a wave. this is a breadth-first approach to discovering the pixels. you will override the provided (abstract) blobiterative() method. for your implementation, you can use either the stack or queue approach. regardless of your choice, you must add immediate neighbours (lines 10-11) in the following order: left, down, right, up. note that up means decreasing the row value, and left means decreasing the column value. as always, row and column values start with value 0. submission recap submit your myblobs.java file. do not submit any other file. comp 1006/1406 - fall 2021 3 recursive approach [10 marks] iterative approach[10 marks] some="" pixel="" removed="" from="" workinglist="" 7="" if="" p="" has="" ink="" and="" has="" not="" been="" visited="" then="" 8="" mark="" p="" as="" visited="" 9="" add="" p="" to="" back="" of="" bloblist="" 10="" for="" each="" immediate="" neighbour="" q="" of="" p="" do="" 11="" add="" q="" to="" workinglist="" 12="" output="" bloblist="" the="" order="" of="" the="" pixels="" in="" the="" output="" list="" will="" depend="" on="" the="" data="" structure="" used="" for="" the="" workinglist="" list="" and="" implementation="" details.="" if="" you="" use="" a="" stack="" (recall="" the="" stack="" adt)="" and="" the="" order="" you="" select="" immediate="" neighbours="" (in="" line="" 10="" of="" the="" pseudocode)="" is="" opposite="" to="" the="" order="" in="" which="" you="" make="" the="" recursive="" calls="" to="" immediate="" comp="" 1006/1406="" -="" fall="" 2021="" 2="" assignment="" #4="" due="" monday,="" december="" 6="" at="" 11:59="" pm="" neighbours,="" then="" the="" output="" list="" will="" be="" in="" the="" same="" order="" as="" your="" recursive="" implementation.="" this="" is="" a="" depth-first="" approach="" to="" discovering="" the="" pixels.="" if="" you="" use="" a="" queue="" (recall="" the="" queue="" adt),="" then="" the="" order="" of="" the="" output="" list="" will="" start="" with="" the="" initial="" pixel="" and="" then="" move="" outwards="" like="" the="" ripple="" of="" a="" wave.="" this="" is="" a="" breadth-first="" approach="" to="" discovering="" the="" pixels.="" you="" will="" override="" the="" provided="" (abstract)="" blobiterative()="" method.="" for="" your="" implementation,="" you="" can="" use="" either="" the="" stack="" or="" queue="" approach.="" regardless="" of="" your="" choice,="" you="" must="" add="" immediate="" neighbours="" (lines="" 10-11)="" in="" the="" following="" order:="" left,="" down,="" right,="" up.="" note="" that="" up="" means="" decreasing="" the="" row="" value,="" and="" left="" means="" decreasing="" the="" column="" value.="" as="" always,="" row="" and="" column="" values="" start="" with="" value="" 0.="" submission="" recap="" submit="" your="" myblobs.java="" file.="" do="" not="" submit="" any="" other="" file.="" comp="" 1006/1406="" -="" fall="" 2021="" 3="" recursive="" approach="" [10="" marks]="" iterative="" approach[10="">
Answered 2 days AfterNov 30, 2021

Answer To: COMP1006/1406 Assignment #4 Due Monday, December 6 at 11:59 pm COMP 1006/1406 – Fall 2021 Submit...

Kondalarao answered on Dec 02 2021
118 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here