Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PyNutil
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Harry Carey
PyNutil
Commits
fefce4cb
Commit
fefce4cb
authored
1 year ago
by
Harry Carey
Browse files
Options
Downloads
Patches
Plain Diff
added the ability to read dzip files
parent
3e311103
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
PyNutil/coordinate_extraction.py
+6
-1
6 additions, 1 deletion
PyNutil/coordinate_extraction.py
PyNutil/main.py
+1
-0
1 addition, 0 deletions
PyNutil/main.py
PyNutil/reconstruct_dzi.py
+51
-0
51 additions, 0 deletions
PyNutil/reconstruct_dzi.py
with
58 additions
and
1 deletion
PyNutil/coordinate_extraction.py
+
6
−
1
View file @
fefce4cb
...
@@ -10,6 +10,8 @@ import cv2
...
@@ -10,6 +10,8 @@ import cv2
from
skimage
import
measure
from
skimage
import
measure
import
threading
import
threading
import
re
import
re
from
.reconstruct_dzi
import
reconstruct_dzi
def
number_sections
(
filenames
,
legacy
=
False
):
def
number_sections
(
filenames
,
legacy
=
False
):
"""
"""
...
@@ -208,7 +210,10 @@ def segmentation_to_atlas_space(
...
@@ -208,7 +210,10 @@ def segmentation_to_atlas_space(
):
):
"""
Combines many functions to convert a segmentation to atlas space. It takes care
"""
Combines many functions to convert a segmentation to atlas space. It takes care
of deformations.
"""
of deformations.
"""
segmentation
=
cv2
.
imread
(
segmentation_path
)
if
segmentation_path
.
endswith
(
"
.dzip
"
):
segmentation
=
reconstruct_dzi
(
segmentation_path
)
else
:
segmentation
=
cv2
.
imread
(
segmentation_path
)
if
pixel_id
==
"
auto
"
:
if
pixel_id
==
"
auto
"
:
# Remove the background from the segmentation
# Remove the background from the segmentation
segmentation_no_background
=
segmentation
[
~
np
.
all
(
segmentation
==
255
,
axis
=
2
)]
segmentation_no_background
=
segmentation
[
~
np
.
all
(
segmentation
==
255
,
axis
=
2
)]
...
...
This diff is collapsed.
Click to expand it.
PyNutil/main.py
+
1
−
0
View file @
fefce4cb
...
@@ -8,6 +8,7 @@ from datetime import datetime
...
@@ -8,6 +8,7 @@ from datetime import datetime
import
os
import
os
class
PyNutil
:
class
PyNutil
:
"""
A utility class for working with brain atlases and segmentation data.
"""
A utility class for working with brain atlases and segmentation data.
...
...
This diff is collapsed.
Click to expand it.
PyNutil/reconstruct_dzi.py
0 → 100644
+
51
−
0
View file @
fefce4cb
import
cv2
import
numpy
as
np
import
os
import
zipfile
import
xmltodict
def
reconstruct_dzi
(
zip_file_path
):
"""
Reconstructs a Deep Zoom Image (DZI) from a zip file containing the tiles.
:param zip_file_path: Path to the zip file containing the tiles.
:return: The reconstructed DZI.
"""
with
zipfile
.
ZipFile
(
zip_file_path
,
"
r
"
)
as
zip_file
:
# Get the highest level of the pyramid
highest_level
=
str
(
np
.
max
(
[
int
(
os
.
path
.
split
(
os
.
path
.
split
(
i
)[
0
])[
1
])
for
i
in
zip_file
.
namelist
()
if
i
.
endswith
(
"
.png
"
)
]
)
)
# Get the filenames of the highest level tiles
highest_level_files
=
[
i
for
i
in
zip_file
.
namelist
()
if
i
.
endswith
(
"
.png
"
)
and
i
.
split
(
"
/
"
)[
-
2
]
==
highest_level
]
# Read the DZI file
dzi_file
=
zip_file
.
open
([
i
for
i
in
zip_file
.
namelist
()
if
i
.
endswith
(
"
.dzi
"
)][
0
])
xml
=
dzi_file
.
read
()
json_data
=
xmltodict
.
parse
(
xml
)
tileSize
=
json_data
[
"
Image
"
][
"
@TileSize
"
]
width
,
height
=
int
(
json_data
[
"
Image
"
][
"
Size
"
][
"
@Width
"
]),
int
(
json_data
[
"
Image
"
][
"
Size
"
][
"
@Height
"
])
# Create an empty image
image
=
np
.
zeros
((
height
,
width
,
3
),
dtype
=
np
.
uint8
)
# Fill in the image with the highest level tiles
for
file
in
highest_level_files
:
with
zip_file
.
open
(
file
)
as
f
:
contents
=
f
.
read
()
# Decode the binary PNG data
image_
=
cv2
.
imdecode
(
np
.
frombuffer
(
contents
,
np
.
uint8
),
cv2
.
IMREAD_COLOR
)
x
,
y
=
map
(
int
,
os
.
path
.
splitext
(
os
.
path
.
split
(
file
)[
1
])[
0
].
split
(
"
_
"
))
x
,
y
=
x
*
int
(
tileSize
),
y
*
int
(
tileSize
)
image
[
y
:
y
+
image_
.
shape
[
0
],
x
:
x
+
image_
.
shape
[
1
],
:]
=
image_
# Save the image
return
image
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
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