navigate.controller.sub_controllers.camera_view.BaseViewController
- class navigate.controller.sub_controllers.camera_view.BaseViewController(view, parent_controller=None)
Bases:
GUIController
,ABaseViewController
Base View Controller Class.
- __init__(view, parent_controller=None) → None
Initialize the Camera View Controller Class.
- Parameters:
view (tkinter.Frame) – The tkinter frame that contains the widgets.
parent_controller (Controller) – The parent controller of the camera view controller.
Methods
__init__
(view[, parent_controller])Initialize the Camera View Controller Class.
add_crosshair
(image)Adds a cross-hair to the image.
apply_lut
(image)Apply a LUT to an 8-bit single-channel image.
Calculates the offset of the image.
Apply digital zoom.
display_image
(image)Display an image.
down_sample_image
(image)Down-sample the data for image display according to widget size.
execute
(command, *args)This function is called when a command is passed from a child process.
flip_image
(image)Flip the image according to the flip flags.
Gets the absolute position of the computer mouse.
get_selected_channels
([microscope_state])Get the selected microscope channels from the MicroscopeState.
As images arrive, identify channel index and slice.
initialize
(name, data)Sets widgets based on data given from main controller/config.
Initialize the non-live display.
left_click
(*_)Toggles cross-hair on image upon left click event.
Marks the current position of the microscope in the multi-position acquisition table.
mouse_wheel
(event)Digitally zooms in or out on the image upon scroll wheel event.
Move the crosshair to a non-default position.
Move the stage according to the position the user clicked.
populate_image
(image)Update the Tk canvas using a persistent PhotoImage + paste.
popup_menu
(event)Right-Click Popup Menu
Processes the image to be displayed.
refresh
(width, height)Refresh the window.
register_event_listener
(event_name, ...)Register event listener in the parent_controller
render
(image)Process the image to be displayed.
reset_display
([display_flag, reset_crosshair])Set the display back to the original digital zoom.
resize
(event)Resize the window.
scale_image_intensity
(image)Scale the data to the min/max counts, and adjust bit-depth.
Sets values of widgets based on experiment setting
set_mode
([mode])Sets mode of camera_view_controller.
show_verbose_info
(*info)Prints verbose information to the console
toggle_min_max_buttons
([display])Checks the value of the autoscale widget.
transpose_image
(image)Transpose the image according to the flip flags.
try_to_display_image
(image)Try to display an image using a single worker and a 1-deep queue.
Update the canvas size.
Collects all the values of widgets
update_lut
(target)Update the LUT in the Camera View.
update_min_max_counts
([display])Get min and max count values from the View.
Updates the signal-to-noise ratio.
update_transpose_state
([display])Get Flip XY widget value from the View.
Attributes
Custom events for the controller
Max frames per second (0 or None disables throttling)
The imaging mode.
The flag for the display of the cross-hair.
The flag for autoscaling the image intensity.
The bit depth of the image.
The tkinter canvas that displays the image.
The width of the canvas.
The height of the image.
The height of the canvas.
The scaling factor for the height of the canvas.
The width of the canvas.
The scaling factor for the width of the canvas.
Precomputed lookup table for the image colormap.
The mode of the camera view controller.
The microscope name
The flip flags for the camera.
The image data.
The count of images.
The logger for the camera view controller.
The maximum counts of the image.
The minimum counts of the image.
The number of channels in the image.
The number of slices in the image volume.
The original height of the image.
The original width of the image.
The resize event ID.
The selected channels being acquired.
The index of the slice in the image volume.
The stack cycling mode.
The tkinter image.
The total number of images per volume.
The flag for transposing the image.
The zoom scale of the image.
The zoom offset of the image.
The zoom rectangle of the image.
The zoom scale of the image.
The zoom value of the image.
The zoom width of the image.
The dictionary of image palette widgets.
The x position of the mouse.
The y position of the mouse.
Percentage of crosshair in x
Percentage of crosshair in y
the flag for offsetting the crosshair
- add_crosshair(image: ndarray) → ndarray
Adds a cross-hair to the image.
- Parameters:
image (np.ndarray) – Image data.
- Returns:
image – Image data with cross-hair.
- Return type:
np.ndarray
- apply_lut(image: ndarray) → ndarray
Apply a LUT to an 8-bit single-channel image.
- Parameters:
image (np.ndarray) – 8-bit image data (uint8), scaled to [0..255].
- Returns:
image – RGB image data with LUT applied.
- Return type:
np.ndarray
- calculate_offset() → tuple
Calculates the offset of the image.
- Returns:
offset_x (int) – The offset of the image in x.
offset_y (int) – The offset of the image in y.
- digital_zoom() → ndarray
Apply digital zoom.
The x and y positions are between 0 and the canvas width and height respectively.
- Returns:
image – Image after digital zoom applied
- Return type:
np.ndarray
- display_image(image: ndarray) → None
Display an image.
- Parameters:
image (np.ndarray) – Image data.
- down_sample_image(image: ndarray) → ndarray
Down-sample the data for image display according to widget size.
Interpolation type is cv2.INTER_LINEAR by default.
- Parameters:
image (np.ndarray) – Image data.
- Returns:
down_sampled_image – Down-sampled image data.
- Return type:
np.ndarray
- execute(command, *args)
This function is called when a command is passed from a child process.
- Parameters:
command (str) – command name
args (tuple) – command arguments
- flip_image(image: ndarray) → ndarray
Flip the image according to the flip flags.
- Parameters:
image (np.ndarray) – Image data.
- Returns:
image – Flipped and/or transposed image data.
- Return type:
numpy.ndarray
- get_absolute_position() → tuple
Gets the absolute position of the computer mouse.
- Returns:
x (int) – The x position of the mouse.
y (int) – The y position of the mouse.
- get_selected_channels(microscope_state: Optional[dict] = None) → None
Get the selected microscope channels from the MicroscopeState.
- Parameters:
microscope_state (Optional[dict]) – The microscope state dictionary object.
- identify_channel_index_and_slice() → tuple
As images arrive, identify channel index and slice.
- Returns:
channel_idx (int) – The channel index.
slice_idx (int) – The slice index.
- initialize(name, data) → None
Sets widgets based on data given from main controller/config.
- Parameters:
name (str) – ‘minmax’, ‘image’.
data (list) – Min and max intensity values.
- initialize_non_live_display(microscope_state: dict, camera_parameters: dict) → None
Initialize the non-live display.
- Parameters:
microscope_state (dict) – Microscope state.
camera_parameters (dict) – Camera parameters.
- left_click(*_) → None
Toggles cross-hair on image upon left click event.
- mark_position() → None
Marks the current position of the microscope in the multi-position acquisition table.
- mouse_wheel(event: Event) → None
Digitally zooms in or out on the image upon scroll wheel event.
Sets the self.zoom_value between 0.05 and 1 in .05 unit steps.
- Parameters:
event (tk.Event) – num = 4 is zoom out. num = 5 is zoom in. x, y location. 0,0 is top left corner.
- move_crosshair() → None
Move the crosshair to a non-default position.
- move_stage() → None
Move the stage according to the position the user clicked.
- populate_image(image: ndarray) → None
Update the Tk canvas using a persistent PhotoImage + paste.
This is a zero-copy operation that allows us to update the canvas image without creating a new PhotoImage object every time. This is much faster than creating a new PhotoImage object and reconfiguring the canvas item. Copying the image from a buffer is between 100 and 800 microseconds. Pasting the image is between 3 and 5 ms.
- Parameters:
image (np.ndarray) – The image data to be displayed on the canvas.
- popup_menu(event: Event) → None
Right-Click Popup Menu
- Parameters:
event (tk.Event) – x, y location. 0,0 is top left corner.
- process_image() → None
Processes the image to be displayed.
- refresh(width: int, height: int) → None
Refresh the window.
- Parameters:
width (int) – Width of the window.
height (int) – Height of the window.
- register_event_listener(event_name, event_handler)
Register event listener in the parent_controller
- Parameters:
event_name (str) – event name
event_handler (function) – event handler
- render(image: ndarray) → Optional[ndarray]
Process the image to be displayed.
- Parameters:
image (np.ndarray) – Image data to be processed.
- Returns:
image (np.ndarray)
Applies digital zoom, down-samples the image, scales the
image intensity, adds a crosshair, applies the lookup table, and populates the
image.
- reset_display(display_flag: bool = True, reset_crosshair: bool = True) → None
Set the display back to the original digital zoom.
- Parameters:
display_flag (bool) – Flag for refreshing the image display. Default True.
reset_crosshair (bool) – Flag for resetting the crosshair. Default True.
- resize(event: Event) → None
Resize the window.
- Parameters:
event (tk.Event) – Tkinter event.
- scale_image_intensity(image: ndarray) → ndarray
Scale the data to the min/max counts, and adjust bit-depth.
Notes
For autoscaled image intensity, with numpy, it was taking around 6ms. With cv2, this is reduced to 300 microseconds. With non autoscaled data, still taking around 4 ms. Need to change the trace.
- Parameters:
image (np.ndarray) – Image data.
- Returns:
image – Scaled image data (uint8).
- Return type:
np.ndarray
- set_experiment_values()
Sets values of widgets based on experiment setting
setting_dict is a dictionary
- set_mode(mode: str = '') → None
Sets mode of camera_view_controller.
- Parameters:
mode (str) – camera_view_controller mode.
- show_verbose_info(*info)
Prints verbose information to the console
- Parameters:
info (tuple) – information to be printed
- toggle_min_max_buttons(display: bool = False) → None
Checks the value of the autoscale widget.
If enabled, the min and max widgets are disabled and the image intensity is autoscaled. If disabled, miu and max widgets are enabled, and image intensity scaled.
- transpose_image(image: ndarray) → ndarray
Transpose the image according to the flip flags.
- Parameters:
image (np.ndarray) – Image data.
- Returns:
image – Flipped and/or transposed image data.
- Return type:
np.ndarray
- try_to_display_image(image: ndarray) → None
Try to display an image using a single worker and a 1-deep queue.
This enqueues the most recent frame and drops older frames if the queue is full. Also, rate-limits enqueues to self.max_fps (default 20 Hz).
- update_canvas_size() → None
Update the canvas size.
- update_experiment_values()
Collects all the values of widgets
setting_dict is a reference of experiment dictionary update the dictionary directly
- update_lut(target) → None
Update the LUT in the Camera View.
When the LUT is changed in the GUI, this function is called. Updates the LUT.
- update_min_max_counts(display: bool = False)
Get min and max count values from the View.
When the min and max counts are toggled in the GUI, this function is called. Updates the min and max values.
- Parameters:
display (bool) – Flag to display the image.
- update_snr() → None
Updates the signal-to-noise ratio.
- update_transpose_state(display: bool = False) → None
Get Flip XY widget value from the View.
If True, transpose the image.
- apply_cross_hair
The flag for the display of the cross-hair.
- Type:
bool
- autoscale
The flag for autoscaling the image intensity.
- Type:
bool
- bit_depth
The bit depth of the image.
- Type:
int
- canvas
The tkinter canvas that displays the image.
- Type:
tkinter.Canvas
- canvas_height
The height of the canvas.
- Type:
int
- canvas_height_scale
The scaling factor for the height of the canvas.
- Type:
int
- canvas_width
The width of the canvas.
- Type:
int
- canvas_width_scale
The scaling factor for the width of the canvas.
- Type:
int
- colormap
Precomputed lookup table for the image colormap.
- Type:
np.ndarray
- crosshair_x
Percentage of crosshair in x
- Type:
float
- crosshair_y
Percentage of crosshair in y
- Type:
float
- property custom_events
Custom events for the controller
- flip_flags
The flip flags for the camera.
- Type:
dict
- height
The height of the image.
- Type:
int
- image
The image data.
- Type:
numpy.ndarray
- image_count
The count of images.
- Type:
int
- image_mode
The imaging mode.
- Type:
str
- image_palette
The dictionary of image palette widgets.
- Type:
dict
- logger
The logger for the camera view controller.
- Type:
logging.Logger
- max_counts
The maximum counts of the image.
- Type:
int
- max_fps: float
Max frames per second (0 or None disables throttling)
- Type:
float
- microscope_name
The microscope name
- Type:
str
- min_counts
The minimum counts of the image.
- Type:
int
- mode
The mode of the camera view controller.
- Type:
str
- move_to_x
The x position of the mouse.
- Type:
int
- move_to_y
The y position of the mouse.
- Type:
int
- number_of_channels
The number of channels in the image.
- Type:
int
- number_of_slices
The number of slices in the image volume.
- Type:
int
- offset_crosshair
the flag for offsetting the crosshair
- Type:
bool
- original_image_height
The original height of the image.
- Type:
int
- original_image_width
The original width of the image.
- Type:
int
- parent_controller
parent controller
- Type:
- resize_event_id
The resize event ID.
- Type:
event
- selected_channels
The selected channels being acquired.
- Type:
list
- slice_index
The index of the slice in the image volume.
- Type:
int
- stack_cycling_mode
The stack cycling mode.
- Type:
str
- tk_image
The tkinter image.
- Type:
ImageTk.PhotoImage
- total_images_per_volume
The total number of images per volume.
- Type:
int
- transpose
The flag for transposing the image.
- Type:
bool
- view
GUI view
- Type:
tkinter.Tk
- width
The width of the canvas.
- Type:
int
- zoom_height
The zoom scale of the image.
- Type:
float
- zoom_offset
The zoom offset of the image.
- Type:
numpy.ndarray
- zoom_rect
The zoom rectangle of the image.
- Type:
numpy.ndarray
- zoom_scale
The zoom scale of the image.
- Type:
float
- zoom_value
The zoom value of the image.
- Type:
float
- zoom_width
The zoom width of the image.
- Type:
int