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
Merge requests
!59
Annotation tool 4 0
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
Annotation tool 4 0
annotation_tool_4_0
into
main
Overview
0
Commits
12
Pipelines
0
Changes
2
Merged
Annotation tool 4 0
fima
requested to merge
annotation_tool_4_0
into
main
Mar 4, 2024
Overview
0
Commits
12
Pipelines
0
Changes
2
This merge finished the MVP version of the annotation tool
0
0
Merge request reports
Viewing commit
16e14d0f
Prev
Next
Show latest version
2 files
+
70
−
127
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
16e14d0f
initial tests
· 16e14d0f
Felipe Delestro Matos
authored
Feb 26, 2024
docs/notebooks/annotation_tool.ipynb
+
5
−
18
View file @ 16e14d0f
Edit in single-file editor
Open in Web IDE
Show full file
%% Cell type:markdown id: tags:
# Image annotation tool
This notebook shows how the annotation interface can be used to create masks for images
%% Cell type:code id: tags:
```
python
import
qim3d
import
matplotlib.pyplot
as
plt
import
matplotlib
as
mpl
import
numpy
as
np
%
matplotlib
inline
```
%% Cell type:code id: tags:
```
python
# Load 2D example image
img
=
qim3d
.
examples
.
blobs_256x256
# Load example image
img
=
qim3d
.
examples
.
bone_128x128x128
# Display image
plt
.
imshow
(
img
)
plt
.
show
()
```
%% Cell type:code id: tags:
qim3d
.
viz
.
slices
(
img
)
```
python
# Start annotation tool
interface
=
qim3d
.
gui
.
annotation_tool
.
Interface
()
interface
.
max_masks
=
4
# We can directly pass the image we loaded to the interface
interface
.
launch
(
img
=
img
)
interface
.
launch
(
img
[
0
]
)
```
%% Cell type:code id: tags:
```
python
# When 'prepare mask for download' is pressed once, the mask can be retrieved with the get_result() method
mask
=
interface
.
get_result
()
```
%% Cell type:markdown id: tags:
## Check the obtained mask
%% Cell type:code id: tags:
```
python
print
(
f
"
Original image shape..:
{
img
.
shape
}
"
)
print
(
f
"
Mask image shape......:
{
mask
.
shape
}
"
)
print
(
f
"
\n
Number of masks:
{
np
.
max
(
mask
)
}
"
)
```
%% Cell type:markdown id: tags:
## Show the masked regions
%% Cell type:code id: tags:
```
python
%
matplotlib
inline
nmasks
=
np
.
max
(
mask
)
fig
,
axs
=
plt
.
subplots
(
nrows
=
1
,
ncols
=
nmasks
+
2
,
figsize
=
(
12
,
3
))
# Show original image
axs
[
0
].
imshow
(
img
)
axs
[
0
].
set_title
(
"
Original
"
)
axs
[
0
].
axis
(
'
off
'
)
# Show masks
cmap
=
mpl
.
colormaps
[
"
rainbow
"
].
copy
()
cmap
.
set_under
(
color
=
'
black
'
)
# Sets the background to black
axs
[
1
].
imshow
(
mask
,
interpolation
=
'
none
'
,
cmap
=
cmap
,
vmin
=
1
,
vmax
=
nmasks
+
1
)
axs
[
1
].
set_title
(
"
Masks
"
)
axs
[
1
].
axis
(
'
off
'
)
# Show masked regions
for
idx
in
np
.
arange
(
2
,
nmasks
+
2
):
mask_id
=
idx
-
1
submask
=
mask
.
copy
()
submask
[
submask
!=
mask_id
]
=
0
masked_img
=
img
.
copy
()
masked_img
[
submask
==
0
]
=
0
axs
[
idx
].
imshow
(
masked_img
)
axs
[
idx
].
set_title
(
f
"
Mask
{
mask_id
}
"
)
axs
[
idx
].
axis
(
'
off
'
)
plt
.
show
()
```
Loading