In preparation for doing a clustering analysis on a set of RGB colors, we need a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In preparation for doing a clustering analysis on a set of RGB colors, we need a function that will give us the "distance" from one color to another and a function that calculates the "center of mass" of a set of colors. We'd like to do the easy thing of treating the 24-bit RGB color space as a 3-D cartesian space with the x- axis corresponding to the red intensity, the y-axis corresponding to the green intensity, and the z-axis corresponding to the blue intensity. 24-bit RGB values are represented in integers but usually written in hexadecimal (like decimal, but base 16, with all the digits 0-9 followed by A-F for the values 10-15). So black, which is zero intensity of all three colors is represented as the number zero, but usually that is shown in hexadecimal, Ox000000, white is 100% intensity of all three bases, so OxFFFFFF, pure blue is 0x0000FF, pure green is 0x00FF00, and pure red is OxFF0000. A mixed color like burnt umber, Ox8a3324, has various amounts of red, green, and blue intensities. We'd like to calculate the distance from one color to another as the distance in 3-space which we can calculate with the Pythagorean Formula: d = (1-2)+(9 - 92) + (b b) Q That distance is somewhat, though not perfectly, correlated with human perception of the difference between two colors. We can pull out the red, green, and blue components of an RGB integer as is done in the following example using bit-wise operators in Python: burnt_umber = 0x8a3324 # Python allows hex literals for ints, red burnt_umber >> 16 green burnt_umber >> 8 & 0xff blue burnt_umber & 0xff # 0x8a red intensity # 0x33 green intensity # 0x24 blue intensity Q 1. Write the function, rgb_distance(color1, color2), which returns the distance between color1 and color2. 2. Write the function, rgb_center(colors), which returns the average color of the given sequence of colors. Average the reds, greens, and blues separately then combine the averages into an average color and return that. You can assemble a 24-bit RGB color from its components as follows: color=red < < 16 | green < < 8 | blue In preparation for doing a clustering analysis on a set of RGB colors, we need a function that will give us the "distance" from one color to another and a function that calculates the "center of mass" of a set of colors. We'd like to do the easy thing of treating the 24-bit RGB color space as a 3-D cartesian space with the x- axis corresponding to the red intensity, the y-axis corresponding to the green intensity, and the z-axis corresponding to the blue intensity. 24-bit RGB values are represented in integers but usually written in hexadecimal (like decimal, but base 16, with all the digits 0-9 followed by A-F for the values 10-15). So black, which is zero intensity of all three colors is represented as the number zero, but usually that is shown in hexadecimal, Ox000000, white is 100% intensity of all three bases, so OxFFFFFF, pure blue is 0x0000FF, pure green is 0x00FF00, and pure red is OxFF0000. A mixed color like burnt umber, Ox8a3324, has various amounts of red, green, and blue intensities. We'd like to calculate the distance from one color to another as the distance in 3-space which we can calculate with the Pythagorean Formula: d = (1-2)+(9 - 92) + (b b) Q That distance is somewhat, though not perfectly, correlated with human perception of the difference between two colors. We can pull out the red, green, and blue components of an RGB integer as is done in the following example using bit-wise operators in Python: burnt_umber = 0x8a3324 # Python allows hex literals for ints, red burnt_umber >> 16 green burnt_umber >> 8 & 0xff blue burnt_umber & 0xff # 0x8a red intensity # 0x33 green intensity # 0x24 blue intensity Q 1. Write the function, rgb_distance(color1, color2), which returns the distance between color1 and color2. 2. Write the function, rgb_center(colors), which returns the average color of the given sequence of colors. Average the reds, greens, and blues separately then combine the averages into an average color and return that. You can assemble a 24-bit RGB color from its components as follows: color=red < < 16 | green < < 8 | blue
Expert Answer:
Related Book For
Posted Date:
Students also viewed these operating system questions
-
A researcher wants to examine the production capability of three manufacturing plants that utilize different production methods of the same part in order to select a plant as a supplier for a...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Davis Company opened a Web page design business on January 1 of the current year. The following information relates to Davis Companys operations during the current year: 1. On February 1, Davis...
-
After graduation, you face a choice. One option is to work for a multinational consulting firm and earn a starting salary (benefits included) of $40,000. The other option is to use $5,000 in savings...
-
The cost of the entire program (1.00.00) is: A. $25K B. $66K C. $91K D. Cannot be determined
-
List some of the personal issues you will need to consider when planning your career.
-
Rocky Mountain Races, Inc., sponsors the Pioneer Trail Ultramarathon with an advertised first prize of $ 10,000. The rules require the competitors to run 100 miles from the floor of Blackwater Canyon...
-
Chapter 5 Homework 1. Parent purchases Land on January 1, 2009 for $100,000. On January 1, 2010 parent sells land to 100% owned subsidiary for $140,000. Subsidiary holds land until December 31, 2014...
-
plzhelp this part? During November, the following summary transactions were completed. Nov. 8 Paid \( \$ 1,775 \) for salaries due employees, of which \( \$ 925 \) is for November and \( \$ 850 \) is...
-
1 I think the most important sentence in the Ackerlof profile you read for questions 5-7 is "A person without a job loses not just his income but often the sense that he is fulfilling the duties...
-
read the following article: Boyle, M. A., Augustine, J. J., Garton, E. M., Sharp, D. S., & Mansfield, H. M. (2022). Incorporating noncontingent reinforcement into functional communication training....
-
There are many different ways to add capacity. List several of these and discuss when each would be appropriate.
-
-Discuss the role of policies and procedures for outlining communication responsibilities and provide two (2) examples of human resource communication responsibilities. - Read the following case...
-
1. Communication and the concept of "communicative intelligence" are introduced in ELM #1 as "the lifeblood of [an] organization." This means that effective professional communication is an essential...
-
In Franklin & Blankenburger 2016 Program evaluation of community college learning assistance center: What do LAC directors think? Community College Review, what obstacles of program evaluation were...
-
Global.asax is used for: a. declare application variables O b. all other answers are wrong O c. declare global variables O d. handle application events
-
The following data relate to the direct materials cost for the production of 2,000 automobile tires: Actual: ...... 54,600 lbs. at $1.80 .. $98,280 Standard: . 53,400 lbs. at $1.85 .. $98,790 (a)...
-
Name the following chart, and identify the items represented by the letters (a) through(f). Sales and Costs $200,000 $150,000 $100,000 $50,000 10,000 20,000 30,000 40,000 50,000 60,000 70,000 80,000...
-
What method can be used to place two capital investment proposals with unequal useful lives on a comparable basis?
-
Which statement is false? a. Significant deficiencies need only be reported to the BOD. b. Material deficiencies must be publicly reported. c. The most common area of material weaknesses has been...
-
According to the SEC, which is not a sign of a possible fraudulent company a. Insiders having greater than 50 percent control of the BOD. b. CEO also being chairman of the BOD. c. CEO being the...
-
Prepare a one-hour action pack T.V. episode with the main character a forensic accountant or auditor. The main character should be called Dane Striker or Sloane Striker. Your project can include a...
Study smarter with the SolutionInn App