Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Y
YeaZ-GUI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container 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
chadhat
YeaZ-GUI
Commits
7f1bf934
Commit
7f1bf934
authored
4 years ago
by
mattminder
Browse files
Options
Downloads
Patches
Plain Diff
image loader
parent
7d3d3464
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
disk/image_loader.py
+60
-0
60 additions, 0 deletions
disk/image_loader.py
with
60 additions
and
0 deletions
disk/image_loader.py
0 → 100644
+
60
−
0
View file @
7f1bf934
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri May 15 17:05:00 2020
@mattminder
"""
import
os
import
re
from
skimage
import
io
import
numpy
as
np
def
load_image
(
path
,
ix
=
None
):
"""
Loads Image at specified path. Path can be to single image as supported
by skimage.io, or to folder containing images supported by skimage.io.
Ix specifies which image should be loaded, if None it loads all images.
"""
_
,
ext
=
os
.
path
.
splitext
(
path
)
# Folder
if
ext
==
''
:
filelist
=
sorted
(
os
.
listdir
(
path
))
filelist
=
[
f
for
f
in
filelist
if
re
.
search
(
r
"
.png|.tif|.jpg|.bmp|.jpeg|.pbm|.pgm|.ppm|.pxm|.pnm|.jp2
"
,
f
)]
filelist
=
[
os
.
path
.
join
(
path
,
f
)
for
f
in
filelist
]
if
len
(
filelist
)
==
0
:
raise
ValueError
(
'
Folder does not contain images
'
)
if
ix
is
None
:
ims
=
[
io
.
imread
(
f
)
for
f
in
filelist
]
ims
=
np
.
array
(
ims
)
return
ims
else
:
im
=
io
.
imread
(
filelist
[
ix
])
return
im
# File
else
:
try
:
im
=
io
.
imread
(
path
)
except
ValueError
:
raise
ValueError
(
'
Not an image file
'
)
# Single image
if
im
.
ndim
==
2
:
if
ix
is
not
None
:
return
im
else
:
return
im
[
None
,:,:]
# Multistack image
if
im
.
ndim
==
3
:
if
ix
is
None
:
return
im
else
:
return
im
[
ix
,:,:]
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