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
330f4837
Commit
330f4837
authored
7 months ago
by
s233039
Committed by
fima
7 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Automatic objects colormap
parent
73ea1c27
No related branches found
No related tags found
1 merge request
!130
Automatic objects colormap
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
qim3d/processing/operations.py
+3
-0
3 additions, 0 deletions
qim3d/processing/operations.py
qim3d/viz/colormaps.py
+8
-2
8 additions, 2 deletions
qim3d/viz/colormaps.py
qim3d/viz/explore.py
+27
-8
27 additions, 8 deletions
qim3d/viz/explore.py
with
38 additions
and
10 deletions
qim3d/processing/operations.py
+
3
−
0
View file @
330f4837
...
...
@@ -91,6 +91,9 @@ def watershed(bin_vol: np.ndarray, min_distance: int = 5) -> tuple[np.ndarray, i
import
skimage
import
scipy
if
len
(
np
.
unique
(
bin_vol
))
>
2
:
raise
ValueError
(
"
bin_vol has to be binary volume - it must contain max 2 unique values.
"
)
# Compute distance transform of binary volume
distance
=
scipy
.
ndimage
.
distance_transform_edt
(
bin_vol
)
...
...
This diff is collapsed.
Click to expand it.
qim3d/viz/colormaps.py
+
8
−
2
View file @
330f4837
...
...
@@ -86,11 +86,17 @@ def objects(
```

Tip:
It can be easily used when calling visualization functions as
```python
qim3d.viz.slices(segmented_volume, cmap =
'
objects
'
)
```
which automatically detects number of unique classes
and creates the colormap object with defualt arguments.
Tip:
The `min_dist` parameter can be used to control the distance between neighboring colors.

"""
from
skimage
import
color
...
...
This diff is collapsed.
Click to expand it.
qim3d/viz/explore.py
+
27
−
8
View file @
330f4837
...
...
@@ -19,7 +19,6 @@ import seaborn as sns
import
qim3d
def
slices
(
vol
:
np
.
ndarray
,
axis
:
int
=
0
,
...
...
@@ -33,7 +32,7 @@ def slices(
img_width
:
int
=
2
,
show
:
bool
=
False
,
show_position
:
bool
=
True
,
interpolation
:
Optional
[
str
]
=
"
n
one
"
,
interpolation
:
Optional
[
str
]
=
N
one
,
img_size
=
None
,
cbar
:
bool
=
False
,
cbar_style
:
str
=
"
small
"
,
...
...
@@ -85,6 +84,11 @@ def slices(
img_height
=
img_size
img_width
=
img_size
# If we pass python None to the imshow function, it will set to
# default value 'antialiased'
if
interpolation
is
None
:
interpolation
=
'
none
'
# Numpy array or Torch tensor input
if
not
isinstance
(
vol
,
(
np
.
ndarray
,
da
.
core
.
Array
)):
raise
ValueError
(
"
Data type not supported
"
)
...
...
@@ -107,6 +111,19 @@ def slices(
f
"
Invalid value for
'
axis
'
. It should be an integer between 0 and
{
vol
.
ndim
-
1
}
.
"
)
if
type
(
cmap
)
==
matplotlib
.
colors
.
LinearSegmentedColormap
or
cmap
==
'
objects
'
:
num_labels
=
len
(
np
.
unique
(
vol
))
if
cmap
==
'
objects
'
:
cmap
=
qim3d
.
viz
.
colormaps
.
objects
(
num_labels
)
# If vmin and vmax are not set like this, then in case the
# number of objects changes on new slice, objects might change
# colors. So when using a slider, the same object suddently
# changes color (flickers), which is confusing and annoying.
vmin
=
0
vmax
=
num_labels
# Get total number of slices in the specified dimension
n_total
=
vol
.
shape
[
axis
]
...
...
@@ -152,9 +169,10 @@ def slices(
vol
=
vol
.
compute
()
if
cbar
:
# In this case, we want the vrange to be constant across the slices, which makes them all comparable to a single cbar.
new_vmin
=
vmin
if
vmin
else
np
.
min
(
vol
)
new_vmax
=
vmax
if
vmax
else
np
.
max
(
vol
)
# In this case, we want the vrange to be constant across the
# slices, which makes them all comparable to a single cbar.
new_vmin
=
vmin
if
vmin
is
not
None
else
np
.
min
(
vol
)
new_vmax
=
vmax
if
vmax
is
not
None
else
np
.
max
(
vol
)
# Run through each ax of the grid
for
i
,
ax_row
in
enumerate
(
axs
):
...
...
@@ -164,8 +182,9 @@ def slices(
slice_img
=
vol
.
take
(
slice_idxs
[
slice_idx
],
axis
=
axis
)
if
not
cbar
:
# If vmin is higher than the highest value in the image ValueError is raised
# We don't want to override the values because next slices might be okay
# If vmin is higher than the highest value in the
# image ValueError is raised. We don't want to
# override the values because next slices might be okay
new_vmin
=
(
None
if
(
isinstance
(
vmin
,
(
float
,
int
))
and
vmin
>
np
.
max
(
slice_img
))
...
...
@@ -277,7 +296,7 @@ def slicer(
img_height
:
int
=
3
,
img_width
:
int
=
3
,
show_position
:
bool
=
False
,
interpolation
:
Optional
[
str
]
=
"
n
one
"
,
interpolation
:
Optional
[
str
]
=
N
one
,
img_size
=
None
,
cbar
:
bool
=
False
,
**
imshow_kwargs
,
...
...
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