Images. That's it. Images. As a point of practicality, take a fashion designer (as a forum member vividly described to me at one point). You are given an image or have an image at your disposal that simply tickles your curiosity and want to incorporate it in one of your new lines. Let's swerve a little into the genetics section. Given a petri dish image for instance, with pigmented bacteria or similar organisms, and you would like to find the abundance of that organism or organisms in this specific image. Get the gist? That's why we have . Letting you knab those colors right from the image, or if you were a tad bit crazy a video. For an overview, we'll kick it off by installation. ColorDetect As all Pythonistas have it, create a virtual environment, and install. pip install ColorDetect For this demonstration, we'll borrow Greyson Joralemon's photo. A program that gets the colors in this specific image. colordetect ColorDetect user_image = ColorDetect( ) colors = user_image.get_color_count() print(colors) from import 'media/random_balls.jpg' ColorDetect will go, do its thing and return this: $ python get_colors.py { : 7.63, : 9.0, : 11.98, : 35.54, : 35.85} '[59.0, 70.0, 198.0]' '[245.0, 155.0, 186.0]' '[232.0, 22.0, 103.0]' '[207.0, 143.0, 3.0]' '[88.0, 70.0, 34.0]' A color description of the image, breaking down the relevant most abundant colors to say, hey, this image has of it occupied by this color: . 7.63 % RGB '[59.0, 70.0, 198.0]' If we wanted the for this instead, we'd pass that as the parameter to . hex get_color_count() colors = user_image.get_color_count(color_format= ) 'hex' #colors # {'#3b46c6': 7.63, '#f59bba': 9.0, '#e81667': 11.99, '#cf8f03': 35.56, '#584622': 35.83} We could, of course, look for more color than just five of the most dominant. user_image.get_color_count(color_format= , color_count= ) 'hex' 8 Depending on the size or ratio of the image, it may take a moment. A case in point, a low graphic image, say 2MP vs a high definition top of the line camera image. These two images, despite pointing to the same object or scene, have very different pixel ratios. Let's go ahead, and instead of getting the color as a variable, write this color onto the image. user_image.write_color_count() user_image.save_image( , ) # save the image after writing the color count to it 'media' 'processed.jpg' We save this image in the media directory with a name : processed.jpg Perfecto! We did have something about the crazy people with videos, didn't we? Now, where is that video...oh, . Our file. here it is earth.mp4 colordetect VideoColor my_video = VideoColor( ) video_colors = my_video.get_video_frames( progress= ) print( ) from import 'media/earth.mp4' True f" " {video_colors} { : 0.92, : 2.16, : 11.17, : 17.59, : 68.83, : 0.84, : 2.09, : 11.18, : 16.69, : 0.95, : 2.05, : 15.43, : 0.94, : 2.38, : 15.72, : 0.9, : 2.26, : 13.12, : 0.89, : 2.27, : 0.79, : 2.1, : 14.18, : 0.89, : 2.08, : 0.9, : 2.06, : 12.11, : 16.76, : 0.88, : 0.86, : 2.0, : 10.65, : 16.93, : 0.99, : 2.14, : 10.66, : 0.88, : 2.19, : 10.68, : 0.85, : 2.0, : 11.04, : 0.87, : 11.15, : 10.6, : 19.34, : 2.0, : 9.31, : 0.85, : 1.98, : 0.87, : 1.96, : 8.58, : 17.77, : 0.88, : 1.9, : 6.95, : 1.89, : 0.81, : 1.85, : 6.83, : 22.22, : 0.85, : 1.79, : 7.22, : 22.48, : 1.69, : 0.85, : 1.9, : 7.25, : 21.7, : 1.9, : 7.91, : 0.94, : 1.91, : 9.19, : 0.84, : 1.96, : 10.65, : 0.85, : 10.61, : 17.7, : 0.85, : 1.96, : 11.34, : 0.92} '[137.0, 165.0, 182.0]' '[71.0, 84.0, 95.0]' '[24.0, 30.0, 50.0]' '[7.0, 10.0, 26.0]' '[0.0, 0.0, 0.0]' '[143.0, 170.0, 187.0]' '[76.0, 89.0, 101.0]' '[26.0, 32.0, 52.0]' '[8.0, 11.0, 28.0]' '[135.0, 163.0, 181.0]' '[76.0, 88.0, 98.0]' '[8.0, 11.0, 27.0]' '[127.0, 160.0, 179.0]' '[71.0, 83.0, 94.0]' '[7.0, 11.0, 27.0]' '[124.0, 160.0, 181.0]' '[69.0, 84.0, 96.0]' '[26.0, 32.0, 53.0]' '[125.0, 160.0, 182.0]' '[68.0, 82.0, 95.0]' '[132.0, 166.0, 186.0]' '[71.0, 87.0, 100.0]' '[25.0, 32.0, 52.0]' '[132.0, 164.0, 183.0]' '[70.0, 85.0, 97.0]' '[132.0, 165.0, 183.0]' '[73.0, 88.0, 99.0]' '[26.0, 33.0, 53.0]' '[8.0, 10.0, 27.0]' '[134.0, 166.0, 184.0]' '[132.0, 165.0, 185.0]' '[74.0, 88.0, 100.0]' '[26.0, 33.0, 52.0]' '[7.0, 10.0, 27.0]' '[124.0, 157.0, 178.0]' '[68.0, 82.0, 93.0]' '[25.0, 31.0, 50.0]' '[124.0, 160.0, 182.0]' '[67.0, 82.0, 94.0]' '[25.0, 31.0, 49.0]' '[124.0, 160.0, 183.0]' '[67.0, 83.0, 95.0]' '[25.0, 30.0, 49.0]' '[123.0, 160.0, 182.0]' '[24.0, 29.0, 47.0]' '[23.0, 29.0, 47.0]' '[6.0, 9.0, 26.0]' '[67.0, 83.0, 97.0]' '[24.0, 29.0, 48.0]' '[125.0, 161.0, 184.0]' '[67.0, 84.0, 97.0]' '[127.0, 162.0, 183.0]' '[67.0, 83.0, 96.0]' '[23.0, 29.0, 46.0]' '[5.0, 8.0, 25.0]' '[125.0, 161.0, 183.0]' '[68.0, 84.0, 98.0]' '[24.0, 29.0, 46.0]' '[67.0, 84.0, 99.0]' '[133.0, 166.0, 186.0]' '[67.0, 86.0, 99.0]' '[23.0, 28.0, 45.0]' '[5.0, 8.0, 24.0]' '[135.0, 165.0, 186.0]' '[69.0, 86.0, 100.0]' '[22.0, 27.0, 43.0]' '[5.0, 7.0, 24.0]' '[73.0, 91.0, 105.0]' '[129.0, 163.0, 185.0]' '[69.0, 85.0, 98.0]' '[21.0, 27.0, 44.0]' '[4.0, 7.0, 24.0]' '[68.0, 86.0, 101.0]' '[22.0, 27.0, 45.0]' '[126.0, 160.0, 181.0]' '[66.0, 83.0, 96.0]' '[22.0, 27.0, 46.0]' '[129.0, 164.0, 185.0]' '[69.0, 86.0, 99.0]' '[21.0, 27.0, 46.0]' '[133.0, 165.0, 185.0]' '[23.0, 29.0, 48.0]' '[7.0, 9.0, 26.0]' '[135.0, 165.0, 185.0]' '[73.0, 88.0, 100.0]' '[24.0, 29.0, 50.0]' '[139.0, 164.0, 177.0]' We may find the colors are too much for our use case. So let's shorten this: print(my_video.color_sort(color_count= )) 6 { : 68.83, : 22.48, : 22.22, : 21.7, : 19.34, : 17.77} '[0.0, 0.0, 0.0]' '[5.0, 7.0, 24.0]' '[5.0, 8.0, 24.0]' '[4.0, 7.0, 24.0]' '[6.0, 9.0, 26.0]' '[5.0, 8.0, 25.0]' This will return the top 6 most dominant colors from the whole video, having taken a frame for every second. Looks much better! Unless you want to use all the colors, that is. I'll iterate on this. This all depends on the quality of the input media file, and length if it is a video in this case. take it this way, a video 5 minutes long, showing a wide variety of colors from all sorts of crayons vs a short video as just shown. Remember, the process is per frame of every second. I'm certain this will be addressed in a future . release We can hold off here and let the steam cool off. Do keep up to date with the as more features and performance improvements come to light. package Previously published at https://thegreencodes.com/colordetection-python-colordetect-package