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
9bd73062
Commit
9bd73062
authored
3 years ago
by
DEBREUVE Eric
Browse files
Options
Downloads
Patches
Plain Diff
attempt to implement auto image resizing with wdw
parent
ccba4cd5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
brick/io/screen/soma_validation.py
+71
-31
71 additions, 31 deletions
brick/io/screen/soma_validation.py
with
71 additions
and
31 deletions
brick/io/screen/soma_validation.py
+
71
−
31
View file @
9bd73062
...
...
@@ -4,11 +4,12 @@ from typing import Callable, Sequence, Tuple, Union
import
matplotlib.cm
as
mpcm
import
numpy
as
nmpy
import
skimage.segmentation
as
sisg
from
PIL
import
Image
as
im
age_t
from
PIL
import
Image
as
pl
im
from
PIL
import
ImageTk
as
pltk
array_t
=
nmpy
.
ndarray
image_t
=
plim
.
Image
tk_image_t
=
pltk
.
PhotoImage
...
...
@@ -18,29 +19,33 @@ STATIC_ROW_MIN_HEIGHT = 30
class
soma_validation_window_t
:
__slots__
=
(
"
gfp
"
,
"
lma
p
"
,
"
color_version
"
,
"
with_cm
"
,
"
gfp_mi
p
"
,
"
gfp_pil_image
"
,
"
gfp_tk_image
"
,
"
lmap
"
,
"
lmap_mip
"
,
"
lmap_mip_4_display
"
,
"
lmap_pil_image
"
,
"
lmap_tk_image
"
,
"
color_version
"
,
"
with_cm
"
,
"
root
"
,
"
mip_axis_wgt
"
,
"
gfp_wgt
"
,
"
lmap_wgt
"
,
"
cursor_nfo
"
,
"
gfp_tk_image
"
,
"
lmap_tk_image
"
,
)
gfp
:
array_t
lma
p
:
array_t
color_version
:
bool
with_cm
:
str
gfp_mi
p
:
array_t
gfp_pil_image
:
image_t
gfp_tk_image
:
tk_image_t
lmap
:
array_t
lmap_mip
:
array_t
lmap_mip_4_display
:
array_t
gfp_tk
_image
:
tk_
image_t
lmap_pil
_image
:
image_t
lmap_tk_image
:
tk_image_t
color_version
:
bool
with_cm
:
str
root
:
tknt
.
Tk
mip_axis_wgt
:
tknt
.
Menubutton
gfp_wgt
:
tknt
.
Canvas
...
...
@@ -61,7 +66,15 @@ class soma_validation_window_t:
root
=
tknt
.
Tk
()
# --- Creation of MIPs and Tk images
gfp_mip
,
lmap_mip
,
lmap_mip_4_display
,
gfp_tk_image
,
lmap_tk_image
=
_MIPImages
(
(
gfp_mip
,
lmap_mip
,
lmap_mip_4_display
,
gfp_pil_image
,
gfp_tk_image
,
lmap_pil_image
,
lmap_tk_image
,
)
=
_MIPImages
(
gfp
,
lmap
,
mip_axis
,
...
...
@@ -76,16 +89,13 @@ class soma_validation_window_t:
mip_axis_wgt
=
_MIPAxisChoiceWidget
(
mip_axis
,
self
.
_ChangeMIPAxis
,
gfp
.
shape
,
root
)
gfp_wgt
=
tknt
.
Label
(
root
,
width
=
gfp_mip
.
shape
[
1
],
height
=
gfp_mip
.
shape
[
0
],
image
=
gfp_tk_image
)
lmap_wgt
=
tknt
.
Label
(
root
,
width
=
lmap_mip
.
shape
[
1
],
height
=
lmap_mip
.
shape
[
0
],
image
=
lmap_tk_image
)
gfp_wgt
=
tknt
.
Label
(
root
,
image
=
gfp_tk_image
)
lmap_wgt
=
tknt
.
Label
(
root
,
image
=
lmap_tk_image
)
cursor_nfo
=
tknt
.
Label
(
root
,
text
=
""
)
done_button
=
tknt
.
Button
(
root
,
text
=
"
Done
"
,
command
=
root
.
quit
)
# --- Event management
gfp_wgt
.
bind
(
"
<Configure>
"
,
self
.
_OnResize
)
lmap_wgt
.
bind
(
"
<Motion>
"
,
self
.
_DisplaySomaLabel
)
lmap_wgt
.
bind
(
"
<Button-1>
"
,
self
.
_DeleteSoma
)
...
...
@@ -124,11 +134,25 @@ class soma_validation_window_t:
return
nmpy
.
amax
(
self
.
lmap
)
def
_OnResize
(
self
,
event
:
tknt
.
EventType
.
Configure
)
->
None
:
""""""
self
.
gfp_pil_image
=
self
.
gfp_pil_image
.
resize
((
event
.
width
,
event
.
height
))
self
.
gfp_tk_image
=
pltk
.
PhotoImage
(
master
=
self
.
root
,
image
=
self
.
gfp_pil_image
)
self
.
gfp_wgt
.
configure
(
image
=
self
.
gfp_tk_image
)
def
_ChangeMIPAxis
(
self
,
mip_axis
:
tknt
.
IntVar
,
*
_
,
**
__
):
""""""
new_mip_axis
=
mip_axis
.
get
()
gfp_mip
,
lmap_mip
,
lmap_mip_4_display
,
gfp_tk_image
,
lmap_tk_image
=
_MIPImages
(
(
gfp_mip
,
lmap_mip
,
lmap_mip_4_display
,
gfp_pil_image
,
gfp_tk_image
,
lmap_pil_image
,
lmap_tk_image
,
)
=
_MIPImages
(
self
.
gfp
,
self
.
lmap
,
new_mip_axis
,
...
...
@@ -136,12 +160,20 @@ class soma_validation_window_t:
self
.
with_cm
,
self
.
root
,
)
self
.
gfp_wgt
.
configure
(
width
=
gfp_mip
.
shape
[
1
],
height
=
gfp_mip
.
shape
[
0
],
image
=
gfp_tk_image
)
self
.
lmap_wgt
.
configure
(
width
=
lmap_mip
.
shape
[
1
],
height
=
lmap_mip
.
shape
[
0
],
image
=
lmap_tk_image
)
self
.
gfp_wgt
.
configure
(
width
=
gfp_mip
.
shape
[
1
],
height
=
gfp_mip
.
shape
[
0
],
image
=
gfp_tk_image
)
self
.
lmap_wgt
.
configure
(
width
=
lmap_mip
.
shape
[
1
],
height
=
lmap_mip
.
shape
[
0
],
image
=
lmap_tk_image
)
self
.
gfp_mip
=
gfp_mip
self
.
gfp_pil_image
=
gfp_pil_image
self
.
gfp_tk_image
=
gfp_tk_image
self
.
lmap_mip
=
lmap_mip
self
.
lmap_mip_4_display
=
lmap_mip_4_display
self
.
gfp_tk
_image
=
gfp_tk
_image
self
.
lmap_pil
_image
=
lmap_pil
_image
self
.
lmap_tk_image
=
lmap_tk_image
def
_DisplaySomaLabel
(
self
,
event
:
tknt
.
EventType
.
Motion
)
->
None
:
...
...
@@ -177,7 +209,7 @@ class soma_validation_window_t:
else
:
for
channel
in
range
(
self
.
lmap_mip_4_display
.
shape
[
2
]):
self
.
lmap_mip_4_display
[...,
channel
][
soma_bmap
]
=
0
self
.
lmap_tk_image
=
_TkImageFromNumpyArray
(
self
.
lmap_tk_image
,
self
.
lmap_pil_image
=
_TkImageFromNumpyArray
(
self
.
lmap_mip_4_display
,
self
.
root
)
self
.
lmap_wgt
.
configure
(
image
=
self
.
lmap_tk_image
)
...
...
@@ -190,7 +222,7 @@ def _MIPImages(
color_version
:
bool
,
with_cm
:
str
,
parent
:
Union
[
tknt
.
Widget
,
tknt
.
Tk
],
)
->
Tuple
[
array_t
,
array_t
,
array_t
,
tk_
image_t
,
tk_image_t
]:
)
->
Tuple
[
array_t
,
array_t
,
array_t
,
image_t
,
tk_image_t
,
image_t
,
tk_image_t
]:
""""""
gfp_mip
=
nmpy
.
amax
(
gfp
,
axis
=
mip_axis
)
gfp_mip
*=
255.0
/
nmpy
.
amax
(
gfp_mip
)
...
...
@@ -205,10 +237,18 @@ def _MIPImages(
else
:
lmap_mip_4_display
=
_ScaledVersion
(
lmap_mip
)
gfp_tk_image
=
_TkImageFromNumpyArray
(
gfp_mip
,
parent
)
lmap_tk_image
=
_TkImageFromNumpyArray
(
lmap_mip_4_display
,
parent
)
return
gfp_mip
,
lmap_mip
,
lmap_mip_4_display
,
gfp_tk_image
,
lmap_tk_image
gfp_tk_image
,
gfp_pil_image
=
_TkImageFromNumpyArray
(
gfp_mip
,
parent
)
lmap_tk_image
,
lmap_pil_image
=
_TkImageFromNumpyArray
(
lmap_mip_4_display
,
parent
)
return
(
gfp_mip
,
lmap_mip
,
lmap_mip_4_display
,
gfp_pil_image
,
gfp_tk_image
,
lmap_pil_image
,
lmap_tk_image
,
)
def
_ScaledVersion
(
image
:
array_t
,
offset
:
int
=
50
)
->
array_t
:
...
...
@@ -256,12 +296,12 @@ def _ColoredVersionFromColormap(image: array_t, colormap_name: str) -> array_t:
def
_TkImageFromNumpyArray
(
array
:
array_t
,
parent
:
Union
[
tknt
.
Widget
,
tknt
.
Tk
]
)
->
tk_image_t
:
)
->
Tuple
[
tk_image_t
,
image_t
]
:
""""""
pil_image
=
im
age_t
.
fromarray
(
array
)
output
=
pltk
.
PhotoImage
(
master
=
parent
,
image
=
pil_image
)
pil_image
=
pl
im
.
fromarray
(
array
)
tk_image
=
pltk
.
PhotoImage
(
master
=
parent
,
image
=
pil_image
)
return
output
return
tk_image
,
pil_image
def
_MIPAxisChoiceWidget
(
...
...
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