Latest YouTube Video
Saturday, June 10, 2017
I have a new follower on Twitter
Kevin
Just a guy who likes to sing and play guitar. Check out my music at the link below!
https://t.co/2DfXEmgDcL
Following: 44264 - Followers: 43775
June 10, 2017 at 03:55PM via Twitter http://twitter.com/kevinlytlemusic
Orioles: Manny Machado (wrist) out of lineup Saturday vs. Yankees, misses 3rd straight game; Ruben Tejada draws start at 3B (ESPN)
via IFTTT
[10/06/2017] }_D ..,,.. bitcoin generator anonymous
from Google Alert - anonymous http://ift.tt/2rMFiZE
via IFTTT
Interpretations with Improv Anonymous
from Google Alert - anonymous http://ift.tt/2rhBkVz
via IFTTT
Nationals GM Mike Rizzo tells Buck Showalter, Orioles "quit whining" after complaining about Thursday's make-up game (ESPN)
via IFTTT
Ravens: TE Nick Boyle has chance to stick at top of depth chart for position filled with question marks - Jamison Hensley (ESPN)
via IFTTT
Anonymous Donors Give $5000 To Recovery Center
from Google Alert - anonymous http://ift.tt/2rc4o5j
via IFTTT
Weezer (ii. Anonymous)
from Google Alert - anonymous http://ift.tt/2rXfrwJ
via IFTTT
Warning! Hackers Started Using "SambaCry Flaw" to Hack Linux Systems
from The Hacker News http://ift.tt/2t5VIdr
via IFTTT
Anonymous People
from Google Alert - anonymous http://ift.tt/2sO3aKQ
via IFTTT
Hackers Are Using An Effective Way to Spread Fake News From Verified Accounts
from The Hacker News http://ift.tt/2sNxtkH
via IFTTT
we hear from the girlfriend of anonymous, anonymous who hates wal mart that is
from Google Alert - anonymous http://ift.tt/2sduc1j
via IFTTT
Saturn in the Milky Way
Friday, June 9, 2017
Sherman to tell his own story, not 'cowardly' anonymous sources
from Google Alert - anonymous http://ift.tt/2reZArb
via IFTTT
Flix Anonymous - Episode 29
from Google Alert - anonymous http://ift.tt/2rKq9In
via IFTTT
Orioles place P Darren O'Day (shoulder) on 10-day DL; P Stefan Crichton recalled from Triple-A (ESPN)
via IFTTT
I have a new follower on Twitter
Digital Guardian
Provider of data protection solutions and services that secure businesses around the world. Tweets about infosec news and cybersecurity tips.
Waltham, Massachusetts
http://t.co/vc6TzRrWuX
Following: 9831 - Followers: 13088
June 09, 2017 at 06:10PM via Twitter http://twitter.com/DigitalGuardian
Orioles: Manny Machado (strained left wrist) out of lineup Friday vs. Yankees; listed as day-to-day (ESPN)
via IFTTT
Sherman will tell his own story, not 'cowardly' anonymous sources
from Google Alert - anonymous http://ift.tt/2t3jKWz
via IFTTT
Anonymous $2.5M Gift Launches Trauma Initiative at McLean
from Google Alert - anonymous http://ift.tt/2s5yhnk
via IFTTT
Feature request: allow anonymous types to be used as return types and generic arguments
from Google Alert - anonymous http://ift.tt/2t3s20E
via IFTTT
Ravens: John Harbaugh confident in team's safety for London trip in wake of recent UK attacks - Jamison Hensley (ESPN)
via IFTTT
ISS Daily Summary Report – 6/08/2017
from ISS On-Orbit Status Report http://ift.tt/2smnPbI
via IFTTT
Re: [FD] libcroco multiple vulnerabilities
Source: Gmail -> IFTTT-> Blogger
Anonymous Sourcing Under Siege: CNN, NY Times Bungle Trump Reports
from Google Alert - anonymous http://ift.tt/2rSN9TM
via IFTTT
First-Ever Data Stealing Malware Found Using Intel AMT Tool to Bypass Firewall
from The Hacker News http://ift.tt/2rHYGqR
via IFTTT
M27 Not a Comet
Thursday, June 8, 2017
Download Not God: A History of Alcoholics Anonymous Read / PDF / Book / Audio id:6qix6rn
from Google Alert - anonymous http://ift.tt/2r7YQJh
via IFTTT
New Insider Fast build with anonymous guest join, touch bar support, and other features!
from Google Alert - anonymous http://ift.tt/2rRVTtj
via IFTTT
Ravens: Dennis Pitta remains hospitalized after re-injuring his hip; latest injury threatens to be career-ending - Jamison Hensley (ESPN)
via IFTTT
Orioles: Manny Machado day-to-day after MRI on left hand comes back clean (ESPN)
via IFTTT
22 Apple Distributors Arrested for Selling Customers’ Data in $7.4 Million
from The Hacker News http://ift.tt/2rQxmEV
via IFTTT
First Android-Rooting Trojan With Code Injection Ability Found On Google Play Store
from The Hacker News http://ift.tt/2sY4sC7
via IFTTT
[FD] libcroco multiple vulnerabilities
Source: Gmail -> IFTTT-> Blogger
ISS Daily Summary Report – 6/07/2017
from ISS On-Orbit Status Report http://ift.tt/2s7yoj9
via IFTTT
Hard-coded Passwords Make Hacking Foscam ‘IP Cameras’ Much Easier
from The Hacker News http://ift.tt/2rE7MF3
via IFTTT
Firefall by Moonlight
Wednesday, June 7, 2017
MLB Video: Orioles' Trey Mancini crushes 3-run walk-off HR two innings after hitting game-tying homer in 9-6 win over Pirates (ESPN)
via IFTTT
Orioles Video: Manny Machado takes a cleat to the wrist as he tries to tag out Andrew McCutchen (ESPN)
via IFTTT
Orioles: Manny Machado leaves game vs. Pirates in 4th inning after Andrew McCutchen slid into his left wrist (ESPN)
via IFTTT
Alcoholics Anonymous Dating Sites alcoholics anonymous dating tips
from Google Alert - anonymous http://ift.tt/2rNuJUv
via IFTTT
Enabling a flag adds session cookies to anonymous users, add warning or option for only ...
from Google Alert - anonymous http://ift.tt/2r3JbdX
via IFTTT
Ravens: Dennis Pitta's release can help lure much-needed WR - Jamison Hensley (ESPN)
via IFTTT
Orioles recall P Edwin Jackson, who will be joining his 12th team; 33-year-old had 5-6 record with 5.89 ERA for Padres last season (ESPN)
via IFTTT
Anonymous Users in Meetings
from Google Alert - anonymous http://ift.tt/2r2EalJ
via IFTTT
ISS Daily Summary Report – 6/06/2017
from ISS On-Orbit Status Report http://ift.tt/2sfVKTa
via IFTTT
Gamblers anonymous 12 steps printable
from Google Alert - anonymous http://ift.tt/2rLFI0T
via IFTTT
Beware! This Microsoft PowerPoint Hack Installs Malware Without Requiring Macros
from The Hacker News http://ift.tt/2s3Q5ju
via IFTTT
Kaspersky Accuses Microsoft of Unfairly Disabling its Antivirus in Windows 10
from The Hacker News http://ift.tt/2rTBCG0
via IFTTT
[FD] Xavier v2.4 PHP MP - SQL Injection Web Vulnerabilities
Source: Gmail -> IFTTT-> Blogger
Police rescue 16 year old from human trafficking ring following anonymous tip
from Google Alert - anonymous http://ift.tt/2rzpJ7j
via IFTTT
Tuesday, June 6, 2017
Orioles Video: Mark Trumbo drives in Adam Jones with clutch walk-off single in 10th inning for 6-5 victory over Pirates (ESPN)
via IFTTT
Anonymous Users
from Google Alert - anonymous http://ift.tt/2s2nIC9
via IFTTT
Orioles select contract of INF Ruben Tejada from Triple-A Norfolk; designate SS Paul Janish for assignment (ESPN)
via IFTTT
Creators of Bitcoin Miners Face $12 Million Fine for 'Ponzi Scheme' Scam
from The Hacker News http://ift.tt/2s0TCPz
via IFTTT
Anonymous Communications and Tips
from Google Alert - anonymous http://ift.tt/2r2ii5m
via IFTTT
Anonymous function
from Google Alert - anonymous http://ift.tt/2rxDWlh
via IFTTT
ISS Daily Summary Report – 6/05/2017
from ISS On-Orbit Status Report http://ift.tt/2qXxntL
via IFTTT
Ravens: Former Chiefs WR Jeremy Maclin planning trip to Baltimore on Wednesday - Adam Schefter; also scheduled to visit Buffalo Tuesday (ESPN)
via IFTTT
14-Year-Old Japanese Boy Arrested for Creating Ransomware
from The Hacker News http://ift.tt/2qSWhGN
via IFTTT
FBI Arrests NSA Contractor for Leaking Secrets – Here's How they Caught Her
from The Hacker News http://ift.tt/2scclXY
via IFTTT
[FD] CVE-2017-8083 CompuLab IntensePC lacks BIOS Write Protection
Source: Gmail -> IFTTT-> Blogger
[FD] X41-2017-005 - Multiple Vulnerabilities in peplink balance routers
Source: Gmail -> IFTTT-> Blogger
Anonymous user af7d3a
from Google Alert - anonymous http://ift.tt/2r0RzpT
via IFTTT
The Case of the Missing Star
Monday, June 5, 2017
Ravens sign CB Brandon Boykin; 8 INT during 5-year career with Eagles, Steelers, Panthers and Bears (ESPN)
via IFTTT
I have a new follower on Twitter
John Snow Labs
We accelerate #DataScience, #BigData & #Analytics teams in #HealthIT & #DataPhilanthropy with clean, matched, current & compliant #Data. #DataOps is our passion
Delaware, USA
https://t.co/FHCs4TNk22
Following: 9743 - Followers: 14960
June 05, 2017 at 12:23PM via Twitter http://twitter.com/JohnSnowLabs
[InsideNothing] nicholasjlennox liked your post "[FD] [ERPSCAN-16-036] SAP ASE ODATA SERVER - DENIAL OF SERVICE"
|
Source: Gmail -> IFTTT-> Blogger
[InsideNothing] nicholasjlennox liked your post "[FD] [ERPSCAN-16-036] SAP ASE ODATA SERVER - DENIAL OF SERVICE"
|
Source: Gmail -> IFTTT-> Blogger
Computing image “colorfulness” with OpenCV and Python
Today’s blog post is inspired by a question I received from a PyImageSearch reader on Twitter, @makingyouthink.
Paraphrasing the tweets myself and @makingyouthink exchanged, the question was:
Have you ever seen a Python implementation of Measuring colourfulness in natural images (Hasler and Süsstrunk, 2003)?
I would like to use it as an image/produce search engine. By giving each image a “colorfulness” amount, I can sort my images according to their color.
There are many practical uses for image colorfulness, including evaluating compression algorithms, assessing a given camera sensor module’s sensitivity to color, computing the “aesthetic qualities” of an image, or simply creating a bulk image visualization took to show a spectrum of images in a dataset arranged by colorfulness.
Today we are going to learn how to calculate the colorfulness of an image as described in Hasler and Süsstrunk’s 2003 paper, Measuring colorfulness in natural images. We will then implement our colorfulness metric using OpenCV and Python.
After implementing the colorfulness metric, we’ll sort a given dataset according to color and display the results using the image montage tool that we created last week.
To learn about computing image “colorfulness” with OpenCV, just keep reading.
Looking for the source code to this post?
Jump right to the downloads section.
Computing image “colorfulness” with OpenCV and Python
There are three core parts to today’s blog post.
First, we will walk through the colorfulness metric methodology described in in the Hasler and Süsstrunk paper.
We’ll then implement the image colorfulness calculations in Python and OpenCV.
Finally, I’ll demonstrate how we can apply the colorfulness metric to a set of images and sort the images according to how “colorful” they are. We will make use of our handy image montage routine for visualization.
To download the source code + example images to this blog post, be sure to use the “Downloads” section below.
Measuring colorfulness in an image
In their paper, Hasler and Süsstrunk first asked 20 non-expert participants to rate images on a 1-7 scale of colorfulness. This survey was conducted on a set of 84 images. The scale values were:
- Not colorful
- Slightly colorful
- Moderately colorful
- Averagely colorful
- Quite colorful
- Highly colorful
- Extremely colorful
In order to set a baseline, the authors provided the participants with 4 example images and their corresponding colorfulness value from 1-7.
Through a series of experimental calculations, they derived a simple metric that correlated with the results of the viewers.
They found through these experiments that a simple opponent color space representation along with the mean and standard deviations of these values correlates to 95.3% of the survey data.
We now now derive their image colorfulness metric:
The above two equations show the opponent color space representation where R is Red, G is Green, and B is Blue. In the first equation, is the difference of the Red channel and the Green channel. In the second equation, is represents half of the sum of the Red and Green channels minus the Blue channel.
Next, the standard deviation () and mean () are computed before calculating the final colorfulness metric, .
As we’ll find out, this turns out to be an extremely efficient and practical way for computing image colorfulness.
In the next section, we will implement this algorithm with Python and OpenCV code.
Implementing an image colorfulness metric in OpenCV
Now that we have a basic understanding of the colorfulness metric, let’s calculate it with OpenCV and NumPy.
In this section we will:
- Import our necessary Python packages.
- Parse our command line arguments.
- Loop through all images in our dataset and compute the corresponding colorfulness metric.
- Sort the images based on their colorfulness.
- Display the “most colorful” and “least colorful” images in a montage.
To get started open up your favorite text editor or IDE, create a new file named
colorfulness.py, and insert the following code:
# import the necessary packages from imutils import build_montages from imutils import paths import numpy as np import argparse import imutils import cv2
Lines 2-7 import our required Python packages.
If you do not have
imutilsinstalled on your system (v0.4.3 as of this writing), then make sure you install/upgrade it via
pip:
$ pip install --upgrade imutils
Note: If you are using Python virtual environments (as all of my OpenCV install tutorials do), make sure you use the
workoncommand to access your virtual environment first and then install/upgrade
imutils.
Next, we will define a new function,
image_colorfullness:
# import the necessary packages from imutils import build_montages from imutils import paths import numpy as np import argparse import imutils import cv2 def image_colorfulness(image): # split the image into its respective RGB components (B, G, R) = cv2.split(image.astype("float")) # compute rg = R - G rg = np.absolute(R - G) # compute yb = 0.5 * (R + G) - B yb = np.absolute(0.5 * (R + G) - B) # compute the mean and standard deviation of both `rg` and `yb` (rbMean, rbStd) = (np.mean(rg), np.std(rg)) (ybMean, ybStd) = (np.mean(yb), np.std(yb)) # combine the mean and standard deviations stdRoot = np.sqrt((rbStd ** 2) + (ybStd ** 2)) meanRoot = np.sqrt((rbMean ** 2) + (ybMean ** 2)) # derive the "colorfulness" metric and return it return stdRoot + (0.3 * meanRoot)
Line 9 defines the
image_colorfulnessfunction, which takes an
imageas the only argument and returns the colorfulness metric as described in the section above.
Note: Line 11, Line 14, and Line 17 make use of color spaces which are beyond the scope of this blog post. If you are interested in learning more about color spaces, be sure to refer to Practical Python and OpenCV and the PyImageSearch Gurus course.
To break the image into it’s Red, Green, and Blue (RGB) channels we make a call to
cv2.spliton Line 11. The function returns a tuple in BGR order as this is how images are represented in OpenCV.
Next we use a very simple opponent color space.
As in the referenced paper, we compute the Red-Green opponent,
rg, on Line 14. This is a simple difference of the Red channel minus the Blue channel.
Similarly, we compute the Yellow-Blue opponent on Line 17. In this calculation, we take half of the Red+Green channel sum and then subtract the Blue channel. This produces our desired opponent,
yb.
From there, on Lines 20 and 21 we compute the mean and standard deviation of both
rgand
yb, and store them in respective tuples.
Next, we combine the
rbStd(Red-Blue standard deviation) with the
ybStd(Yellow-Blue standard deviation) on Line 24. We add the square of each and then take the square root, storing it as
stdRoot.
Similarly, we combine the
rbMeanwith the
ybMeanby squaring each, adding them, and taking the square root on Line 25. We store this value as
meanRoot.
The last step of computing image colorfulness is to add
stdRootand 1/3
meanRootfollowed by returning the value to the calling function.
Now that our image
image_colorfulnessmetric is defined, we can parse our command line arguments:
# import the necessary packages from imutils import build_montages from imutils import paths import numpy as np import argparse import imutils import cv2 def image_colorfulness(image): # split the image into its respective RGB components (B, G, R) = cv2.split(image.astype("float")) # compute rg = R - G rg = np.absolute(R - G) # compute yb = 0.5 * (R + G) - B yb = np.absolute(0.5 * (R + G) - B) # compute the mean and standard deviation of both `rg` and `yb` (rbMean, rbStd) = (np.mean(rg), np.std(rg)) (ybMean, ybStd) = (np.mean(yb), np.std(yb)) # combine the mean and standard deviations stdRoot = np.sqrt((rbStd ** 2) + (ybStd ** 2)) meanRoot = np.sqrt((rbMean ** 2) + (ybMean ** 2)) # derive the "colorfulness" metric and return it return stdRoot + (0.3 * meanRoot) # construct the argument parse and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-i", "--images", required=True, help="path to input directory of images") args = vars(ap.parse_args())
We only need one command line argument here,
--images, which is the path to a directory of images residing on your machine.
Now let’s loop through each image in the dataset and compute the corresponding colorfulness metric:
# import the necessary packages from imutils import build_montages from imutils import paths import numpy as np import argparse import imutils import cv2 def image_colorfulness(image): # split the image into its respective RGB components (B, G, R) = cv2.split(image.astype("float")) # compute rg = R - G rg = np.absolute(R - G) # compute yb = 0.5 * (R + G) - B yb = np.absolute(0.5 * (R + G) - B) # compute the mean and standard deviation of both `rg` and `yb` (rbMean, rbStd) = (np.mean(rg), np.std(rg)) (ybMean, ybStd) = (np.mean(yb), np.std(yb)) # combine the mean and standard deviations stdRoot = np.sqrt((rbStd ** 2) + (ybStd ** 2)) meanRoot = np.sqrt((rbMean ** 2) + (ybMean ** 2)) # derive the "colorfulness" metric and return it return stdRoot + (0.3 * meanRoot) # construct the argument parse and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-i", "--images", required=True, help="path to input directory of images") args = vars(ap.parse_args()) # initialize the results list print("[INFO] computing colorfulness metric for dataset...") results = [] # loop over the image paths for imagePath in paths.list_images(args["images"]): # load the image, resize it (to speed up computation), and # compute the colorfulness metric for the image image = cv2.imread(imagePath) image = imutils.resize(image, width=250) C = image_colorfulness(image) # display the colorfulness score on the image cv2.putText(image, "{:.2f}".format(C), (40, 40), cv2.FONT_HERSHEY_SIMPLEX, 1.4, (0, 255, 0), 3) # add the image and colorfulness metric to the results list results.append((image, C))
Line 38 initializes a list,
results, which will hold a 2-tuple containing the image path and the corresponding colorfulness of the image.
We begin our loop through our images in our dataset specified by our command line argument,
--imageson Line 41.
In the loop, we first load the image on Line 44, then we resize the
imageto a
width=250pixels on Line 45, maintaining the aspect ratio.
Our
image_colorfulnessfunction call is made on Line 46 where we provide the only argument,
image, storing the corresponding colorfulness metric in
C.
On Lines 49 and 50, we draw the colorfulness metric on the image using
cv2.putText. To read more about the parameters to this function, see the OpenCV Documentation (2.4, 3.0).
On the last line of the
forloop, we append the tuple,
(imagePath, C)to the
resultslist (Line 53).
Note: Typically, you would not want to store each image in memory for a large dataset. We do this here for convenience. In practice you would load the image, compute the colorfulness metric, and then maintain a list of the image ID/filename and corresponding colorfulness metric. This is a much more efficient approach; however, for the sake of this example we are going to store the images in memory so we can easily build our montage of “most colorful” and “least colorful” images later in the tutorial.
At this point, we have answered our PyImageSearch reader’s question. The colorfulness metric has been calculated for all images.
If you’re using this for an image search engine as @makingyouthinkcom is, you probably want to display your results.
And that is exactly what we will do next, where we will:
- Sort the images according to their corresponding colorfulness metric.
- Determine the 25 most colorful and 25 least colorful images.
- Display our results in a montage.
Let’s go ahead and tackle these three tasks now:
# import the necessary packages from imutils import build_montages from imutils import paths import numpy as np import argparse import imutils import cv2 def image_colorfulness(image): # split the image into its respective RGB components (B, G, R) = cv2.split(image.astype("float")) # compute rg = R - G rg = np.absolute(R - G) # compute yb = 0.5 * (R + G) - B yb = np.absolute(0.5 * (R + G) - B) # compute the mean and standard deviation of both `rg` and `yb` (rbMean, rbStd) = (np.mean(rg), np.std(rg)) (ybMean, ybStd) = (np.mean(yb), np.std(yb)) # combine the mean and standard deviations stdRoot = np.sqrt((rbStd ** 2) + (ybStd ** 2)) meanRoot = np.sqrt((rbMean ** 2) + (ybMean ** 2)) # derive the "colorfulness" metric and return it return stdRoot + (0.3 * meanRoot) # construct the argument parse and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-i", "--images", required=True, help="path to input directory of images") args = vars(ap.parse_args()) # initialize the results list print("[INFO] computing colorfulness metric for dataset...") results = [] # loop over the image paths for imagePath in paths.list_images(args["images"]): # load the image, resize it (to speed up computation), and # compute the colorfulness metric for the image image = cv2.imread(imagePath) image = imutils.resize(image, width=250) C = image_colorfulness(image) # display the colorfulness score on the image cv2.putText(image, "{:.2f}".format(C), (40, 40), cv2.FONT_HERSHEY_SIMPLEX, 1.4, (0, 255, 0), 3) # add the image and colorfulness metric to the results list results.append((image, C)) # sort the results with more colorful images at the front of the # list, then build the lists of the *most colorful* and *least # colorful* images print("[INFO] displaying results...") results = sorted(results, key=lambda x: x[1], reverse=True) mostColor = [r[0] for r in results[:25]] leastColor = [r[0] for r in results[-25:]][::-1]
On Line 59 we sort the
resultsin reverse order (according to their colorfulness metric) making use of Python Lambda Expressions.
Then on Line 60, we store the 25 most colorful images into a list,
mostColor.
Similarly, on Line 61, we load the least colorful images which are the last 25 images in our results list. We reverse this list so that the images are displayed in ascending order. We store these images as
leastColor.
Now, we can visualize the
mostColorand
leastColorimages using the
build_montagesfunction we learned about last week.
# import the necessary packages from imutils import build_montages from imutils import paths import numpy as np import argparse import imutils import cv2 def image_colorfulness(image): # split the image into its respective RGB components (B, G, R) = cv2.split(image.astype("float")) # compute rg = R - G rg = np.absolute(R - G) # compute yb = 0.5 * (R + G) - B yb = np.absolute(0.5 * (R + G) - B) # compute the mean and standard deviation of both `rg` and `yb` (rbMean, rbStd) = (np.mean(rg), np.std(rg)) (ybMean, ybStd) = (np.mean(yb), np.std(yb)) # combine the mean and standard deviations stdRoot = np.sqrt((rbStd ** 2) + (ybStd ** 2)) meanRoot = np.sqrt((rbMean ** 2) + (ybMean ** 2)) # derive the "colorfulness" metric and return it return stdRoot + (0.3 * meanRoot) # construct the argument parse and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-i", "--images", required=True, help="path to input directory of images") args = vars(ap.parse_args()) # initialize the results list print("[INFO] computing colorfulness metric for dataset...") results = [] # loop over the image paths for imagePath in paths.list_images(args["images"]): # load the image, resize it (to speed up computation), and # compute the colorfulness metric for the image image = cv2.imread(imagePath) image = imutils.resize(image, width=250) C = image_colorfulness(image) # display the colorfulness score on the image cv2.putText(image, "{:.2f}".format(C), (40, 40), cv2.FONT_HERSHEY_SIMPLEX, 1.4, (0, 255, 0), 3) # add the image and colorfulness metric to the results list results.append((image, C)) # sort the results with more colorful images at the front of the # list, then build the lists of the *most colorful* and *least # colorful* images print("[INFO] displaying results...") results = sorted(results, key=lambda x: x[1], reverse=True) mostColor = [r[0] for r in results[:25]] leastColor = [r[0] for r in results[-25:]][::-1] # construct the montages for the two sets of images mostColorMontage = build_montages(mostColor, (128, 128), (5, 5)) leastColorMontage = build_montages(leastColor, (128, 128), (5, 5))
A most-colorful and least-colorful montage are each built on Lines 64 and 65. Here we indicate that all images in the montage will be resized to 128 x 128 and there will be 5 columns by 5 rows of images.
Now that we have assembled the montages, we will display each on the screen.
# import the necessary packages from imutils import build_montages from imutils import paths import numpy as np import argparse import imutils import cv2 def image_colorfulness(image): # split the image into its respective RGB components (B, G, R) = cv2.split(image.astype("float")) # compute rg = R - G rg = np.absolute(R - G) # compute yb = 0.5 * (R + G) - B yb = np.absolute(0.5 * (R + G) - B) # compute the mean and standard deviation of both `rg` and `yb` (rbMean, rbStd) = (np.mean(rg), np.std(rg)) (ybMean, ybStd) = (np.mean(yb), np.std(yb)) # combine the mean and standard deviations stdRoot = np.sqrt((rbStd ** 2) + (ybStd ** 2)) meanRoot = np.sqrt((rbMean ** 2) + (ybMean ** 2)) # derive the "colorfulness" metric and return it return stdRoot + (0.3 * meanRoot) # construct the argument parse and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-i", "--images", required=True, help="path to input directory of images") args = vars(ap.parse_args()) # initialize the results list print("[INFO] computing colorfulness metric for dataset...") results = [] # loop over the image paths for imagePath in paths.list_images(args["images"]): # load the image, resize it (to speed up computation), and # compute the colorfulness metric for the image image = cv2.imread(imagePath) image = imutils.resize(image, width=250) C = image_colorfulness(image) # display the colorfulness score on the image cv2.putText(image, "{:.2f}".format(C), (40, 40), cv2.FONT_HERSHEY_SIMPLEX, 1.4, (0, 255, 0), 3) # add the image and colorfulness metric to the results list results.append((image, C)) # sort the results with more colorful images at the front of the # list, then build the lists of the *most colorful* and *least # colorful* images print("[INFO] displaying results...") results = sorted(results, key=lambda x: x[1], reverse=True) mostColor = [r[0] for r in results[:25]] leastColor = [r[0] for r in results[-25:]][::-1] # construct the montages for the two sets of images mostColorMontage = build_montages(mostColor, (128, 128), (5, 5)) leastColorMontage = build_montages(leastColor, (128, 128), (5, 5)) # display the images cv2.imshow("Most Colorful", mostColorMontage[0]) cv2.imshow("Least Colorful", leastColorMontage[0]) cv2.waitKey(0)
On Lines 68 and 69 we display each montage in a separate window.
The
cv2.waitKeycall on Line 70 pauses execution of our script until we select a currently active window. When a key is pressed, the windows close and the script exits.
Image colorfulness results
Now let’s put this script to work and see the results. Today we will use a sample (1,000 images) of the popular UKBench dataset, a collection of images containing everyday objects.
Our goal is to sort the images by most colorful and least colorful.
To run the script, fire up a terminal and execute the following command:
$ python colorfulness.py --images ukbench_sample
Notice how our image colorfulness metric has done a good job separating non-colorful images (left) that are essentially black and white from “colorful” images that are vibrant (right).
Summary
In today’s blog post we learned how to compute the “colorfulness” of an image using the approach detailed by Hasler and Süsstrunk’s in their 2003 paper, Measuring colorfulness in nature images.
Their method is based on the mean and standard deviation of pixel intensities values in an opponent color space. This metric was derived by examining correlations between experimental metrics and the colorfulness assigned to images by participants in their study.
We then implemented the image colorfulness metric and applied it to the UKBench dataset. As our results demonstrated, the Hasler and Süsstrunk method is a quick and easy way to quantify the colorfulness contents of an image.
Have fun using this method to experiment with the image colorfulness in your own datasets!
And before you go, be sure to enter your email address in the form below to be notified when new tutorials are published here on the PyImageSearch blog.
Downloads:
The post Computing image “colorfulness” with OpenCV and Python appeared first on PyImageSearch.
from PyImageSearch http://ift.tt/2rsPSoh
via IFTTT