Reference no: EM132372632
Homework: You are to implement the 8-connected component algorithms as taught in class in Java and C++.
Language: Java and C++
I. Input (args[0]): A binary image.
II. Outputs:
- outFile1 (args[1]):** (include in your hard copy)
- Pretty print the result of the Pass-1 *and*
the EQAry with proper captions
- Pretty print the result of the Pass-2 *and*
the EQAry with proper captions
-Print EQAry after manage the EQAry
- Pretty print the result of the Pass-3 *and*
the EQAry with proper caption
// a proper caption means the caption should say what the printing is.
- outFile2 (args[2]): ** (include in your hard copy)
the labelled image file from the result of Pass-3
with header information for your next project.
- outFile3 (args[3]):** (include in your hard copy)
To store the connected component properties.
The format is to be as below:
- 1st text-line, the header of the input image,
- 2nd text-line is the total number of connected components.
- from 3rd text, use four text-lines per each connected component:
- label
- number of pixels
- minRow, minCol //the r c coordinated of the upper left corner
- maxRow, maxCole //the r c coordinated of lower right corner
For an example:
45 40 0 8 // image header
8 // there are a total of 8 CC in the image
1 // CC label 1
187 // 187 pixels in CC label 1
4 9 // upper left corner of the bounding box at row 4 column 9
35 39// lower right corner of the bounding box at row 35 column 39
:
:
*******************************
III. Data structure:
*******************************
- numRows (int)
- numCols (int)
- minVal (int)
- maxVal (int)
- newMin (int)
- newMax (int)
- newLabel (int)
- zeroFramedAry (int **) // a 2D array, need to dynamically allocate
//at run timeof size numRows + 2 by numCols + 2.
- numNb (int) // number of neighbors to be looked at.
// For 8-connectness is set to 5
- NonZeroNeighbor [numNb] (int)
// 1-D array to store pixel(i, j)'s non-zero neighbors
- EQAry (int *)
// an 1-D array, need to dynamically allocate at run time
// of size (numRows * numCols) / 4
// and initialize to EQAry[i] = i.
- Property (you may use 1D struct or class)
- label
- numpixels
- minRow
- minCol
- maxRow
- maxCol
- CCproperty (*Property) // a array of 1D property struct/class
- methods:
- constructor(s) // need to dynamically allocate all arrays;
and assign values to numRows,..., etc.
- zeroFramed // zero framing the image as taught in class
- loadImage // read from input file and writeto zeroFramedAry begin at(1,1)
- (int) loadNonZero (whichPass, i, j, extraLabel, minLabel, diffLabel)
// This method load non-zero neighbors of given p(i,j)
// with respect of whichPass (pass1 or pass2).
// extraLabel set to 0 in pass 1, meaning, it does not include p(i,j)
// and set to p(i,j) for pass-2, meaning, it includes p(i,j)
// during the loading, it determines the minLabel and number of
// different labels.
// The method returns the number of non-zero neighbors
// You should be able to write this method on your own.
- Connect8CC_Pass1// as taught in class
//suggested algorithm steps are given below.
- Connect8CC_Pass2 // as taught in class
//suggested algorithm steps are given below.
- Connect8CC_Pass3 // In the pass3, you will use the EQAry
// to relabel the components;
// keep track the newMin newMax for the label image header
// as well as compute the property of each c.c.
// and store the cc label i's properties toCCproperty[i]
// please note that the bounding box is computed from
// zeroFramedAry, therefore, the actual
// (minRow, minCol, maxRow, maxCol)
// need to be subtract by 1 for these four numbers.
// You should be able to implement this method.
- updateEQ (...) // Update EQAry of all non-zero neighbors to minLabel
- manageEQAry (...) // algorithm was given in class.
- printCCproperty // print the component properties.
- prettyPrint (outFile) // prettyPrintzeroFramedAry
//without the extra rows and columns to outFile
- printEQAry // Print EQAry with index up to newLable, not beyond.
*******************************
IV. main(...)
*******************************
step 0: inFile ← open the input file
numRows, numCols, minVal, maxVal ←read the image header
dynamically allocate zeroFramedAry and initialize to zero.
outFile1, outFile1, outFile3← open
step 1: loadImage(inFile,zeroFramedAry)
// read from input file and writeto zeroFramedAry begin at(1,1)
step 2: Connect8CCPass1 (...) // suggested algorithm steps given below.
prettyPrint(outFile1) // the result of pass1
printEQAry (outFile1)// with index up to newLable with proper caption
step 3: Connect8CCPass2 (...)//suggested algorithm steps given below.
prettyPrint (outFile1) // the result of pass2
printEQAry (outFile1) // with index up to newLable with caption
step 4: manageEQAry (...)// algorithm was given in class.
printEQAry (outFile1)// with index up to newLable with caption
step 5: 8ConnectCCPass3 (...) // see description in the above.
prettyPrint (outFile1) // the result of pass3
printEQAry (outFile1) // with index up to newLable with caption
step 6: output numRows, numCols, newMin, newMax to outFile2
step 7: Output the result of pass3 from zeroFramedAryto outFile2,
begins at (1, 1) and ending at ??
step 8: printCCproperty (...)to outFile 3
step 9: close all files
*******************************
V. ConnectCCPass1 (...)// suggested algorithm steps.
*******************************
step 0: newLabel ← 1
step 1: scan zeroFramedAry L to R & T to B (inside the frame)
if zeroFramedAry (i, j) <= 0
repeat step 1
step 2: numNz← loadNonZero(i, j, 0, minLabel, diffLabel)
case 1: if numNz == 0
zeroFramedAry (i, j) ← newLabel
newLabel ++
case 2: if numNz>0 && diffLabel == 1
zeroFramedAry (i, j) ← minLabel
case 3: if numNz>0 && diffLabel > 1
zeroFramedAry (i, j) ← minLabel
updateEQ (minLabel)
step 3: repeat step 1 to step 2 until all pixels are processed
*******************************
V. ConnectCCPass2 (...)// suggested algorithm steps.
*******************************
step 1: scan zeroFramedAry R to L & B to T (inside the frame)
if zeroFramedAry (i, j) <= 0
repeat step 1
step 2 numNz← loadNonZero(i, j, zeroFramedAry (i, j), minLabel, diffLabel)
if numNz>0 && diffLabel > 1
zeroFramedAry (i, j) ← minLabel
updateEQ (minLabel)
step 3: repeat step 1 to step 2 until all pixels are processed
*******************************
V. drawBoxes(zeroFramedAry, CCproperty)
*******************************
step 1: index ← 1
step 2: minRow ←CCproperty[i].minRow // need to add 1
minCol ←CCproperty[i].minCol // need to add 1
maxRow←CCproperty[i].maxRow // need to add 1
maxCol ←CCproperty[i].maxCol // need to add 1
label ←CCproperty[i].label
step 3: Assign all pixels on minRow from minCol to maxCol ← label
Assign all pixels on maxRow from minCol to maxCol← label
Assign all pixels on minCol from minRow to maxRow ← label
Assign all pixels on maxCol from minRow to maxRow ← label
step 4: index++
step 5: repeat step 2 - step 4 while index is within the number of cc.
There are 12 key requirement for this homework. Please ready carefully before you accept this order.
(1)Must use Visual Studio 2019 for this homework (this can be downloaded for free in the Internet)
(2) Need to use Java and C++ two languages. That means needs two source files: Java source file and C++ source file (.cpp).
(3) Java source code deadline: 9/15/19 Midnight. Only one Java source code to create all required output files.
(4) C++ source code deadline: 9/16/19 Midnight. Only one C++ source code to crate all required output files.
(5) Cannot be separated into more than one source doe. Can be compiler. This program does need any command line argument when running their compiler source code (.exe)
(6)Need to use the same variable name and function name as the name in the document. Cannot use your own names of variable and functions.
(7) Must follow the instruction for each step in the document:
(8) Need to step by step to follow all requirement in the document.
(9) Need to give key and reasonable explanation on the source code.
(10) Need to write 10 - 15 pseudo code linesfor this homework.
(11) Finally, send me all files including: source file, complier file, output files, screen shot output files.
(12) Tech support response time should bye 0 - 12 hours, not 0 -24 hours, because the deadline is close.
Attachment:- connected component algorithmsas.zip