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
-
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...
-
Classify the following items as either financial capital or physical capital. a. A computer server owned by an information processing company b. $100,000 set aside in an account to purchase a...
-
Plot the given points on the same axes. (3, 2)
-
True or False: For personal investment decision making, rates of return are used more frequently than present worth.
-
Goodman Tire and Rubber Company has capacity to produce 170,000 tires. Goodman presently produces and sells 130,000 tires for the North American market at a price of $ 125 per tire. Goodman is...
-
Bank extends a revolving line of credit to Epstein Corp., secured by Epstein's inventory and receivables. Epstein has now filed bankruptcy. At all times during the 90 days preceding the filing the...
-
The Following problems will lead you to find the moment of inertia of a uniform thick spherical shell of inner radius b and mass M. (The moment of inertia of a thin spherical shell is I = 2MR/3). 8)...
-
Describe three types of software that can assist in project quality management.
-
Discuss the advantages and disadvantages of different ways of distributing project information.
-
How can you use Project 2013 to assist in project human resource management?
-
Discuss the common sources of risk on IT projects and suggestions for managing them. Which suggestions do you find most useful? Which do you feel would not work in your organization? Why?
-
List five reasons why organizations outsource. When should an organization choose not to outsource? Why are some organizations moving their software development work back in-house? Why are some...
-
The Fine Point Company currently produces all of the components for its one product, an electric pencil sharpener. The unit cost of manufacturing the motor for this pencil sharpener Is: Direct...
-
Time Solutions, Inc. is an employment services firm that places both temporary and permanent workers with a variety of clients. Temporary placements account for 70% of Time Solutions' revenue;...
-
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?
-
Consider a sample taken from the population of all taxi-in times for all flights that land in Los Angeles. Identify the symbols used for the sample standard deviation, the population standard...
-
An article in the New York Times noted that these new ZIP codes were created in New York City: 10065, 10021, 10075. Find the mean of these three numbers. What is fundamentally wrong with this result?
-
Shown below is a boxplot of a sample of 20 brain volumes (cm 3 ). What do the numbers in the boxplot represent? 963 1034.5 1079 1439 1188.5
Study smarter with the SolutionInn App