Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NutriMorph
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DEBREUVE Eric
NutriMorph
Commits
1f68b7fd
Commit
1f68b7fd
authored
4 years ago
by
DEBREUVE Eric
Browse files
Options
Downloads
Patches
Plain Diff
refactored soma validation interface + color
parent
1b41ed0e
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
brick/interface/soma_validation.py
+86
-36
86 additions, 36 deletions
brick/interface/soma_validation.py
nutrimorph.py
+1
-1
1 addition, 1 deletion
nutrimorph.py
with
87 additions
and
37 deletions
brick/interface/soma_validation.py
+
86
−
36
View file @
1f68b7fd
import
tkinter
as
tk
import
tkinter
as
tknt
from
typing
import
Union
import
numpy
as
n
p
from
PIL
import
Image
,
ImageTk
import
numpy
as
n
mpy
from
PIL
import
Image
as
image_t
,
ImageTk
as
tk_image_t
array_t
=
n
p
.
ndarray
array_t
=
n
mpy
.
ndarray
class
soma_validation_window_t
:
def
__init__
(
self
,
lmap
:
array_t
,
mip_axis
:
int
=
-
1
):
__slots__
=
(
"
lmap
"
,
"
mip
"
,
"
mip_4_display
"
,
"
root
"
,
"
canvas
"
,
"
tk_image
"
,
"
canvas_image
"
,
)
lmap
:
array_t
mip
:
array_t
mip_4_display
:
array_t
root
:
tknt
.
Tk
canvas
:
tknt
.
Canvas
tk_image
:
tk_image_t
canvas_image
:
int
def
__init__
(
self
,
lmap
:
array_t
,
mip_axis
:
int
=
-
1
,
color_version
:
bool
=
True
):
""""""
self
.
lmap
=
lmap
self
.
mip
=
np
.
max
(
lmap
,
axis
=
mip_axis
)
mip_shape
=
self
.
mip
.
shape
offset
=
50
scaling
=
(
255.0
-
offset
)
/
np
.
max
(
self
.
mip
)
self
.
scaled_mip
=
scaling
*
self
.
mip
+
offset
self
.
scaled_mip
[
self
.
mip
==
0
]
=
0
self
.
root
=
tk
.
Tk
()
self
.
canvas
=
tk
.
Canvas
(
self
.
root
,
width
=
mip_shape
[
1
],
height
=
mip_shape
[
0
]
)
self
.
tk_image
=
ImageTk
.
PhotoImage
(
master
=
self
.
root
,
image
=
Image
.
fromarray
(
self
.
scaled_mip
)
)
self
.
canvas_image
=
self
.
canvas
.
create_image
(
0
,
0
,
anchor
=
"
nw
"
,
image
=
self
.
tk_image
)
self
.
canvas
.
bind
(
"
<Button-1>
"
,
self
.
_DeleteSoma
)
self
.
canvas
.
pack
()
def
LaunchInteraction
(
self
)
->
None
:
mip
=
nmpy
.
max
(
lmap
,
axis
=
mip_axis
)
if
color_version
:
mip_4_display
=
_ColoredVersion
(
mip
)
else
:
mip_4_display
=
_ScaledVersion
(
mip
)
root
=
tknt
.
Tk
()
canvas
=
tknt
.
Canvas
(
root
,
width
=
mip
.
shape
[
1
],
height
=
mip
.
shape
[
0
])
tk_image
=
_TkImageFromNumpyArray
(
mip_4_display
,
root
)
canvas_image
=
canvas
.
create_image
(
0
,
0
,
anchor
=
"
nw
"
,
image
=
tk_image
)
canvas
.
pack
()
canvas
.
bind
(
"
<Button-1>
"
,
self
.
_DeleteSoma
)
for
field
in
self
.
__class__
.
__slots__
:
setattr
(
self
,
field
,
eval
(
field
))
def
LaunchValidation
(
self
)
->
None
:
""""""
self
.
root
.
mainloop
()
# scikit-image.relabel(self.lmap)
def
_DeleteSoma
(
self
,
event
)
->
None
:
def
_DeleteSoma
(
self
,
event
:
tknt
.
EventType
.
ButtonPress
)
->
None
:
""""""
row
=
event
.
y
col
=
event
.
x
...
...
@@ -50,8 +61,47 @@ class soma_validation_window_t:
soma_bmap
=
self
.
mip
==
value
self
.
mip
[
soma_bmap
]
=
0
self
.
scaled_mip
[
soma_bmap
]
=
0
self
.
tk_image
=
ImageTk
.
PhotoImage
(
master
=
self
.
root
,
image
=
Image
.
fromarray
(
self
.
scaled_mip
)
)
self
.
canvas
.
itemconfig
(
self
.
canvas_image
,
image
=
self
.
tk_image
)
if
self
.
mip_4_display
.
ndim
==
1
:
self
.
mip_4_display
[
soma_bmap
]
=
0
else
:
for
channel
in
range
(
self
.
mip_4_display
.
shape
[
2
]):
self
.
mip_4_display
[...,
channel
][
soma_bmap
]
=
0
self
.
tk_image
=
_TkImageFromNumpyArray
(
self
.
mip_4_display
,
self
.
root
)
self
.
canvas
.
itemconfigure
(
self
.
canvas_image
,
image
=
self
.
tk_image
)
def
_ScaledVersion
(
image
:
array_t
,
offset
:
int
=
50
)
->
array_t
:
"""
offset: Value of darkest non-background intensity
"""
scaling
=
(
255.0
-
offset
)
/
nmpy
.
max
(
image
)
output
=
scaling
*
image
+
offset
output
[
image
==
0
]
=
0
return
output
.
astype
(
nmpy
.
uint8
)
def
_ColoredVersion
(
image
:
array_t
)
->
array_t
:
""""""
max_label
=
nmpy
.
amax
(
image
)
labels
=
tuple
(
range
(
1
,
max_label
+
1
))
half_length
=
int
(
round
(
0.5
*
max_label
))
shuffled_labels
=
labels
[
half_length
:]
+
labels
[:
half_length
]
shuffled_image
=
nmpy
.
zeros_like
(
image
)
for
label
,
shuffled_label
in
enumerate
(
shuffled_labels
):
shuffled_image
[
image
==
label
]
=
shuffled_label
output
=
nmpy
.
dstack
((
image
,
shuffled_image
,
max_label
-
image
))
output
=
(
255.0
/
max_label
)
*
output
output
[
image
==
0
]
=
0
return
output
.
astype
(
nmpy
.
uint8
)
def
_TkImageFromNumpyArray
(
array
:
array_t
,
parent
:
Union
[
tknt
.
Widget
,
tknt
.
Tk
])
->
tk_image_t
:
""""""
pil_image
=
image_t
.
fromarray
(
array
)
output
=
tk_image_t
.
PhotoImage
(
master
=
parent
,
image
=
pil_image
)
return
output
This diff is collapsed.
Click to expand it.
nutrimorph.py
+
1
−
1
View file @
1f68b7fd
...
...
@@ -277,7 +277,7 @@ def NutriMorph(data_path: str,
elif
interactive
:
# smvl.SomaValidation(som_nfo["lmp"], mip_axis=0)
window
=
smvl
.
soma_validation_window_t
(
som_nfo
[
"
lmp
"
],
mip_axis
=
0
)
window
.
Launch
Interac
tion
()
window
.
Launch
Valida
tion
()
#
# -- Extentions
...
...
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