Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.io.image
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
Model registry
Operate
Environments
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.io.image
Commits
f58f05b2
There was a problem fetching the pipeline summary.
Commit
f58f05b2
authored
7 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
Add a utility function to convert images from matplotlib format to bob format
parent
df829367
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!32
Add a utility function to convert images from matplotlib format to bob format
Pipeline
#
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
bob/io/image/__init__.py
+1
-1
1 addition, 1 deletion
bob/io/image/__init__.py
bob/io/image/utils.py
+50
-19
50 additions, 19 deletions
bob/io/image/utils.py
doc/guide.rst
+3
-0
3 additions, 0 deletions
doc/guide.rst
requirements.txt
+1
-0
1 addition, 0 deletions
requirements.txt
with
55 additions
and
20 deletions
bob/io/image/__init__.py
+
1
−
1
View file @
f58f05b2
...
...
@@ -10,7 +10,7 @@ from . import version
from
.version
import
module
as
__version__
from
._library
import
*
from
.utils
import
imshow
,
to_matplotlib
from
.utils
import
*
import
os
...
...
This diff is collapsed.
Click to expand it.
bob/io/image/utils.py
+
50
−
19
View file @
f58f05b2
#!/usr/bin/env python
import
numpy
as
np
import
matplotlib.pyplot
as
plt
def
to_matplotlib
(
img
):
'''
Returns a view of the image compatible with matplotlib.
Parameters:
img (numpy.ndarray): A 2 or 3 dimensional array containing an image in
bob style: For a 2D array (grayscale image) should be ``(y, x)``;
For a 3D array (color image) should be ``(n, y, x)``.
Parameters
----------
img : numpy.ndarray
A 2 or 3 dimensional array containing an image in bob style: For a 2D
array (grayscale image) should be ``(y, x)``; For a 3D array (color
image) should be ``(n, y, x)``.
Returns:
numpy.ndarray: A view of the ``img`` compatible with
:py:func:`matplotlib.pyplot.imshow`.
Returns
-------
numpy.ndarray
A view of the ``img`` compatible with
:py:func:`matplotlib.pyplot.imshow`.
'''
import
numpy
as
np
if
img
.
ndim
==
3
:
img
=
np
.
moveaxis
(
img
,
0
,
-
1
)
return
img
def
to_bob
(
img
):
'''
Returns a view of the image compatible with Bob.
Parameters
----------
img : numpy.ndarray
A 2 or 3 dimensional array containing an image in matplotlib style: For
a 2D array (grayscale image) should be ``(y, x)``; For a 3D array
(color image) should be ``(y, x, n)``.
Returns
-------
numpy.ndarray
A view of the ``img`` compatible with Bob ``(n, y, x)`` for 3D images.
'''
if
img
.
ndim
==
3
:
img
=
np
.
moveaxis
(
img
,
-
1
,
0
)
return
img
def
imshow
(
img
,
cmap
=
None
,
**
kwargs
):
'''
Plots the images that are returned by :py:func:`bob.io.base.load`
Parameters:
img (numpy.ndarray): A 2 or 3 dimensional array containing an image in
bob style: For a 2D array (grayscale image) should be ``(y, x)``;
For a 3D array (color image) should be ``(n, y, x)``.
cmap (matplotlib.colors.Colormap): Colormap, optional, default: ``None``.
If ``cmap`` is ``None`` and ``img.ndim`` is 2, defaults to
'
gray
'
.
``cmap`` is ignored when ``img`` has RGB(A) information.
kwargs: These are passed directly to :py:func:`matplotlib.pyplot.imshow`
Parameters
----------
img : numpy.ndarray
A 2 or 3 dimensional array containing an image in
bob style: For a 2D array (grayscale image) should be ``(y, x)``;
A 3D array (color image) should be in the ``(n, y, x)`` format.
cmap : matplotlib.colors.Colormap
Colormap, optional, default: ``None``.
If ``cmap`` is ``None`` and ``img.ndim`` is 2, defaults to
'
gray
'
.
``cmap`` is ignored when ``img`` has RGB(A) information.
**kwargs
These are passed directly to :py:func:`matplotlib.pyplot.imshow`
Returns
-------
object
Returns whatever ``plt.imshow`` returns.
'''
import
matplotlib.pyplot
as
plt
if
cmap
is
None
and
img
.
ndim
==
2
:
cmap
=
'
gray
'
...
...
This diff is collapsed.
Click to expand it.
doc/guide.rst
+
3
−
0
View file @
f58f05b2
...
...
@@ -82,6 +82,9 @@ Or you can just get a view (not copy) of your image that is
>>> assert img_view_for_matplotlib.shape[-1] == 3
>>> assert img_view_for_matplotlib.base is img
You can also get the original image back using :py:func:`bob.io.image.to_bob`.
.. testcleanup:: *
import shutil
...
...
This diff is collapsed.
Click to expand it.
requirements.txt
+
1
−
0
View file @
f58f05b2
setuptools
numpy
bob.extension
bob.blitz
bob.core
...
...
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