Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
alibylite
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Swain Lab
aliby
alibylite
Commits
1ebd37bd
Commit
1ebd37bd
authored
2 years ago
by
Alán Muñoz
Browse files
Options
Downloads
Patches
Plain Diff
tweak(meta): Create ABC for ImageLocal
parent
d9d9c00e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/aliby/io/image.py
+33
-17
33 additions, 17 deletions
src/aliby/io/image.py
with
33 additions
and
17 deletions
src/aliby/io/image.py
+
33
−
17
View file @
1ebd37bd
...
...
@@ -47,9 +47,22 @@ def get_image_class(source: t.Union[str, int, t.Dict[str, str], PosixPath]):
return
instatiator
class
ImageLocal
:
class
BaseLocalImage
:
"""
Base class to set path and provide context management method.
"""
def
__init__
(
self
,
path
:
t
.
Union
[
str
,
PosixPath
]):
# If directory, assume contents are naturally sorted
self
.
path
=
Path
(
path
)
def
__enter__
(
self
):
return
self
class
ImageLocal
(
BaseLocalImage
):
def
__init__
(
self
,
path
:
str
,
dimorder
=
None
):
s
elf
.
path
=
path
s
uper
().
__init__
(
path
)
self
.
_id
=
str
(
path
)
meta
=
dict
()
...
...
@@ -154,16 +167,26 @@ class ImageLocal:
reshaped
,
range
(
len
(
reshaped
.
shape
)),
target_order
)
self
.
_formatted_img
=
da
.
rechunk
(
img
,
chunks
=
(
1
,
1
,
1
,
self
.
_meta
[
"
size_y
"
],
self
.
_meta
[
"
size_x
"
]),
)
return
self
.
format_data
(
img
)
def
format_data
(
self
,
img
):
self
.
_formatted_img
=
da
.
rechunk
(
img
,
chunks
=
(
1
,
1
,
1
,
*
[
self
.
_meta
[
f
"
size_
{
n
}
"
]
for
n
in
self
.
dimorder
[
-
2
:]],
),
)
return
self
.
_formatted_img
class
ImageDir
(
ImageLocal
):
"""
Image class for case where all images are split in one or multiple folders with time-points and channels as independent files.
Image class for the case in which all images are split in one or
multiple folders with time-points and channels as independent files.
It inherits from Imagelocal so we only override methods that are critical.
Assumptions:
...
...
@@ -174,9 +197,7 @@ class ImageDir(ImageLocal):
"""
def
__init__
(
self
,
path
:
t
.
Union
[
str
,
PosixPath
]):
# Assume they are naturally sorted
self
.
path
=
Path
(
path
)
super
().
__init__
(
path
)
self
.
image_id
=
str
(
self
.
path
.
stem
)
filenames
=
list
(
self
.
path
.
glob
(
"
*.tiff
"
))
...
...
@@ -220,13 +241,8 @@ class ImageDir(ImageLocal):
img
=
img
[...,
0
]
self
.
_meta
[
"
size_x
"
],
self
.
_meta
[
"
size_y
"
]
=
img
.
shape
[
-
2
:]
reshaped
=
da
.
reshape
(
img
,
(
*
self
.
_dim_shapes
,
*
img
.
shape
[
1
:]))
self
.
_formatted_img
=
da
.
rechunk
(
reshaped
,
chunks
=
(
1
,
1
,
1
,
self
.
_meta
[
"
size_y
"
],
self
.
_meta
[
"
size_x
"
]),
)
return
self
.
_formatted_img
img
=
da
.
reshape
(
img
,
(
*
self
.
_dim_shapes
,
*
img
.
shape
[
1
:]))
return
self
.
format_data
(
img
)
class
Image
(
BridgeOmero
):
...
...
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