Matlab, Color and Statistics

Matlab, Color and Statistics
Color/Histogram/Similarity 1. Attempt
•Different color systems
•Distribution of colors in an image
•How to compare descriptions of different images
RGB related Color Systems
Most images today are stored in RGB format
A color pixel [C] on a monitor is generated by
adding weighted amounts of primary colors
C = R + G + B
with 0  , ,   1
All RGB colors can be visualized as a cube
HSV System
Color is characterized by three attributes:
HUE: red-yellow-green-blue-magenta
SATURATION: absence of white, grey-pink-red
VALUE/INTENSITY: black-white
Matlab functions rgb2hsv and hsv2rgb:
Him = rgb2hsv(Rim)
Rim is mxnx3 RGB image and Him is mxnx3 HSV image
Him(:,:,1) from 0 to 1: resulting color varies red, yellow, green, blue, …
Him(:,:,2) = 0, colors are unsaturated (gray), H(:,:,2) = 1, fully saturated
Him(:,:,3) = 0, black and H(:,:,3) = 1, white
Hue is an angle, Saturation and Value are intervals
HSV Color Space
Relation between HSV and RGB
Computer Vision Opponent Color
Systems
Convert RGB into opponent-like color system:
Used in Semantic Pathfinder:
CIE Color Matching Functions
z( )
y( )
x( )
A special transformation lead to
the CIE color matching functions
x( ), y( ), z( )
Motivation:
• Positive functions are to easier to
use in computations (done by hand!)
• Positive functions can be
implemented in hardware
• The y-functions describes spectral
sensitivity of human color vision
CIEXYZ
Collect the CIE color matching functions in the weight matrix WCIE.
Define the co-ordinates of a stimulus C by:
The constant k is selected such that Y = 100 for a given white color
CIELAB
CIELUV
Some Useful Matlab Commands
http://webstaff.itn.liu.se/~reile/edu/TNM025/Matlab/html/ColorAndBasics.html
Reading images
Conversion
Scaling
Image types
Color Commands
Programming style (like usage of : )
Display
Color Spaces
Global Color Properties of Images
Mainly Red
Mainly Blue&White
Mainly Green&Brown
Characterization by Mean Gray
Value
rgb2gray Convert a truecolor image to a grayscale image.
Characterization by Mean and Variance
Distance between Images Similarity of Images
Description by a single value: Mean
Image I1 with Mean m1
and
Image I2 with Mean m2
Distance:
Similarity: m1m2
Advantage: I1 query image and I2 database image
then mean-terms can be pre-computed
m1  m2  m1  m2   m12  m22  2m1m2
2
2
Signature-based Retrieval
General Strategy:
1. Select a property (intensity/hue/texture…)
2. Design a method to measure this property
3. Do it for all/some/selected pixels/parts of an image
4. Estimate probability distribution p of measurements
5. Compute key-numbers x(p) from p (mean/…)
6. Design a measure to compute distances between
x(p) and x(q) for two distributions/images p,q
Distance between Images/Similarity of
Images
Description by Mean and
Variance?
Green = Cat
Blue = Polar Bear
Red = Sunset
Basic Probability Theory (Scalar)
x is a (scalar) variable defined on a space X
p(x) is a probability if
Mean (1. order moment):
2. order moment
Variance (centered 2. order moment):
Standard deviation:
Basic Probability Theory (Vector)
x is a vector
M = E(x) is mean vector
C = E(xx’) is (auto-) correlation matrix
V = E((x-M)(x-M)’) is the covariance matrix
cij = E((xi-mi)(xj-mj)) (ij) entry in the covariance matrix
cii = i2 is the variance of xi
i is the standard deviation of xi
cij = ij ij
ij is the correlation coefficient
Discrete Probablity Distributions
The variable can only assume a finite number (L) of values
for example 0 and 1 (coin flipping)
Binomial :
 N  N k
1  p k
Bp,N (k )    p
k
The distribution is given by the L numbers in the L-dimensional vector
(p1, …, pL)
this vector is the probability density function (pdf)
The cumulative distribution function (cdf) is given by the sums
(p1, p1 + p2 ,…, p1 + p2 …+ pL)
Continuous Probability Distributions
Normal distribution (1-D)

1
N m ( x) 
exp  ( x  m) 2 / 2 2
 2

Normal distribution (n-D)
M is the mean vector and  is the covariance matrix
Histograms Gray Valued Images
Grey value histogram gives the probability of
a given grey value range
Here 32*(0,1,2,3,4,5,6,7)
Few pixels in range (0,31), almost none in (224,255)
most in middle range
Histograms
Mean/Variance are PARAMETRIC descriptions of densities
Histograms are NON-PARAMETRIC descriptions of densities
Consider the range of values is [0,1] (or {0, …, 255} etc)
Divide range into K sets B1, …, BK also called bins
count how many samples hk lie in Bk.
pk = hk/(h1+…+hK)
gives the estimated probability distribution (p1, …, pK)
Example Gray Valued Image
 1 2 70 80 


Image  2 32 200 221
 9 110 90 80 


Example 1:
B1 = 0…127
B2 = 128 … 255
Range = 0… 255
2 Bins
h1 = 10; h2 = 2
p1 = 5/6; p2 = 1/6
Example 2:
B1 = 0…63
B2 = 64…127
B3 = 128…191
B4 = 192…255
Range = 0… 255
4 Bins
h1 = 5; h2 = 5; h3=0;h4=2
p1 = 5/12; p2 = 5/12
p3 = 0; p4 = 2/12
Histograms and Binary Numbers
The binary number 01100010 is a short notation of
1 * 64 + 1*32 + 1*2 = 1*26+1*25+1*21 = 64+32+2 = 98
It is < 128 = 27 (leading 0)
Shift one position to the left
01100010 -> 1100010
Rest is > 64 = 26 (new leading 1)
Shift one position to the left
1100010 -> 100010
Rest is > 32= 25 (new leading 1)
etc.
If we want an 8-bin histogram the index of the gray value 98 is 011 = 3
and if we start counting bins with 1 then we have entry 3+1=4
Matlab Demo Image Statistics
..\Matlab\html\BasicImageStatistics.html
Manipulation of path- and filenames name
Basic statistics mean, std, hist, ecdf
..\Matlab\html\BasicStatToolbox.html
Basics from the statistics toolbox