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
07264a86
Commit
07264a86
authored
1 year ago
by
Harry Carey
Browse files
Options
Downloads
Patches
Plain Diff
added emoji
parent
1e51888c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
PyNutil/coordinate_extraction.py
+17
-10
17 additions, 10 deletions
PyNutil/coordinate_extraction.py
PyNutil/main.py
+4
-4
4 additions, 4 deletions
PyNutil/main.py
with
21 additions
and
14 deletions
PyNutil/coordinate_extraction.py
+
17
−
10
View file @
07264a86
...
...
@@ -17,8 +17,8 @@ def getCentroidsAndArea(Segmentation, pixelCutOff=0):
"""
this function returns the center coordinate of each object in the segmentation.
You can set a pixelCutOff to remove objects that are smaller than that number of pixels
"""
SegmentationBinary
=
~
np
.
all
(
Segmentation
==
255
,
axis
=
2
)
labels
=
measure
.
label
(
Segmentation
Binary
)
#
SegmentationBinary = ~np.all(Segmentation == 255, axis=2)
labels
=
measure
.
label
(
Segmentation
)
# this finds all the objects in the image
labelsInfo
=
measure
.
regionprops
(
labels
)
# remove objects that are less than pixelCutOff
...
...
@@ -144,11 +144,6 @@ def SegmentationToAtlasSpace(
"""
combines many functions to convert a segmentation to atlas space. It takes care
of deformations
"""
Segmentation
=
cv2
.
imread
(
SegmentationPath
)
if
method
in
[
"
per_object
"
,
"
all
"
]:
# this function returns the centroids, area and coordinates of all the objects in the segmentation
# right now we only use centroids
centroids
,
area
,
coords
=
getCentroidsAndArea
(
Segmentation
,
pixelCutOff
=
0
)
print
(
"
number of objects:
"
,
len
(
centroids
))
if
pixelID
==
"
auto
"
:
# remove the background from the segmentation
SegmentationNoBackGround
=
Segmentation
[
~
np
.
all
(
Segmentation
==
255
,
axis
=
2
)]
...
...
@@ -157,7 +152,7 @@ def SegmentationToAtlasSpace(
)
# remove background
# currently only works for a single label
pixelID
=
pixelID
[
0
]
ID_pixels
=
findMatchingPixels
(
Segmentation
,
pixelID
)
# transform pixels to registration space (the registered image and segmentation have different dimensions)
SegHeight
=
Segmentation
.
shape
[
0
]
SegWidth
=
Segmentation
.
shape
[
1
]
...
...
@@ -166,8 +161,20 @@ def SegmentationToAtlasSpace(
# this calculates reg/seg
Yscale
,
Xscale
=
transformToRegistration
(
SegHeight
,
SegWidth
,
RegHeight
,
RegWidth
)
# scale the seg coordinates to reg/seg
scaledY
,
scaledX
=
scalePositions
(
ID_pixels
[
0
],
ID_pixels
[
1
],
Yscale
,
Xscale
)
if
method
in
[
"
per_object
"
,
"
all
"
]:
# this function returns the centroids, area and coordinates of all the objects in the segmentation
# right now we only use centroids
binary_seg
=
Segmentation
==
pixelID
binary_seg
=
np
.
all
(
binary_seg
,
axis
=
2
)
centroids
,
area
,
coords
=
getCentroidsAndArea
(
binary_seg
,
pixelCutOff
=
0
)
print
(
"
number of objects:
"
,
len
(
centroids
))
# print(centroids)
if
method
in
[
"
per_pixel
"
,
"
all
"
]:
ID_pixels
=
findMatchingPixels
(
Segmentation
,
pixelID
)
# scale the seg coordinates to reg/seg
scaledY
,
scaledX
=
scalePositions
(
ID_pixels
[
0
],
ID_pixels
[
1
],
Yscale
,
Xscale
)
if
nonLinear
:
if
"
markers
"
in
slice
:
# this creates a triangulation using the reg width
...
...
This diff is collapsed.
Click to expand it.
PyNutil/main.py
+
4
−
4
View file @
07264a86
...
...
@@ -53,11 +53,11 @@ class PyNutil:
startTime
=
datetime
.
now
()
self
.
atlas_volume
=
readAtlasVolume
(
atlas_root_path
+
current_atlas_path
)
time_taken
=
datetime
.
now
()
-
startTime
print
(
f
"
atlas volume loaded in:
{
time_taken
}
"
)
print
(
f
"
atlas volume loaded in:
{
time_taken
}
✅
"
)
atlas_label_path
=
self
.
config
[
"
annotation_volumes
"
][
self
.
atlas
][
"
labels
"
]
print
(
"
loading atlas labels
"
)
self
.
atlas_labels
=
pd
.
read_csv
(
atlas_root_path
+
atlas_label_path
)
print
(
"
atlas labels loaded
"
)
print
(
"
atlas labels loaded
✅
"
)
def
get_coordinates
(
self
,
nonLinear
=
True
,
method
=
"
all
"
):
if
not
hasattr
(
self
,
"
atlas_volume
"
):
...
...
@@ -90,7 +90,7 @@ class PyNutil:
self
.
label_df
=
PixelCountPerRegion
(
labeled_points
,
self
.
atlas_labels
)
self
.
labeled_points
=
labeled_points
print
(
"
quantification complete
"
)
print
(
"
quantification complete
✅
"
)
def
save_analysis
(
self
,
output_folder
):
if
not
hasattr
(
self
,
"
pixel_points
"
):
...
...
@@ -113,4 +113,4 @@ class PyNutil:
output_folder
+
"
/pixels_meshview.json
"
,
self
.
atlas_labels
,
)
print
(
"
analysis saved
"
)
print
(
"
analysis saved
✅
"
)
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