Session Ready
Exercise

Display dominant colors

We have loaded the following image using the imread() function of the image class of matplotlib.

To display the dominant colors, convert the colors of the cluster centers to their raw values and then converted them to the range of 0-1, using the following formula: converted_pixel = standardized_pixel * pixel_std / 255

The RGB values are stored in a data frame, batman_df. The scaled RGB values are stored in columns, scaled_red, scaled_blue and scaled_green. The cluster centers are stored in the variable cluster_centers, which were generated using the kmeans() function with three clusters.

Instructions
100 XP
  • Get standard deviations of each color from the data frame and store it in r_std, g_std, b_std.
  • For each cluster center, convert the standardized RGB values to scaled values in the range of 0-1.
  • Display the colors of the cluster centers.