Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.pad.face
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bob
bob.pad.face
Commits
91b1f278
There was a problem fetching the pipeline summary.
Commit
91b1f278
authored
7 years ago
by
Olegs NIKISINS
Browse files
Options
Downloads
Patches
Plain Diff
Added spatially enhanced histogram histogram option to LBPHistogram class
parent
ffd5e023
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!61
Added spatially enhanced histogram option to LBPHistogram class
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/pad/face/extractor/LBPHistogram.py
+51
-8
51 additions, 8 deletions
bob/pad/face/extractor/LBPHistogram.py
with
51 additions
and
8 deletions
bob/pad/face/extractor/LBPHistogram.py
+
51
−
8
View file @
91b1f278
...
@@ -2,7 +2,7 @@ from __future__ import division
...
@@ -2,7 +2,7 @@ from __future__ import division
from
bob.bio.base.extractor
import
Extractor
from
bob.bio.base.extractor
import
Extractor
import
bob.bio.video
import
bob.bio.video
import
bob.ip.base
import
bob.ip.base
import
numpy
import
numpy
as
np
class
LBPHistogram
(
Extractor
):
class
LBPHistogram
(
Extractor
):
...
@@ -24,6 +24,12 @@ class LBPHistogram(Extractor):
...
@@ -24,6 +24,12 @@ class LBPHistogram(Extractor):
computed (4, 8, 16)
computed (4, 8, 16)
circ : bool
circ : bool
True if circular LBP is needed, False otherwise
True if circular LBP is needed, False otherwise
n_hor : int
Number of blocks horizontally for spatially-enhanced LBP/MCT
histograms. Default: 1
n_vert
Number of blocks vertically for spatially-enhanced LBP/MCT
histograms. Default: 1
Attributes
Attributes
----------
----------
...
@@ -40,7 +46,9 @@ class LBPHistogram(Extractor):
...
@@ -40,7 +46,9 @@ class LBPHistogram(Extractor):
rad
=
1
,
rad
=
1
,
neighbors
=
8
,
neighbors
=
8
,
circ
=
False
,
circ
=
False
,
dtype
=
None
):
dtype
=
None
,
n_hor
=
1
,
n_vert
=
1
):
super
(
LBPHistogram
,
self
).
__init__
(
super
(
LBPHistogram
,
self
).
__init__
(
lbptype
=
lbptype
,
lbptype
=
lbptype
,
...
@@ -49,7 +57,8 @@ class LBPHistogram(Extractor):
...
@@ -49,7 +57,8 @@ class LBPHistogram(Extractor):
neighbors
=
neighbors
,
neighbors
=
neighbors
,
circ
=
circ
,
circ
=
circ
,
dtype
=
dtype
,
dtype
=
dtype
,
)
n_hor
=
n_hor
,
n_vert
=
n_vert
)
elbps
=
{
elbps
=
{
'
regular
'
:
'
regular
'
,
'
regular
'
:
'
regular
'
,
...
@@ -117,9 +126,12 @@ class LBPHistogram(Extractor):
...
@@ -117,9 +126,12 @@ class LBPHistogram(Extractor):
self
.
dtype
=
dtype
self
.
dtype
=
dtype
self
.
lbp
=
lbp
self
.
lbp
=
lbp
self
.
n_hor
=
n_hor
self
.
n_vert
=
n_vert
def
__call__
(
self
,
data
):
def
comp_block_histogram
(
self
,
data
):
"""
Extracts LBP histograms from a gray-scale image.
"""
Extracts LBP/MCT histograms from a gray-scale image/block.
Takes data of arbitrary dimensions and linearizes it into a 1D vector;
Takes data of arbitrary dimensions and linearizes it into a 1D vector;
Then, calculates the histogram.
Then, calculates the histogram.
...
@@ -135,12 +147,11 @@ class LBPHistogram(Extractor):
...
@@ -135,12 +147,11 @@ class LBPHistogram(Extractor):
1D :py:class:`numpy.ndarray`
1D :py:class:`numpy.ndarray`
The extracted feature vector, of the desired ``dtype`` (if
The extracted feature vector, of the desired ``dtype`` (if
specified)
specified)
"""
"""
assert
isinstance
(
data
,
n
umpy
.
ndarray
)
assert
isinstance
(
data
,
n
p
.
ndarray
)
# allocating the image with lbp codes
# allocating the image with lbp codes
lbpimage
=
n
umpy
.
ndarray
(
self
.
lbp
.
lbp_shape
(
data
),
'
uint16
'
)
lbpimage
=
n
p
.
ndarray
(
self
.
lbp
.
lbp_shape
(
data
),
'
uint16
'
)
self
.
lbp
(
data
,
lbpimage
)
# calculating the lbp image
self
.
lbp
(
data
,
lbpimage
)
# calculating the lbp image
hist
=
bob
.
ip
.
base
.
histogram
(
lbpimage
,
(
0
,
self
.
lbp
.
max_label
-
1
),
hist
=
bob
.
ip
.
base
.
histogram
(
lbpimage
,
(
0
,
self
.
lbp
.
max_label
-
1
),
self
.
lbp
.
max_label
)
self
.
lbp
.
max_label
)
...
@@ -148,3 +159,35 @@ class LBPHistogram(Extractor):
...
@@ -148,3 +159,35 @@ class LBPHistogram(Extractor):
if
self
.
dtype
is
not
None
:
if
self
.
dtype
is
not
None
:
hist
=
hist
.
astype
(
self
.
dtype
)
hist
=
hist
.
astype
(
self
.
dtype
)
return
hist
return
hist
def
__call__
(
self
,
data
):
"""
Extracts spatially-enhanced LBP/MCT histograms from a gray-scale image.
Parameters
----------
data : numpy.ndarray
The preprocessed data to be transformed into one vector.
Returns
-------
1D :py:class:`numpy.ndarray`
The extracted feature vector, of the desired ``dtype`` (if
specified)
"""
# Make sure the data can be split into equal blocks:
row_max
=
int
(
data
.
shape
[
0
]
/
self
.
n_vert
)
*
self
.
n_vert
col_max
=
int
(
data
.
shape
[
1
]
/
self
.
n_hor
)
*
self
.
n_hor
data
=
data
[:
row_max
,
:
col_max
]
blocks
=
[
sub_block
for
block
in
np
.
hsplit
(
data
,
self
.
n_hor
)
for
sub_block
in
np
.
vsplit
(
block
,
self
.
n_vert
)]
hists
=
[
self
.
comp_block_histogram
(
block
)
for
block
in
blocks
]
hist
=
np
.
hstack
(
hists
)
hist
=
hist
/
len
(
blocks
)
# histogram normalization
return
hist
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment