Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.io.base
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.io.base
Commits
aa55f254
Commit
aa55f254
authored
2 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
Add bob_to_pillow and back conversion
parent
6601f669
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!39
Add bob_to_pillow and back conversion
Pipeline
#60635
passed
2 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/io/image.py
+41
-0
41 additions, 0 deletions
bob/io/image.py
conda/meta.yaml
+2
-0
2 additions, 0 deletions
conda/meta.yaml
with
43 additions
and
0 deletions
bob/io/image.py
+
41
−
0
View file @
aa55f254
import
numpy
as
np
from
PIL
import
Image
def
to_matplotlib
(
img
):
...
...
@@ -45,6 +46,46 @@ def to_bob(img):
return
np
.
moveaxis
(
img
,
-
1
,
-
3
)
def
bob_to_pillow
(
img
):
"""
Converts the floating or uint8 image to a Pillow Image.
Parameters
----------
img : numpy.ndarray
A gray-scale or RGB color image in Bob format (channels first)
Returns
-------
Image
An object of pillow.Image.
"""
# first convert to matplotlib format
img
=
to_matplotlib
(
img
)
# if img is floating point, convert to uint8
if
isinstance
(
img
,
np
.
floating
):
# we expect float images to be between 0 and 1
img
=
np
.
clip
(
img
,
0
,
1
)
*
255
img
=
img
.
astype
(
np
.
uint8
)
return
Image
.
fromarray
(
img
)
def
pillow_to_bob
(
img
):
"""
Converts an RGB or gray-scale pillow image to Bob format
Parameters
----------
img : Image
A Pillow Image
Returns
-------
numpy.ndarray
Image in Bob format
"""
return
to_bob
(
np
.
array
(
img
))
def
opencvbgr_to_bob
(
img
):
"""
Returns a view of the image from OpenCV BGR format to Bob RGB format.
This function works with images, batches of images, videos, and higher
...
...
This diff is collapsed.
Click to expand it.
conda/meta.yaml
+
2
−
0
View file @
aa55f254
...
...
@@ -24,11 +24,13 @@ requirements:
-
bob.extension
-
h5py {{ h5py }}
-
numpy {{ numpy }}
-
pillow {{ pillow }}
-
imageio {{ imageio }}
run
:
-
python
-
setuptools
-
{{
pin_compatible('numpy')
}}
-
{{
pin_compatible('pillow')
}}
-
{{
pin_compatible('imageio')
}}
-
{{
pin_compatible('h5py')
}}
...
...
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