Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Problem When working with digital images, there are many simple, but powerfu

ID: 3842103 • Letter: T

Question

The Problem

When working with digital images, there are many simple, but powerful algorithms we can use to extract properties of those images. One such operation is hole counting.

Some Background on Hole Counting

(from Shapiro and Stockman's 2001 Computer Vision)

In the late 1970s an engineer in Milwaukee implemented a machine vision system that successfully counted the number of bolt holes in crossbars made for truck companies. The truck companies demanded that every crossbar be inspected before being shipped to them, because a missing bolt hole on a partly assembled truck was a very costly defect. Either the assembly line would have to be stopped while the needed hole was drilled, or worse, a worker might ignore placing a required bolt in order to keep the production line running. To create a digital image of the truck crossbar, lights were placed beneath the existing transfer line and a digital camera above it. When a crossbar came into the field of view, an image was taken. Dark pixels inside the shadow of the crossbar were represented as 1s indicating steel, and pixels in the bright holes were represented as 0s, indicating that the hole was drilled. The number of holes can be computed as the number of external corners minus the number of internal corners all divided by four.

An external corner is just a 2 x 2 set of neighboring pixels containing exactly 3 ones, while an internal corner is a 2 x 2 set of neighboring pixels containing exactly 3 zeros.

Hole Counting Practice

To visualize a binary (black and white) image, we will assume that 0s are black (the “holes”) and 1s are white (the “steel”). Here is a simple 6 x 6 set of pixels forming an image.

Fill in the blank cells with “e” or “i” if they are external or internal corners, and calculate the number of holes using the formula. The solution is on the following page.

Here are the correctly-filled-in cells:

Calculate the number of holes using the formula described in the background:

A Note

The hole counting algorithm will not work for all arrangements of binary pixels. Can you think of examples in which the hole counting algorithm would fail?

Your program will only be tested on cases where this simple algorithm produces the correct hole count.

Your Tasks

Complete the Project 6 by writing code for the following functions. Details of type for the functions can be found in functions.h (provided for you, see details below):

readImage – Reads in lines of 0s and 1s and returns a binary multidimensional vector.

Inputs: Two integers – the number of columns and the number of rows, respectively.

Output: The image stored in a two-dimensional vector of ints.

printImage – Outputs the binary image of the multidimensional vector returned by readImage. For formatting, see the output files.

Input: Two dimensional vector of ints.

Output: Nothing (void). Should print to terminal.

countHoles – Returns the number of holes in the multidimensional vector returned by

readImage.

Inputs: The two dimensional vector of ints (the image).

Outputs: The number of holes as an int.

Test Cases

• 6 test cases

Assignment Notes

1. You are given the following files:

main.cpp – This file includes the main function where the test cases will be run.

Do not modify this file.

functions.h – This file is the header file for your functions.cpp file. Do not

modify this file.

input#.txt – These four text files will be used to run the test cases.

d. correct_output_#.txt – These text files will be used to grade your output based on the corresponding input files. Be sure that your output matches these text files exactly to get credit for the test cases.

You will write only functions.cpp and compile that file using functions.h and main.cpp in the same directory (as you have done in the lab). You are only turning in functions.cpp for the project.

Comparing outputs: You can use redirected output to compare the output of your program to the correct output. Use redirected output and the “diff” command in the Unix terminal to accomplish this:

Run your executable on the desired input file. Let’s assume you’re testing input1.txt, the first test case. Redirect the output using the following line when in your directory: ./a.out < input1.txt > output1.txt

Now your output is in the file output1.txt. Compare output1.txt to correct_output1.txt using the following line: diff output1.txt correct_output1.txt

If the two files match, nothing will be output to the terminal. Otherwise, “diff “will print the two outputs.

main.cpp:

functions.h :

Finally, save your function.cpp for completion.

input1:

output1:

input2:

output2:

input3:

output3:

T 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Explanation / Answer

#include #include using std::cout;using std::cin;using std::endl; using std::vector; #include "functions.h" int main() { int x_dim, y_dim, test_case; cin >> test_case; // read in number of columns as x_dim cin >> x_dim; // read in number of rows as y_dim cin >> y_dim; vector image = readImage(x_dim, y_dim); switch (test_case){ case 1 : { printImage(image); break; } // of case 1 case 2 : { printImage(image); break; } // of case 2 case 3 : { printImage(image); cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote