Skip to content

tabs/Images_comparison.py

Overview

This file contains 10 documented elements.

Classes

Comparision

No description available. A QDialog subclass that provides an experimental image comparison tool within the pyArchInit framework. It allows a user to select a reference image file and a directory of images, computes a per-band absolute difference score between each directory image and the reference file, and displays the results as a bar chart. On initialization, the dialog applies the application theme and displays a warning indicating that the tool is experimental and intended for development use only.

Inherits from: QDialog, MAIN_DIALOG_CLASS

Methods

init(self)

No description available. Initializes the dialog by calling the QDialog base class constructor and invoking setupUi to build the user interface. Applies the application theme via ThemeManager.apply_theme and attaches a theme toggle button using ThemeManager.add_theme_toggle_to_form. Sets the window title to "pyArchInit - Images Comparision Tools" and immediately displays a warning message box alerting the user that this is an experimental system intended for development only.

connection(self)

No description available. Establishes a database connection by instantiating a Connection object and retrieving its connection string via conn_str(), then passing it to get_db_manager() to initialise self.DB_MANAGER as a singleton. If the operation raises an exception, the method inspects the error message: if it contains "no such table", a warning dialog is displayed instructing the user to restart QGIS; any other exception triggers a separate warning dialog prompting the user to report the bug to the developer.

on_pushButton_chose_dir_pressed(self)

No description available. Opens a directory selection dialog using QFileDialog.getExistingDirectory, restricting the view to directories only via QFileDialog.Option.ShowDirsOnly. If the user selects a valid path, the chosen directory path is stored in the instance attribute self.PATH.

on_pushButton_chose_file_pressed(self)

Opens a file selection dialog restricted to image files (*.png, *.xpm, *.jpg), starting in the directory specified by the PYARCHINIT_HOME environment variable. If the user selects a file, its path is stored as a string in self.FILE.

on_pushButton_run_pressed(self)

No description available. Handles the press event of the "Run" button by iterating over all file pairs generated by generate_files_couples() and invoking calculate() on each pair. Non-None results returned by calculate() are collected into a list, and the remaining pair count is decremented accordingly. Once all pairs have been processed, the accumulated results are passed to plot_chart() for rendering.

calculate(self, imgs)

No description available. Accepts a two-element sequence imgs containing paths to two image files, opens them using Image.open, and returns -1 if the images differ in size or band composition. Otherwise, computes the sum of absolute per-band pixel differences between the two images, scales the result by dividing by 1,000,000, and returns a tuple of (label, s) where label is a string formed by concatenating the two filenames with a hyphen separator. If any exception occurs during processing, a warning dialog is displayed and the method returns None implicitly.

generate_files_couples(self)

No description available. Generates a list of file path pairs by iterating over all files found in the directory specified by self.PATH. For each file in that directory, it creates a two-element list pairing self.FILE (a fixed reference file path) with the full path of the iterated file, constructed by joining path and the filename using the OS separator. Returns the complete list of these pairs as lista_con_coppie.

plot_chart(self, d)

No description available. Accepts a list of key-value pairs d and renders a bar chart on the embedded canvas widget, where each bar represents an entry with its height corresponding to the associated numeric value. The chart is titled 'Classifica' with a y-axis label of 'Indice di differenza', and each bar is annotated with its corresponding team name rendered as rotated vertical text. If an error occurs during processing or rendering, a QMessageBox warning dialog is displayed showing the current state of data_list.