Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
3
3DIM-reconstruction
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
3DIM-reconstruction
Commits
6f286e34
Commit
6f286e34
authored
4 months ago
by
David Johansen
Browse files
Options
Downloads
Patches
Plain Diff
save work for projection chunking
parent
7ba0780b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ct_chunking.py
+92
-0
92 additions, 0 deletions
ct_chunking.py
with
92 additions
and
0 deletions
ct_chunking.py
0 → 100644
+
92
−
0
View file @
6f286e34
import
zarr
import
numpy
as
np
from
cil.io
import
ZEISSDataReader
,
NikonDataReader
from
cil.framework
import
AcquisitionData
from
cil.processors
import
TransmissionAbsorptionConverter
from
cil.recon
import
FDK
def
create_reader
(
file_name
,
roi
=
None
):
if
file_name
.
endswith
(
'
txrm
'
):
DataReader
=
ZEISSDataReader
elif
file_name
.
endswith
(
'
xtekct
'
):
DataReader
=
NikonDataReader
else
:
raise
ValueError
(
"
Unrecognizable CT metadata file. File extension should either be
'
.txrm
'
or
'
.xtekct
'"
)
if
roi
is
None
:
return
DataReader
(
file_name
=
file_name
)
else
:
return
DataReader
(
file_name
=
file_name
,
roi
=
roi
)
def
write_projection_chunks
(
config_path
,
zarr_path
,
chunk_size
,
proj_shape
):
"""
# (ignore for now, meant for custom reader) input_path: Directory containing .tiff projection data.
out_path: Directory to write zarr file.
"""
nchunks
=
(
proj_shape
[
0
]
-
1
)
//
chunk_size
+
1
compressors
=
zarr
.
codecs
.
Blosc
(
cname
=
'
lz4
'
)
zarr_array
=
zarr
.
open
(
store
=
zarr_path
,
mode
=
'
w
'
,
dtype
=
np
.
uint16
,
chunks
=
(
chunk_size
,
*
proj_shape
[
1
:]),
compressors
=
compressors
)
for
i
in
range
(
nchunks
):
start
=
i
*
chunk_size
end
=
min
((
i
+
1
)
*
chunk_size
,
proj_shape
[
0
])
reader
=
create_reader
(
config_path
,
roi
=
{
'
angle
'
:
(
start
,
end
,
1
)})
chunk
=
reader
.
read
()
expected_shape
=
(
end
-
start
,
*
proj_shape
[
1
:])
if
chunk
.
shape
!=
expected_shape
:
raise
ValueError
(
f
'
Chunk shape mismatch: expected
{
expected_shape
}
, got
{
chunk
.
shape
}
'
)
zarr_array
[
start
:
end
,:,:]
=
chunk
def
read_projection_chunk
(
zarr_path
,
chunk_size
,
chunk_index
):
zarr_array
=
zarr
.
open_array
(
store
=
zarr_path
,
mode
=
'
r
'
)
proj_shape
=
zarr_array
.
shape
start
=
chunk_index
*
chunk_size
end
=
min
((
chunk_index
+
1
)
*
chunk_size
,
proj_shape
[
0
])
chunk
=
zarr_array
[
start
:
end
,:,:]
return
chunk
def
recon_projection_chunk
(
ag
,
ig
,
zarr_path
,
chunk_size
,
chunk_index
):
"""
ag: AcquisitionGeometry with chunked projection.
ig: ImageGeometry for the reconstruction volume.
"""
start
=
chunk_index
*
chunk_size
end
=
min
((
chunk_index
+
1
)
*
chunk_size
,
ag
.
shape
[
0
])
ag_chunk
=
ag
.
copy
().
set_angles
(
ag
.
angles
[
start
:
end
])
chunk
=
read_projection_chunk
(
zarr_path
,
chunk_size
,
chunk_index
)
chunk
=
chunk
.
astype
(
np
.
float32
)
data_chunk
=
AcquisitionData
(
array
=
chunk
,
deep_copy
=
False
,
geometry
=
ag_chunk
)
data_chunk
=
TransmissionAbsorptionConverter
()(
data_chunk
)
data_chunk
.
reorder
(
order
=
'
tigre
'
)
recon_chunk
=
FDK
(
data_chunk
,
image_geometry
=
ig
).
run
(
verbose
=
1
)
return
recon_chunk
def
chunk_volumes
():
pass
def
main
():
path
=
'
/dtu/3d-imaging-center/projects/2024_QIM_platform/analysis/data/valnut/valnut_2014-03-21_643_28/tomo-A/valnut_tomo-A.txrm
'
chunk_size
=
600
zarr_path
=
'
ct_chunk.zarr
'
ag
=
create_reader
(
path
).
get_geometry
()
ig
=
ag
.
get_ImageGeometry
()
proj_shape
=
ag
.
shape
# get number of projections. then use CIL reader to read in subset of tiff files for each chunk and have a function to write to disk.
# potentially replace this with a custom reader
write_projection_chunks
(
config_path
=
path
,
zarr_path
=
zarr_path
,
chunk_size
=
chunk_size
,
proj_shape
=
proj_shape
)
nchunks
=
(
proj_shape
[
0
]
-
1
)
//
chunk_size
+
1
recon_accumulated
=
np
.
zeros
(
ig
.
shape
,
dtype
=
np
.
float32
)
for
chunk_index
in
range
(
nchunks
):
recon_accumulated
+=
recon_projection_chunk
(
ag
,
ig
,
zarr_path
,
chunk_size
=
chunk_size
,
chunk_index
=
chunk_index
)
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