SC101Assignment3 Eng
SC101Assignment3 Eng
SC101Assignment3 Eng
In the rst half of this assignment, we will become more familiar with the
rst data structure we learned in Python - "List"! And in the second half, we
will experience what a software engineer often encounters - "continuing the
code written by others" and completing the entire program! Please note that
for this assignment, you will have to use the terminal in PyCharm and run
all of the programs from the command line.
Before starting the assignment, please watch the video provided below
https://youtu.be/BXZ7XeN9Eys
Download
Should you have any questions, feel free to ask your TA! Conceptual
discussions are encouraged while working through each problem set.
However, do not show your codes to anyone else except your TA. The
plagiarism checker would warn the Professor of a potential Honor Code
Violation.
fi
fi
stanCodoshop.py
Suppose the user imports the three pictures shown above - "photos of
our magical "stanCodoshop" APP. In that case, the user will get a photo with
Suppose the user has imported several pictures of the same size, and the
positions of random passers-by in the photos are di erent. Thus, we will
take pixels that exist at the same coordinate (x, y) in each respective picture
and compare them one by one. Afterward, we will nd a pixel not a ected by
pedestrians and put it at the same coordinate in a "blank picture of the same
size as the photo imported." When all coordinate of the blank image is lled
with the pixels we choose, our picture with a clean landscape is produced!
From their (r, g, b) values, we can nd out that the value of pixel_pic4 is
di erent from the three other pixels that exist at the same location. In this
case, we can assume a high probability of having a person (or a dog) pass
by at the (x, y) position of the fourth photo(pic4)!
ff
fi
fi
ff
ff
ff
fi
Color Distance
We can easily nd the strangest pixel from the example above, yet, how can
we distinguish the odd pixel with a principle?
Suppose we respectively compute the average of the RGB values from pixels
across all images at the same coordinate(x,y); we will have the value
of red_avg, green_avg, and blue_avg. By adding these average RGB values
to our 3D space, we will create another point named "avg_point." Then,
using the formula below, we can calculate the "color distance" between
Your task is to write the code for the get_pixel_dist(pixel, red, green,
blue) function of the stanCodoshop.py le. This function returns the color
distance between a pixel and the avg_point. A given red, green, and blue
Test
To check whether the function you wrote works, please add the three-line
The parameter - pixels of this function is a Python List that contains a total
Your task is to average all the red values of the given (x, y) pixels to get the
average red value, and do the same for green and blue. And please contain
the values in a Python List and return it in the the order [red, green, blue].
Test
Please modify the code in "def solve(images)." Change the code into the
four-line code shown in the red box in the gure below to check whether the
==================================================
Milestone 3 - get_best_pixel(pixels)
Please call the functions you have de ned in Milestone 1 and Milestone 2 to
complete the get_best_pixel(pixels) function. This function will return the
best pixel, which has the closest distance between the avg_point among all
pixels and will be the one to put on the blank image!
Test
Please change the code in "def solve(images)." into the ve-line code
shown in the red box in the gure below to check whether the function of
this function is correct:
fi
fi
fi
Click and open the terminal window in Pycham:
for macOS please enter: python3 stanCodoshop.py hoover
for Windows please enter: py stanCodoshop.py hoover
==================================================
Milestone 4 - solve(images)
Now comes to our last step to build the "stanCodoshop" App. Please delete
all the code shown in the above red box that you have written in "def
solve(images).”
taken in the same place (All images will be in the same size). Your task is to
nd the best pixel in each (x, y) position among all images and add this pixel
To ensure you have completed this assignment, we provide you with four
sets of images to check (all are well-known spots at Stanford). Please type
macOS/ Windows/
1. python3 stanCodoshop.py clock-tower 1. py stanCodoshop.py clock-tower
2. python3 stanCodoshop.py hoover 2. py stanCodoshop.py hoover
3. python3 stanCodoshop.py math-corner 3. py stanCodoshop.py math-corner
fi
GRADING
Functionality - Does the program meet our basic requirements? The program
must be bug-free, complete the assigned task successfully, and ensure that the
program does not get stuck in any in nite loop.
Style - Good programs should have good usage instructions and be easily
understood, so that people around the world can use your code to build more,
bigger and more interesting programs. Therefore, please write concise usage
instructions, function descriptions, and single-line comments.
SUBMISSION
1. Select all the les, right click, and choose “compress les” or “zipped”
macOS:
Windows:
fi
fi
fi
2. Rename your compressed/zipped le as ”a(n)_name”. For instance:
assignment 0 -> a0_jerry_liao;
assignment 1 -> a1_jerry_liao. Ect