Lab Exam II (October 29, 2024)
Solutionrgb2cmyk.py
The most common color model used by computer displays to represent images is the RGB color model. The RGB color model is an additive color model in which the red, green and blue primary colors of light are added together to reproduce the other colors in the spectrum. The abbreviation comes from the first letters of each of the primary colors: Red, Green, and Blue.Colors in the RGB model are represented by a composition of 3 values: R, G, and B. Each primary color value can range between 0-255. This value represents the intensity of the primary color. Red is represented by an RGB value of (255, 0, 0) where only the red primary color is represented. Green is (0, 255, 0) and Blue is (0, 0, 255). All other colors are compositions of these 3 colors. For example, Yellow is created when Red and Green are combined. It is similarly represented in the RGB color model: (255, 255, 0).
However, if you have ever changed the ink on a color printer, you may have noticed that ink cartridges do not come in red, green, and blue inks. This is because color printers use a different color model to represent its images. Color printing uses a subtractive color model called the CMYK color model. The abbreviation refers to the names of the four ink colors: Cyan, Magenta, Yellow, and Key (Black). The values of each of the four ink colors range from 0(%) to 100(%).
Behind the scenes, your computer performs a color model conversion before printing a color document or picture to translate the RGB image you see on screen into the CMYK equivalent that your color printer can print. The formulas for converting the pixels of any RGB image into a CMYK pixel are shown below.
For this exam, you will need to program a function called RGB_to_CMYK() that takes a dictionary of RGB values as input, converts them from RGB to CMYK, and returns a dictionary of the equivalent CMYK value. The keys of the RGB dictionaries are R, G, and B with values ranging from 0-255. The keys of the CMYK dictionaries are C, M, Y, K with values ranging from 0 -100.
Note: CMYK values are always integers. Your results may differ by +1 or -1 from the example output due to differences in rounding.
Your program should allow the user to enter multiple R, G, and B values as input until a stop word is detected, compute the conversion to CMYK using the function, and output the C, M, Y, and K values in the terminal. There should be at least two valid stop words, one of which should be a single letter shortcut. Ex. ‘quit’ and ‘q’.
Example Output:
$ python3 rgb2cmyk.py RGB To CMYK Converter Enter the Red Color Value (enter quit or q to quit): 0 Enter the Green Color Value: 128 Enter the Blue Color Value: 128 CMYK Values Cyan: 100 Magenta: 0 Yellow: 0 Key (Black): 50 RGB To CMYK Converter Enter the Red Color Value (enter quit or q to quit): q $
Lab Exam Policy
This is a closed-book exam! You may only have your cheat sheet and your IDE open. You may not use an internet browser to research the solution. There is only one programming question. Please read the question carefully. You will have 1 hour and 40 minutes to complete this exam. Note: Please leave time to submit your code using the following command on the tinman server:sudo handin1301 e2 rgb2cmyk.pyTo transfer the file to tinman, you may use FileZilla OR the following procedure: Open a Terminal/Powershell Window. cd into the folder containing rgb2cmyk.py. Then, type the following command (replace userid with your campusid):
sftp userid@tinman.cs.gsu.eduyou will be asked for your password; type it in (you may have to say "yes" to a question before password). once you see the sftp prompt, transfer the file as follows:
put rgb2cmyk.pyThen make sure you exit the sftp program:
exit