Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
qim3d
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QIM
Tools
qim3d
Commits
5828cda7
Commit
5828cda7
authored
1 year ago
by
Christian Kento Rasmussen
Browse files
Options
Downloads
Patches
Plain Diff
finalized convert function for zarr to tiff
parent
ebc8ab67
No related branches found
No related tags found
4 merge requests
!102
Conv zarr tiff folders
,
!100
Conv zarr nifti
,
!99
Zarr cli
,
!96
Zarr loading and converting
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
qim3d/io/__init__.py
+1
-0
1 addition, 0 deletions
qim3d/io/__init__.py
qim3d/io/convert.py
+5
-21
5 additions, 21 deletions
qim3d/io/convert.py
with
6 additions
and
21 deletions
qim3d/io/__init__.py
+
1
−
0
View file @
5828cda7
...
@@ -2,4 +2,5 @@ from .loading import DataLoader, load, ImgExamples
...
@@ -2,4 +2,5 @@ from .loading import DataLoader, load, ImgExamples
from
.downloader
import
Downloader
from
.downloader
import
Downloader
from
.saving
import
DataSaver
,
save
from
.saving
import
DataSaver
,
save
from
.sync
import
Sync
from
.sync
import
Sync
from
.convert
import
convert
from
.
import
logger
from
.
import
logger
\ No newline at end of file
This diff is collapsed.
Click to expand it.
qim3d/io/convert.py
+
5
−
21
View file @
5828cda7
...
@@ -23,13 +23,14 @@ class Convert:
...
@@ -23,13 +23,14 @@ class Convert:
def
convert
(
self
,
input_path
,
output_path
):
def
convert
(
self
,
input_path
,
output_path
):
# Stringify path in case it is not already a string
# Stringify path in case it is not already a string
input_path
=
stringify_path
(
input_path
)
input_path
=
stringify_path
(
input_path
)
output_path
=
stringify_path
(
output_path
)
if
os
.
path
.
isfile
(
input_path
)
and
os
.
path
.
isfile
(
output_path
):
if
os
.
path
.
isfile
(
input_path
):
match
input_path
,
output_path
:
input_ext
=
os
.
path
.
splitext
(
input_path
)[
1
]
output_ext
=
os
.
path
.
splitext
(
output_path
)[
1
]
match
input_ext
,
output_ext
:
case
(
"
.tif
"
,
"
.zarr
"
):
case
(
"
.tif
"
,
"
.zarr
"
):
return
self
.
convert_tif_to_zarr
(
input_path
,
output_path
)
return
self
.
convert_tif_to_zarr
(
input_path
,
output_path
)
case
(
"
.npy
"
,
"
.zarr
"
):
return
self
.
convert_npy_to_zarr
(
input_path
,
output_path
,
shape
=
(
64
,
64
,
64
))
case
(
"
.zarr
"
,
"
.tif
"
):
case
(
"
.zarr
"
,
"
.tif
"
):
return
self
.
convert_zarr_to_tif
(
input_path
,
output_path
)
return
self
.
convert_zarr_to_tif
(
input_path
,
output_path
)
case
_
:
case
_
:
...
@@ -75,23 +76,6 @@ class Convert:
...
@@ -75,23 +76,6 @@ class Convert:
return
z
return
z
def
convert_npy_to_zarr
(
self
,
npy_path
,
zarr_path
,
shape
,
dtype
=
np
.
float32
,
chunks
=
(
64
,
64
,
64
)):
"""
Convert a numpy file to a zarr file
Args:
npy_path (str): path to the numpy file
zarr_path (str): path to the zarr file
chunks (tuple, optional): chunk size for the zarr file. Defaults to (64, 64, 64).
Returns:
zarr.core.Array: zarr array containing the data from the numpy file
"""
vol
=
np
.
memmap
(
npy_path
,
dtype
=
dtype
,
mode
=
'
r
'
,
shape
=
shape
)
z
=
zarr
.
open
(
zarr_path
,
mode
=
'
w
'
,
shape
=
vol
.
shape
,
chunks
=
chunks
,
dtype
=
vol
.
dtype
)
z
[:]
=
vol
[:]
return
z
def
convert_zarr_to_tif
(
self
,
zarr_path
,
tif_path
):
def
convert_zarr_to_tif
(
self
,
zarr_path
,
tif_path
):
"""
Convert a zarr file to a tiff file
"""
Convert a zarr file to a tiff file
...
...
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