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
8f8c3264
Commit
8f8c3264
authored
Jan 24, 2024
by
Christian Kento Rasmussen
Browse files
Options
Downloads
Patches
Plain Diff
Began work on function to save .vol file
parent
13958fda
No related branches found
No related tags found
1 merge request
!45
Save files function
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
qim3d/io/load.py
+2
-0
2 additions, 0 deletions
qim3d/io/load.py
qim3d/io/save.py
+29
-0
29 additions, 0 deletions
qim3d/io/save.py
with
31 additions
and
0 deletions
qim3d/io/load.py
+
2
−
0
View file @
8f8c3264
...
@@ -378,6 +378,8 @@ class DataLoader:
...
@@ -378,6 +378,8 @@ class DataLoader:
match
dt
:
match
dt
:
case
'
float
'
:
case
'
float
'
:
dt
=
np
.
float32
dt
=
np
.
float32
case
'
float32
'
:
dt
=
np
.
float32
case
'
uint8
'
:
case
'
uint8
'
:
dt
=
np
.
uint8
dt
=
np
.
uint8
case
'
unsigned integer
'
:
case
'
unsigned integer
'
:
...
...
This diff is collapsed.
Click to expand it.
qim3d/io/save.py
+
29
−
0
View file @
8f8c3264
...
@@ -119,6 +119,29 @@ class DataSaver:
...
@@ -119,6 +119,29 @@ class DataSaver:
# Save image
# Save image
nib
.
save
(
img
,
path
)
nib
.
save
(
img
,
path
)
def
save_vol
(
self
,
path
,
data
):
"""
Save data to a VOL file to the given path.
Args:
path (str): The path to save file to
data (numpy.ndarray): The data to be saved
"""
# Create custom .vgi metadata file
metadata
=
""
metadata
+=
"
{volume1}
\n
"
metadata
+=
"
[file1]
"
metadata
+=
"
Size = 1000 1000 766
"
metadata
+=
"
datatype = float
\n
"
metadata
+=
"
Name = WFW_200kV_6W_1mmSn_6micro_1s.vol
"
# Save metadata
with
open
(
path
[:
-
3
]
+
"
.vgi
"
,
"
w
"
)
as
f
:
f
.
write
(
metadata
)
# Save data using numpy in binary format
np
.
save
(
path
[:
-
3
]
+
"
.vol
"
,
data
)
def
save
(
self
,
path
,
data
):
def
save
(
self
,
path
,
data
):
"""
Save data to the given path.
"""
Save data to the given path.
...
@@ -185,6 +208,12 @@ class DataSaver:
...
@@ -185,6 +208,12 @@ class DataSaver:
return
self
.
save_tiff
(
path
,
data
)
return
self
.
save_tiff
(
path
,
data
)
elif
path
.
endswith
((
"
.nii
"
,
"
nii.gz
"
)):
elif
path
.
endswith
((
"
.nii
"
,
"
nii.gz
"
)):
return
self
.
save_nifti
(
path
,
data
)
return
self
.
save_nifti
(
path
,
data
)
elif
path
.
endswith
((
"
TXRM
"
,
"
XRM
"
,
"
TXM
"
)):
raise
NotImplementedError
(
"
Saving TXRM files is not yet supported
"
)
elif
path
.
endswith
((
"
h5
"
)):
raise
NotImplementedError
(
"
Saving HDF5 files is not yet supported
"
)
elif
path
.
endswith
((
"
.vol
"
,
"
.vgi
"
)):
raise
NotImplementedError
(
"
Saving VOL files is not yet supported
"
)
else
:
else
:
raise
ValueError
(
"
Unsupported file format
"
)
raise
ValueError
(
"
Unsupported file format
"
)
# If there is no file extension in the path
# If there is no file extension in the path
...
...
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