spacr.gui_elements
Module Contents
- spacr.gui_elements.restart_gui_app(root)[source]
Restarts the GUI application by destroying the current instance and launching a fresh one.
- spacr.gui_elements.set_dark_style(style, parent_frame=None, containers=None, widgets=None, font_family='OpenSans', font_size=12, bg_color='black', fg_color='white', active_color='blue', inactive_color='dark_gray')[source]
- class spacr.gui_elements.spacrFont(font_name, font_style, font_size=12)[source]
- class spacr.gui_elements.spacrContainer(parent, orient=tk.VERTICAL, bg=None, *args, **kwargs)[source]
Bases:
tkinter.FrameFrame widget which may contain other widgets and can have a 3D border.
- class spacr.gui_elements.spacrEntry(parent, textvariable=None, outline=False, width=None, *args, **kwargs)[source]
Bases:
tkinter.FrameFrame widget which may contain other widgets and can have a 3D border.
- class spacr.gui_elements.spacrCheck(parent, text='', variable=None, *args, **kwargs)[source]
Bases:
tkinter.FrameFrame widget which may contain other widgets and can have a 3D border.
- class spacr.gui_elements.spacrCombo(parent, textvariable=None, values=None, width=None, *args, **kwargs)[source]
Bases:
tkinter.FrameFrame widget which may contain other widgets and can have a 3D border.
- class spacr.gui_elements.spacrDropdownMenu(parent, variable, options, command=None, font=None, size=50, **kwargs)[source]
Bases:
tkinter.FrameFrame widget which may contain other widgets and can have a 3D border.
- class spacr.gui_elements.spacrCheckbutton(parent, text='', variable=None, command=None, *args, **kwargs)[source]
Bases:
tkinter.ttk.CheckbuttonTtk Checkbutton widget which is either in on- or off-state.
- class spacr.gui_elements.spacrProgressBar(parent, label=True, *args, **kwargs)[source]
Bases:
tkinter.ttk.ProgressbarTtk Progressbar widget shows the status of a long-running operation. They can operate in two modes: determinate mode shows the amount completed relative to the total amount of work to be done, and indeterminate mode provides an animated display to let the user know that something is happening.
- class spacr.gui_elements.spacrSlider(master=None, length=None, thickness=2, knob_radius=10, position='center', from_=0, to=100, value=None, show_index=False, command=None, **kwargs)[source]
Bases:
tkinter.FrameFrame widget which may contain other widgets and can have a 3D border.
- class spacr.gui_elements.spacrFrame(container, width=None, *args, bg='black', radius=20, scrollbar=True, textbox=False, **kwargs)[source]
Bases:
tkinter.ttk.FrameTtk Frame widget is a container, used to group other widgets together.
- class spacr.gui_elements.spacrLabel(parent, text='', font=None, style=None, align='right', height=None, **kwargs)[source]
Bases:
tkinter.FrameFrame widget which may contain other widgets and can have a 3D border.
- class spacr.gui_elements.spacrButton(parent, text='', command=None, font=None, icon_name=None, size=50, show_text=True, outline=False, animation=True, *args, **kwargs)[source]
Bases:
tkinter.FrameFrame widget which may contain other widgets and can have a 3D border.
- class spacr.gui_elements.spacrSwitch(parent, text='', variable=None, command=None, *args, **kwargs)[source]
Bases:
tkinter.ttk.FrameTtk Frame widget is a container, used to group other widgets together.
- class spacr.gui_elements.AnnotateApp(root, db_path, src, image_type=None, channels=None, image_size=200, annotation_column='annotate', percentiles=(1, 99), measurement=None, threshold=None, normalize_channels=None, outline=None, outline_threshold_factor=1, outline_sigma=1, edge_thickness=1, edge_transparency=100, edge_image=False, object_size=(0, 0))[source]
-
- static fill_holes(mask, min_size=0)[source]
Fill holes inside True regions of a binary mask.
- Parameters:
mask (ndarray[bool]) – Binary mask where True denotes foreground.
min_size (int) – Minimum hole area to fill (in pixels). - <= 0 : fill ALL internal holes. - > 0 : fill only holes smaller than min_size; reopen larger ones.
- Returns:
Hole-filled mask.
- Return type:
ndarray[bool]
- outline_image(base_img, full_img, edge_sigma=1, edge_thickness=1, fill_holes=True, object_size=(0, 0))[source]
Anti-aliased outlines with sub-pixel thickness that never get dimmer as they get thinner. Uses peak normalization so outline brightness is thickness-invariant (then scaled only by edge_transparency).
- Parameters:
base_img (PIL.Image) – already filtered (visible base)
full_img (PIL.Image) – normalized RGB before filtering (edge detection / underlay)
edge_sigma (float) – Gaussian smoothing before thresholding
edge_thickness (float) – outline thickness in output pixels (supports < 1, e.g. 0.01)
fill_holes (bool) – fill internal holes in foreground masks before boundary extraction
object_size (tuple[int,int]) – (min_px, max_px) connected-component area filter. 0 disables that bound.
- static normalize_image(img, percentiles=(1, 99), normalize_channels=None)[source]
If normalize_channels is None or [], do nothing. Otherwise normalize only those channels (r/g/b).
- train_and_classify()[source]
Merge data from the relevant DB tables (including png_list).
2) Collect manual annotations from png_list.<annotation_column> => ‘manual_annotation’. - 1 => class=1, 2 => class=0 (for training). 3) If only one class is present, randomly sample unannotated images as the other class. 4) Train an XGBoost model. 5) Classify all rows -> fill XGboost_score (prob of class=1) & XGboost_annotation (1 or 2 if high confidence). 6) Write those columns back to sqlite. 7) Refresh the UI.
- static convert_settings_dict_for_gui(settings)[source]
Decide widget type per setting: - ‘check’ => Checkbutton (bools) - ‘combo’ => readonly Combobox (predefined choices) - ‘entry’ => Entry (free text / numbers / lists) Returns: {key: (kind, options, initial)}
- build_multi_annotation(source_columns, target_column='multi_annot')[source]
Consolidate multiple {1,2,NULL} columns into a single integer code column. Unique per combination. If all inputs NULL -> store NULL. Sets self.annotation_column to target_column and refreshes UI.
Encoding: per col: NULL->0, 1->1, 2->2 code = 1 + sum( digit_i * (3^i) ), i = 0..N-1 (all digits 0) => store NULL instead of 1
- ensure_multi_annot_from_selection(source_columns, target_column='class_column', force_rebuild=True)[source]
If one column selected -> use it directly (no consolidation). If >=2 selected -> build a consolidated column. If target_column already exists, auto-bump to target_column_1, target_column_2, … and use that actual name everywhere.
Returns the effective annotation column name.
- spacr.gui_elements.modify_figure_properties(fig, scale_x=None, scale_y=None, line_width=None, font_size=None, x_lim=None, y_lim=None, grid=False, legend=None, title=None, x_label_rotation=None, remove_axes=False, bg_color=None, text_color=None, line_color=None)[source]
Modifies the properties of the figure, including scaling, line widths, font sizes, axis limits, x-axis label rotation, background color, text color, line color, and other common options.
Parameters: - fig: The Matplotlib figure object to modify. - scale_x: Scaling factor for the width of subplots (optional). - scale_y: Scaling factor for the height of subplots (optional). - line_width: Desired line width for all lines (optional). - font_size: Desired font size for all text (optional). - x_lim: Tuple specifying the x-axis limits (min, max) (optional). - y_lim: Tuple specifying the y-axis limits (min, max) (optional). - grid: Boolean to add grid lines to the plot (optional). - legend: Boolean to show/hide the legend (optional). - title: String to set as the title of the plot (optional). - x_label_rotation: Angle to rotate the x-axis labels (optional). - remove_axes: Boolean to remove or show the axes labels (optional). - bg_color: Color for the figure and subplot background (optional). - text_color: Color for all text in the figure (optional). - line_color: Color for all lines in the figure (optional).
- spacr.gui_elements.generate_dna_matrix(output_path='dna_matrix.gif', canvas_width=1500, canvas_height=1000, duration=30, fps=20, base_size=20, transition_frames=30, font_type='arial.ttf', enhance=[1.1, 1.5, 1.2, 1.5], lowercase_prob=0.3)[source]
Generate a DNA matrix animation and save it as GIF, MP4, or AVI using OpenCV for videos.