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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QIM
Tools
qim3d
Commits
78d314bb
Commit
78d314bb
authored
11 months ago
by
Christian Kento Rasmussen
Browse files
Options
Downloads
Patches
Plain Diff
Began work on convert tool
parent
3ada6701
No related branches found
Branches containing commit
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
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
qim3d/io/convert.py
+51
-0
51 additions, 0 deletions
qim3d/io/convert.py
with
51 additions
and
0 deletions
qim3d/io/convert.py
0 → 100644
+
51
−
0
View file @
78d314bb
import
numpy
as
np
import
tifffile
as
tiff
import
zarr
def
convert_tif_to_zarr
(
tif_path
,
zarr_path
,
chunks
=
(
64
,
64
,
64
)):
"""
Convert a tiff file to a zarr file
Args:
tif_path (str): path to the tiff 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 tiff file
"""
vol
=
tiff
.
memmap
(
tif_path
)
z
=
zarr
.
open
(
zarr_path
,
mode
=
'
w
'
,
shape
=
vol
.
shape
,
chunks
=
chunks
,
dtype
=
vol
.
dtype
)
z
[:]
=
vol
[:]
return
z
def
convert_npy_to_zarr
(
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
(
zarr_path
,
tif_path
):
"""
Convert a zarr file to a tiff file
Args:
zarr_path (str): path to the zarr file
tif_path (str): path to the tiff file
returns:
None
"""
z
=
zarr
.
open
(
zarr_path
)
tiff
.
imwrite
(
tif_path
,
z
)
\ No newline at end of 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