"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

August 30, 2015

Video Analytics Class 2

My Notes
  • Linear Filter - Linear combination of neighbours
  • Box filter - All values constant [1's]
  • Corr-relation - Masked and Moved across Image
  • Gradient  - due to surface normal discontinuity, depth discontinuity, illumination discontinuity
  • LOG - Laplace of Gaussian. LOG capable of finding edges
  • Salt and Pepper Image - Image has random black and white 
Basics
  • Represent Image as a Matrix
  • Represent Image as a function
  • Point, local operations, histogram equalization, moving average model
  • Cross Correlation g = H X F
  • Gaussian filter (Removes High frequency, blurring, smoothens image)
  • Symmetric Matrix (When you shift rows into columns it would appear the same ( aij = aji, for all indices i and j) example link 
Convolution Basics
Programmatic Walkthru - link

From link 
From link

From Link
FFT

Convolution Applications
  • Smoother image
  • Gaussian (Point spread function)
  • Different Kinds of filter (Box, Gaussian filter)

Cross Correlation - Assess how similar are two different functions. Compares position by position. 
Correlation Walkthru

From Link 

Mathematics concepts to learn
  • Vector Product
  • Eigen Value decomposition
  • First Derivative, Second Derivative
Vertical and horizontal edge detection filters - Sobel, Roberts, Prewitt (Veritical, Horizontal, Diagonal edge detection filters).

Good Read Link
MIT Course Slides link

Related Reads







Happy Learning!!!

August 25, 2015

OpenCV Python Basics

Basic image loading modules

Example #1

import cv2
import numpy as np
from matplotlib import pyplot as plt
#Load Image
source = cv2.imread('D:\images\Benz.png')

Ref - Link

Example #2

#Printing width and height of image
import cv2
import numpy as np
from matplotlib import pyplot as plt

#Load Image
source = cv2.imread('D:\images\Benz.png')
print source.shape

#Output Number of Rows / Columns
rowCount = source.shape[0]
columnCount = source.shape[1]
print rowCount, columnCount

Ref - Link

Example #3
#Drawing Histogram

import cv2
import numpy as np
from matplotlib import pyplot as plt

#Load Image
source = cv2.imread('D:\images\Benz.png')

# Image, Channel
# Channels - grayscale image - [0], RGB - 0,1,2
# Mask - Supplied None as FULL Region Needed
# histSize - Bin Size
# ranges - 0 to 256
hist = cv2.calcHist([source], [0], None, [256], [0,256])
plt.plot(hist)
plt.show()

Happy Learning!!!

August 24, 2015

SettingUp OpenCV and Python

Reference Steps - Link

1. Download and Install python from link. Install with Default Settings
2. Download and Install MatPlot Lib (Link in reference steps are fine)
3. Download and Install OpenCV executable. Extract it to C:\OpenCV location
4. Now All Installations are located in C:\
5. Open Python IDLE from program files. In win7 run-it-as admin to open Program Files ->Python IDLE
6. Copy File from below location
      From - C:\OpenCV\opencv\build\python\2.7\x86\cv2.pyd
      To - C:\Python27\Lib\site-packages
7. Got the Error Link
8. Download and install numpy from link (Link provided 1.7 of numpy is incorrect. You need 1.9.2)
9. Validating installation steps

Happy Learning!!!

August 23, 2015

Video Analytics Concepts

  • Image - Matrix of Intensity Values
  • Each pixel has a byte where you can store information
  • Image can be represented in a matrix
  • Image can be represented as a function
Image Processing Operations
  • Point, Local, Global
  • Point - Take every pixel and perform operation
  • Local - Local Neighbourhood data manipulation. Global is extension of local
Point Operations
  • Image Enhancement - new_Pixel = max-old_Pixel+min
  • Contrast Stretching - Histogram stretching

Options
  • Local - Noise reduction using moving average
  • Weighted sum of neighbours computation
  • Linear Filtering - Cross Correlation, Gaussian Filter
  • Convolution Vs Correlation
Happy Learning!!!

Statistical Programming Notes - Class 1

Basics
  • Probability - Study of randomness and uncertainty
  • Random Experiment - Process whose outcome we cannot say predictably
  • Sample Space - All possible outcomes
  • Event - Subset of Sample Space
  • Probability Value - Expected occurence of outcome
Concept #1
Frequentist View 

P(Event) = Number of Times Expected Event Occured / Total Number of Events
P(A) = N(A) / N

Probability P of an uncertain event A, written P(A), is defined by the frequency of that event based on previous observations

More Reads on this topic
Frequentism and Bayesianism: A Practical Introduction

Concept #1.1
Bayesian - Assign based on Intuition

Concept #2 - Conditional Probability
P(E) occurring given that another dependant event has already occurred

P(A/B) = P(A Intersection B) / P(B)

More Read - Link

Bayes Theorem
Three production lines
48% Red - 6% Production Line Defective
31% Blue - 11% Production Line Defective
21% White - 8% Production Line Defective

P(R/D) = P(R Intersection D) / P(D)

P(R) = .48
P(D/R) = 0.06
P(D) = P(D/R)P(R) + P(D/W)P(W) + P(D/B)P(B)

P(R/D) = P(R Intersection D) / P(D)

P(R/D) = P(R Intersection D) / (P(D/R)P(R) + P(D/W)P(W) + P(D/B)P(B))

Concept #5
Independent Events - Independent Events are not affected by previous events

Dependent Events - Taking coloured marbles from a bag: as you take each marble there are less marbles left in the bag, so the probabilities change.

Independent Events - Taking and replacing coloured marbles from a bag: as you take each marble there are same marbles left in the bag, so the probabilities won't change.

R Programming Concepts
  • R - Interpreted language
  • Assignment operator =, <-
  • Vector - Same as Arrays in other languages
  • B <- matric(c(2,4,3,1,5,7) nrow = 3, ncol = 2). matrix(rows, columns)
  • In Matrix - Data Filled in columnar manner
  • matrix columnar, rowwise operations possible using apply command apply(b,2,mean) - Columnar mean, apply(b,1,mean) - rowwise mean
  • Data Frame - Way to store different types of columns, Values in one particular column need to be of same data type
Happy Learning!!!

August 19, 2015

Basics - Excellent Read for Database Enthusiasts

Basics - Excellent Read for Database Enthusiasts - How RDBMS works

Happy Learning!!!

August 17, 2015

Variance and Standard Deviation Example

Basic Example for Variance, Standard Deviation Computation



Happy Learning!!!

R Notes

Matrices
Tip #1 
Declaration - matrix (0,3,4)
3 rows, 4 columns and values 0
print[1,1]

Tip #2
Vector a <- 1:12 (To fill Matrix)
matrix(a, 3, 4)

Tip #3

Assigning, Fetching & Printing values
plank <- 1:8 - Create Vector
dim(plank) <- c(2,4) - Assign Dimension
print(plank) - Print values
plank[1,4] <- 0 - Assign value
plank[2,] - Fetch all 2nd row values

Tip #4 - Plotting Matrix

elevation <- matrix(2,5,10)
contour(elevation) - 2D representation
persp(elevation) - 3D representation
persp(elevation, expand = 0.2)

Statistics
Tip #1 - Mean computation
a <- c(1,2,3,4,5)
mean(a)
barplot(a)
median(a)

Tip #2
Horizontal line across plots
abline(h=mean(a))
abline(h=median(a))

Tip #3 
Standard Deviation
deviation <- sd(a)

Factors
Tip #1 
R has special collection called factors
chests <- c('gold', 'silver', 'gems', 'gold', 'gems')
types <- factor(chests)
print(types)

Data Frame
Similar to Database
Tip #1 - Loading data from files
read.csv("data.csv")
read.table("a.txt",sep="\t")

Tip #2 - Merge Data Frames
data1 <- read.csv("data.csv")
data2 <- read.table("a.txt",sep="\t")
merge(x = data1, y = data2)

Real World Examples
Data1 <- read.csv("a.csv")
Data2 <- read.table("b.txt", sep="  ", header=TRUE)
TargetData <- merge(x = Data1, y = Data2)
plot(TargetData$Data1, TargetData$Data2)

August 16, 2015

R Online Learning


I prefer to switch topics when I find it tricky to focus on one topic. I found R language easy, simple and great to get started. Codeschool has a beautiful self learning portal. This lists cheat sheet and fundamentals working with R. Capturing some of notes for my future reference.

Using R

Tip #1 - Assignment
x <- 42
y <- "Hello"

Tip #2 - Expression
5==10
5>10

Tip #3 - Arithmetic operations
2+2
3*3

Tip #4 - Functions
sum(1,2)
sum(1,2,3,4)

Help

Tip #5 - File I/O
list.files()
source(filename)

Vectors

Tip #1 - Vector
List of Values - vector represented by c(2,3,4)
List of Strings - vector represented by c('a','b','c')
List with multiple data types - vector represented by c(1,'a', TRUE)

Tip #2 - Sequence Vectors
Representing sequence of numbers m to b by m:n
 - seq(10,50)
 - seq(10,50,5) - With increment step 5
 - seq(50,10) - Reverse sequence representation

Tip #3 - Assigning Vectors (Single Quotes)
sentence <- c('walk', 'the', 'plank')
sentence[3]
a <- c (1,2,3)
b <- c (1,2,3)

Sample Vector Operations
a+1
a*2
a+b

x <- seq(1, 20, 0.1)
y <- sin(x)

Tip #4
c for combine vectors
c(1,2,3)

Tip #5
Plotting Vectors
vectorCoordinates <- c(4, 5, 1)
barplot(vectorCoordinates)
barplot(1:100)

x <- seq(1, 20, 0.1)
y <- sin(x)
plot(x,y)

Great Learning Sites
Statsmethod
Code School

Happy Learning!!!

August 15, 2015

Recommendation Algorithm Analysis

Item to Item Rating based on customer’s purchase of products


The formula for comparison is dot product divided by product of vector lengths
In the example for two sets Book and DVD
  • Book – (1,1,1) – Set A consider it as (A1, A2, A3)
  • DVD – (1,0,0) – Set B consider it as (B1, B2, B3)
Formula works as
  • (A1.B1 + A2.B2 + A3.B3) /sqrt((A1 square + A2 Square + A3 Square)( B1 square + B2 Square + B3 Square))
  • (1)/sqrt((3).sqrt(1)
  • 1 / 1.732
  • 0.577
     Item to Item Comparison based on customer ratings

The formula for comparison is dot product divided by product of vector lengths
In the example for two sets Book and DVD
  • Book – (4,3,5) – Set A consider it as (A1, A2, A3)
  • DVD – (1,0,0) – Set B consider it as (B1, B2, B3)
Formula works as 
  • (A1.B1 + A2.B2 + A3.B3) /sqrt((A1 square + A2 Square + A3 Square)( B1 square + B2 Square + B3 Square))
  • (4)/sqrt((16+9+25).sqrt(1)
  • 4/7.07
  • 0.565
Analysis - By comparing multiple items the items that yield the maximum value would be recommended to the customer

Happy Learning!!!

August 14, 2015

Good Courses

Bookmarking two useful courses on Statistics and Machine Learning

Machine Learning Coursera

Statistics 110


Statistics and Data



Statistics One


Descriptive Statistics





Happy Learning!!!

Inverse Matrix Computation

Matrix A Represented by




Reference - Link

Happy Learning!!!


August 13, 2015

Matrix and Determinants (Basics)

Back to School and basics. These posts are for my on-line references.

Matrix
  • Rectangular Array of Numbers in rows and columns
  • Example - [5,2,-3]
  • Order of Matrix is represented as Rows X Columns
Types of Matrices
  • Row matrix (1 Row, any number of columns)
  • Column matrix (1 Column, Multiple Rows)
  • Diagonal matrix (Square matrix, Except diagonal elements every other elements are 0)
  • Scalar matrix (Square matrix & Diagonal matrix in which all diagonal elements are same)
  • Identity matrix - Denoted by I - Diagonal Elements are 1 (Square & Diagonal Matrix)
  • Transpose of matrix - Matrix where rows and columns are interchanged
        [ 1, 1, 1 ]
A  = [ 2, 2, 2 ]
        [ 3, 3, 3 ]

Transpose is

A' =   [ 1, 2, 3 ]
          [ 1, 2, 3 ]
         [ 1, 2, 3 ]

Addition of Matrices
  • They should be of same order
  • Add Corresponding elements

A =   [2,3,5]
         [5,7,-2]
        [5,3,0]

B =    [7,-1,5]
          [0,2,3]
         [7,5,2]

Result ( Add Corresponding elements in same positions)

A + B =     [9,2,10]
         [5,9,1]
               [12,8,2]

Subtraction (similar to addition)
  • Order needs to match
A = [7,-2]
       [0,3]

B = [0,2]
[3,5]

A - B = [7,-4]
          [-3,-2]

Scalar Multiplication
  • Multiplying constant with a Matrix
  • Every Element of Matrix Multipled
c = [3,5]
[-2,-10]

-2c =  [-6,-10]
  [4,20]

Matrix Multiplication
  • A (m x n)
  • B (n x p)
  • Columns in a (n) = Number of Rows in B (n)
A = [3,5]
[7,2]
[2,3]

B = [-2,5]
[3,7]

AB = Operate First Row (Operate) Multiple with First Coulmn

A = [3,5] --->
[7,2]
[2,3]

Select Column 
B = [-2,5] 
[3,7]  

  = [ 3 X -2 + 5 X 3,  3 X 5 + 5 X 7 ]
[ 7 X -2 + 2 X 3,  7 X 5 + 2 X 7 ]
[ 2 X -2 + 3 X 3,  2 X 5 + 3 X 7 ]

 = [9,50]
[-8,49]
[5,31]

Matrix Multiplication is not commutative

Determinant of Square Matrix
+  -
A = [5,6]
[3,-4]

|A| = [Multiply Principal Diagonal Elements ] - [Subtract the Next Diagonal Elements]
= (5 X -4) - (3 X 6)
      = -20 - 18
      = -38

Determinant of 3 X 3 Matrix
        +,-,+
A =  [3,-2,1]
       [2,3,4]
       [2,5,4]

= +3 X [3,4] - (-2) X [2,4] + 1 X [2,3]
                  [5,4]               [2,4]           [2,5]

= 3(12-20) + 2 (8-8) + 1(10-6)
       = -24 + 0 + 4
       = -20

References - Link

Happy Learning!!!