pr4 New
pr4 New
Your
program will let the user to choose which connectness (4 or 8) to run the program, via argv [2]. In addition, your program
gives a conversion option (y or Y for yes, n or N) whether the input data to be converted or not before the processing.
(Conversion is to change pixels in an array from 0 to 1 and 1 to 0.)
*** You will be given two data files, data1 and data2, and the answer file of data1.
What you need to do as follows:
a) Implement your program based on the specs given below.
b) run1: Test and debug your program using data1 for 8-connected with option N until it produces the same result as
given in the answer file.
c) run2: Test and debug your program using data1 for 4-connected with option N until it produces the same result as
given in the answer file.
d) run3: Test and debug your program using data1 for 4-connected with option Y. (Eyeball the result for correctness. See
if you know the meaning of the result with conversion).
e) run4: Run your program using data2 for 8-connected with option N. (Eyeball the result for correctness.)
f) run5: Run your program using data2 for 4-connected with option Y. (Eyeball the result for correctness. See if you
know the meaning of the result with conversion).
** On each run, your program will produce four files: RFprettyPrintFile, LabelFile, propertyFile and deBugFile.
** labelFile and propertyFile will be used as input in your future project(s).
*************************************
I. Inputs:
a) inFile (argv [1]): A binary image.
b) connectness (argv [2]): 4 for 4-connectness, 8 for 8-connectness.
c) conversion (argv [3]): y or Y for yes, n or N for no.
II. Outputs:
a) RFprettyPrintFile (argv [4]): (include in your hard copy) for the followings:
** a proper caption means the caption should say what the printing is.
- reformatPrettyPrint of the result of the Pass-1 with proper captions - print newLabel and the
EQAry after Pass-1, with proper captions
- reformatPrettyPrint of the result of the Pass-2 with proper captions
- print newLabel and the EQAry after Pass-2, with proper captions - Print the
EQAry after manage the EQAry, with proper caption
- reformatPrettyPrint of the result of the Pass-3 with proper captions
- reformatPrettyPrint of the result bounding boxes drawing.
b) labelFile (argv [5]): to store the connected component labels of Pass-3 -- the labelled image file
with image header, numRows numCols newMin NewMax. ** This file to be used in future
processing.
- printEQAry (...) // Print EQAry with index up to newLabel, not beyond. On your own
- drawBoxes (...) // Draw the bounding boxes of CC in zeroFramedAry. See algorithm below
- printImg (...) // Output image header and zeroFramedAry (inside of framing) to labelFile. On your own.
*******************************
IV. main(...)
*******************************
step 0: inFile open the input file from argv [1]
Connectness argv [2] option argv
[3]
RFprettyPrintFile, labelFile, propertyFile, deBugFile open from argv []
numRows, numCols, minVal, maxVal read from inFile zeroFramedAry
dynamically allocate.
newLabel 0 step 1: zero2D
(zeroFramedAry) step 2: loadImage
(inFile, zeroFramedAry)
step 3: if option == ‘y’ or ‘Y’
conversion (zeroFramedAry) step 4: if connectness == 4 connected4
(zeroFramedAry, newLabel, EQAry, RFprettyPrintFile, deBugFile) step 5: if connectness
== 8 connected8 (zeroFramedAry, newLabel, EQAry, RFprettyPrintFile, deBugFile)
step 6: labelFile output numRows, numCols, newMin, newMax to labelFile
step 7: printImg (zeroFramedAry, labelFile) // Output the result of pass3 inside of zeroFramedAry
step 8: printCCproperty (propertyFile) // print cc properties to propertyFile step 9: drawBoxes
(zeroFramedAry, CCproperty, trueNumCC) // draw on zeroFramed image.
step 10: imgReformat (zeroFramedAry, RFprettyPrintFile) step 11:
print trueNumCC to RFprettyPrintFile with proper caption step 12:
close all files
*******************************
V. connected4 (zeroFramedAry, newLabel, EQAry, RFprettyPrintFile, deBugFile)
*******************************
Step 0: deBugFile “entering connected4 method”
Step 1: connect4Pass1 (zeroFramedAry, newLabel, EQAry) deBugFile
“After connected4 pass1, newLabel =” // print newLable imgReformat
(zeroFramedAry, RFprettyPrintFile)
printEQAry (newLabel, RFprettyPrintFile) // print the EQAry up to newLable with proper caption
Step 4: connectPass3 (zeroFramedAry, EQAry, CCproperty, trueNumCC, deBugFile) // see algorithm below.
Step 5: imgReformat (zeroFramedAry, RFprettyPrintFile)
Step 6: printEQAry (newLabel, RFprettyPrintFile) // print the EQAry up to newLabel with proper caption Step
7: deBugFile “Leaving connected4 method”
*******************************
Step 4: connectPass3 (zeroFramedAry, EQAry, CCproperty, trueNumCC, deBugFile) // see algorithm below.
Step 5: imgReformat (zeroFramedAry, RFprettyPrintFile)
Step 6: printEQAry (newLabel, RFprettyPrintFile) // print the EQAry up to newLabel with proper caption Step
7: deBugFile “Leaving connected8 method”
******************************
VII. connectPass3 (zeroFramedAry, EQAry, CCproperty, trueNumCC, deBugFile)
*******************************
Step 0: deBugFile “entering connectPas3 method”
Step 1: for i = 1 to trueNumCC
CCproperty[i].label i
CCproperty[i].numPixels 0
CCproperty[i].minR numRow
CCproperty[i].maxR 0
CCproperty[i].minC numCol
CCproperty[i].maxC 0
Step 4: repeat Step 2 to Step 3 until all pixels inside of zeroFramedAry are processed Step
5: deBugFile “leaving connectPas3 method”
Step 3: Assign label to all pixels on minRow of zeroFramedAry, from minCol to maxCol label //use a loop.
Assign label to all pixels on maxRow of zeroFramedAry, from minCol to maxCol label //use a loop.
Assign label to all pixels on minCol of zeroFramedAry, from minRow to maxRow label //use a loop.
Assign label to all pixels on maxCol of zeroFramedAry, from minRow to maxRow label //use a loop.
Step 4: index++
Step 5: repeat step 2 to step 4 while index <= trueNumCC
Step 6: deBugFile “leaving drawBoxes method”