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
589ba585
Commit
589ba585
authored
3 years ago
by
Tiago de Freitas Pereira
Browse files
Options
Downloads
Patches
Plain Diff
Implemented an extractor of patches
parent
0865f4a1
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!123
Drop bob.db.atnt and bob.ip.base
Pipeline
#60628
failed
3 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/pad/face/test/test_block.py
+22
-0
22 additions, 0 deletions
bob/pad/face/test/test_block.py
bob/pad/face/utils/load_utils.py
+47
-5
47 additions, 5 deletions
bob/pad/face/utils/load_utils.py
with
69 additions
and
5 deletions
bob/pad/face/test/test_block.py
0 → 100644
+
22
−
0
View file @
589ba585
import
numpy
A_org
=
numpy
.
array
(
range
(
1
,
17
),
"
float64
"
).
reshape
((
4
,
4
))
A_ans_0_3D
=
numpy
.
array
(
[[[
1
,
2
],
[
5
,
6
]],
[[
3
,
4
],
[
7
,
8
]],
[[
9
,
10
],
[
13
,
14
]],
[[
11
,
12
],
[
15
,
16
]]],
"
float64
"
,
)
A_ans_0_4D
=
numpy
.
array
(
[[[[
1
,
2
],
[
5
,
6
]],
[[
3
,
4
],
[
7
,
8
]]],
[[[
9
,
10
],
[
13
,
14
]],
[[
11
,
12
],
[
15
,
16
]]]],
"
float64
"
,
)
from
bob.pad.face.utils.load_utils
import
block
def
test_block
():
B
=
block
(
A_org
,
(
2
,
2
),
(
0
,
0
))
assert
(
B
==
A_ans_0_4D
).
all
()
B
=
block
(
A_org
,
(
2
,
2
),
(
0
,
0
),
flat
=
True
)
assert
(
B
==
A_ans_0_3D
).
all
()
This diff is collapsed.
Click to expand it.
bob/pad/face/utils/load_utils.py
+
47
−
5
View file @
589ba585
...
...
@@ -11,6 +11,46 @@ from imageio import get_reader
from
PIL
import
Image
def
block
(
X
,
block_size
,
block_overlap
,
flat
=
False
):
"""
Parameters
----------
X : numpy.ndarray
The image to be split into blocks.
block_size : tuple
The size of the block.
block_overlap : tuple
The overlap of the block.
Returns
-------
numpy.ndarray
The image split into blocks.
"""
assert
len
(
block_size
)
==
2
assert
len
(
block_overlap
)
==
2
size_ov_h
=
int
(
block_size
[
0
]
-
block_overlap
[
0
])
size_ov_w
=
int
(
block_size
[
1
]
-
block_overlap
[
1
])
n_blocks_h
=
int
((
X
.
shape
[
0
]
-
block_overlap
[
0
])
/
size_ov_h
)
n_blocks_w
=
int
((
X
.
shape
[
1
]
-
block_overlap
[
1
])
/
size_ov_w
)
blocks
=
numpy
.
zeros
(
shape
=
(
n_blocks_h
,
n_blocks_w
,
size_ov_h
,
size_ov_w
))
for
h
in
range
(
n_blocks_h
):
for
w
in
range
(
n_blocks_w
):
blocks
[
h
,
w
,
:,
:]
=
X
[
h
*
size_ov_h
:
h
*
size_ov_h
+
block_size
[
0
],
w
*
size_ov_w
:
w
*
size_ov_w
+
block_size
[
1
],
]
if
flat
:
return
blocks
.
reshape
(
n_blocks_h
*
n_blocks_w
,
blocks
.
shape
[
2
],
blocks
.
shape
[
3
])
return
blocks
def
scale
(
image
,
scaling_factor
):
"""
Scales and image using PIL
...
...
@@ -199,19 +239,21 @@ def blocks(data, block_size, block_overlap=(0, 0)):
ValueError
If data dimension is not between 2 and 4 (inclusive).
"""
data
=
numpy
.
asarray
(
data
)
# if a gray scale image:
if
data
.
ndim
==
2
:
output
=
block
(
data
,
block_size
,
block_overlap
,
flat
=
True
)
# if a color image:
elif
data
.
ndim
==
3
:
out_shape
=
list
(
data
.
shape
[
0
:
1
])
+
list
(
block_output_shape
(
data
[
0
],
block_size
,
block_overlap
,
flat
=
True
)
)
#
out_shape = list(data.shape[0:1]) + list(
#
block_output_shape(data[0], block_size, block_overlap, flat=True)
#
)
output
=
numpy
.
empty
(
out_shape
,
dtype
=
data
.
dtype
)
# output = numpy.empty(out_shape, dtype=data.dtype)
output
=
[]
for
i
,
img2d
in
enumerate
(
data
):
block
(
img2d
,
block_size
,
block_overlap
,
output
[
i
],
flat
=
True
)
output
.
append
(
block
(
img2d
,
block_size
,
block_overlap
,
flat
=
True
)
)
output
=
numpy
.
moveaxis
(
output
,
0
,
1
)
# if a color video:
elif
data
.
ndim
==
4
:
...
...
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