At the core of many advanced computer vision algorithms for image segmentation, feature detection, and classication are several basic morphological image processing operations that modify the borders between neighboring clusters of similarly colored pixels. The dilation operation adds pixels along the boundary to expand or grow a cluster. The erosion operation shrinks the boundary of the cluster by reassigning pixels along the boundary to a background color. Well also implement a simple replace operation to change all pixels in the image of color A to color B. And the oodll operation that is similar to replace, but only changes pixels that are part of the same connected cluster. The diagram on the right illustrates the details of the dilation and erosion operations. In both cases we will use a plus-shaped structuring element that contains the 4 adjacent pixels to a candidate pixel. When deciding which pixels to add to expand the boundary of the grey cluster during a dilation operation, we place the structuring element over each candidate pixel and ask if the shape overlaps or hits any of the existing grey pixels. If it does, we change its color to the foreground color (grey). In contrast, when shrinking the boundary during erosion, we consider removing each pixel from the cluster. If all of the pixels of the structuring element do not fully t within the grey cluster of pixels we will set that pixel to the background color (white). 3 45 2 1 130 0 2 6 5 4 EROSION add change no pixel remove change no pixel DILATION You will work with command line arguments, le input and output, and the STL C++ string and vector classes to manipulate manipulate a grid of ASCII characters (instead of a traditional color image le). Please read the entire assignment carefully before starting to program. Command Line Arguments Your program will expect 4-6 command line arguments, depending on the requested operation. The 1st argument is the name of the input ASCII art image le. The 2nd argument is the name of the output le where the ASCII art image resulting from the operation should be written. The 3rd argument is the name of one of 4 operations that should be performed: replace, dilation, erosion, or floodfill. Here are some example command lines: ./image_processing.out input4.txt output4_replace.txt replace X O ./image_processing.out input4.txt output4_dilation.txt dilation X ./image_processing.out input4.txt output4_erosion.txt erosion X . ./image_processing.out input4.txt output4_floodfill.txt floodfill 2 10 O The number and purpose of the remaining arguments on the command line depend on the operation. For a replace operation, the 4th argument is the character that should be removed from the image and the 5th argument is the character that should be substituted in those locations. For the dilation operation, the 4th argument is the foreground character (clusters of pixels of this color should increase in size). For the erosion operation, the 4th argument is the foreground character (clusters of pixels of this color should decrease in size). We also need to know the background color that will replace pixels that are removed from the foreground object and the 5th argument is that background character. Finally, for the oodll operation, the 4th and 5th command line arguments are the integer coordinates of the starting point for oodll (row & column respectively) and the 6th command line argument is the replacement character. Note that certain ASCII characters have special meaning on the command line, and it will be necessary to escape that meaning by preceding those characters by a backslash () to make sure your program receives the desired character. Examples and More Information In many computer vision applications, these operations are applied sequentially, one after the other. Note that these operations are generally not commutative. The opening operation is the result of rst applying erosion and then dilation. The eect of opening is to round sharp outer corners and remove tiny islands. The closing operation is achieved by rst performing dilation and then erosion. The eect of closing is to ll in small gaps within the foreground object and smooth inner corners. ./image_processing.out output4_erosion.txt output4_opening.txt dilation X ./image_processing.out output4_dilation.txt output4_closing.txt erosion X . input4.txt output4 replace.txt output4 dilation.txt output4 erosion.txt output4 floodfill.txt output4 opening.txt output4 closing.txt . . ..XXX..X.. ..XXX..X.. ..XXX.. ..XXX.. ..XXXXXXX. ..XXXXXXX. ..XXXXXXX. . . . . ..OOO..O.. ..OOO..O.. ..OOO.. ..OOO.. ..OOOOOOO. ..OOOOOOO. ..OOOOOOO. . . . ..XXX..X.. .XXXXXXXX. .XXXXXXXX. .XXXXX.X.. .XXXXXXXX. .XXXXXXXXX .XXXXXXXXX .XXXXXXXXX ..XXXXXXX. . . . . X X X XX.. XXXXX.. . . . . . ..XXX..O.. ..XXX..O.. ..XXX.. ..XXX.. ..XXXXXXX. ..XXXXXXX. ..XXXXXXX. . . . . X ..XXX.. ..XXX.. ..XXX.. ..XXXXXX.. ..XXXXXXX. XXXXX.. . . . . ..XXX..X.. ..XXX..X.. ..XXX.. ..XXXX. ..XXXXXXX. ..XXXXXXX. ..XXXXXXX. . . You must follow the specications for the command line arguments and functionality exactly as described in this handout to receive full credit. Sample input and output les are posted on the course website, and the validation and automatic grading on the submission server will also help you check your work. More information on command line arguments and le I/O in C++ is available on the course webpage under Misc. C++ Programming Info. Image Bounds & other Error Checking When the structuring element is placed at the edge of the image, one or more pixels may fall o the edge and not overlap legal image coordinates. You do not want to access data that does not exist (a memory error that could give weird output or crash the program!). Be sure to add appropriate checks in your program to skip these out-of-bounds coordinates. You may assume that the input image le is properly formatting and contains a rectangular grid of non-white space characters. However, to help with your own debugging, you should implement simple error checking to ensure that the command line arguments are appropriate and that the input and output le streams are successfully opened. Your program should exit gracefully with a useful error message sent to std::cerr if there is a problem with the arguments. Extra Credit For extra credit you may extend your program to work with larger and/or dierently shaped structuring elements. Paste interesting examples & comparisons of your results into your README.txt le. You may add additional command line arguments to specify an alternate structuring element; however, make sure your program uses the plus-shaped structuring element by default and still works as described above so you get full credit for the main homework on the submission server! Submission Details Do your work in a folder named hw1 within your Data Structures homeworks directory. Organize your program into logical, reasonable-length functions dont put all of the code in main! Be sure to read the Homework Grading Criteria as you put the nishing touches on your solution. Create new test cases to fully debug your program and dont forget to comment your code! Use the provided template README.txt le for notes you want the grader to read. You must do this assignment on your own, as described in the Collaboration Policy & Academic Integrity handout. If you did discuss this assignment, problem solving techniques, or error messages, etc. with anyone, please list their names in your README.txt le.
Programming
[Solved] SOLVED:Morphological Image Processing solution
$25
File Name: SOLVED:Morphological_Image_Processing_solution.zip
File Size: 433.32 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.