Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 9bd73062 authored by DEBREUVE Eric's avatar DEBREUVE Eric
Browse files

attempt to implement auto image resizing with wdw

parent ccba4cd5
No related branches found
No related tags found
No related merge requests found
......@@ -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 image_t
from PIL import Image as plim
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",
"lmap",
"color_version",
"with_cm",
"gfp_mip",
"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
lmap: array_t
color_version: bool
with_cm: str
gfp_mip: 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 = image_t.fromarray(array)
output = pltk.PhotoImage(master=parent, image=pil_image)
pil_image = plim.fromarray(array)
tk_image = pltk.PhotoImage(master=parent, image=pil_image)
return output
return tk_image, pil_image
def _MIPAxisChoiceWidget(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment