-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlowlevelfeatureextraction.py
More file actions
executable file
·106 lines (80 loc) · 2.74 KB
/
lowlevelfeatureextraction.py
File metadata and controls
executable file
·106 lines (80 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 25 00:45:35 2015
@author: p
"""
import numpy as np
import cv2
import os
from shannonsEntropy import calcentropy
from whitecontrib import whiteContrib
from countobjects import countObjects
'''compute the first two color moments of an image(which has colour),grayscale images are represented bas
% input: image to be analyzed and extract 2 first moments from each R,G,B
% output: 1x6 vector containing the 2 first color momenst from each R,G,B
% construct output vector
colorMoments = zeros(1, 6);
colorMoments(1, :) = [meanR stdR meanG stdG meanB stdB];
% clear workspace
clear('R', 'G', 'B', 'meanR', 'stdR', 'meanG', 'stdG', 'meanB', 'stdB');
end'''
'''Steps to follow
1) Go into the keyframeswalk directory
2) for each image calculate all params
3) Store in a lowlevelfeature matrix for each image
dimensions
1-Which Main video we are considering
2-keyframe number corresponding to the main video
3-color moments
'''
'''
Calculate the Shannon Entropy for a given image
This is dimension number 7 (6 in terms of array indexing in our feature matrix)
Next we calculate how much of the image is dominated by white components which
is stored in dimension 8
We calculate the number of contours present in the image, this is a slightly
inaccurate measure for object detection due to the presence of noise but for
now,we keep it - dimension 9
'''
'''
We label the first 3 training examples of every type of video processed by
creating a matrix of N videos * d categories
0-Human Being
1-Nature
'''
lowlvlfeatures = np.zeros((34,28,9),float)
labelmatrix = np.zeros((34,3),int)
pathforkeyframeswalk = "/home/p/Desktop/Major-Project/keyFramesWalk/"
os.chdir(pathforkeyframeswalk)
workingdirectory = os.listdir( pathforkeyframeswalk )
# This would print all the files and directories
for file in workingdirectory:
split = file.split('.')
firstpart = split[0].split(' ')
videonum = int(firstpart[1])
secondpart = split[1].split(' ')
imagenum = int(secondpart[1])
img = cv2.imread(file)
B = img[:,:,0]
G = img[:,:,1]
R = img[:,:,2]
meanR = np.mean(R[:])
stdR = np.std(R[:])
meanG = np.mean(G[:])
stdG = np.std(G[:])
meanB = np.mean(B[:])
stdB = np.std(B[:])
entropy = calcentropy(file,B,G,R)
whitecontrib = whiteContrib(file)
countobj = countObjects(file)
lowlvlfeatures[videonum,imagenum,:] = [meanR, stdR, meanG, stdG, meanB, stdB,entropy,whitecontrib,countobj]
#Labelling the Human videos
labelmatrix[0] = [1,0,0]
labelmatrix[1] = [1,0,0]
labelmatrix[2] = [1,0,0]
labelmatrix[12] = [0,1,0]
labelmatrix[13] = [0,1,0]
labelmatrix[14] = [0,1,0]
labelmatrix[21] = [0,0,1]
labelmatrix[22] = [0,0,1]
labelmatrix[23] = [0,0,1]