Project

General

Profile

Project: Image Processing Application

User documentation
10/31/2024

Here's documentation for each component of the code, covering class descriptions, methods, functions, and key details for a better understanding of the entire process.


  1. Project: Image Processing Application
  1. Overview
    This application is a GUI-based tool for loading, processing, and saving images based on configuration settings. Users select configuration files that define parameters for processing images (such as gamma correction, transparency factor, and image side), and the application performs alpha blending and other transformations before displaying and saving the processed images.

  1. 1. `ConfigReader` Class
    Handles reading configuration settings from an `.ini` file and provides methods to retrieve specific parameters.
  1. Methods:
    - `__init__(self, config_path)`: Initializes the `ConfigReader` with the provided configuration file path, loading the file for further operations.
    - `getImageName(self)`: Returns the image filename as a string from the configuration file.
    - `getProjectedImageWidth(self)`: Returns the projected width of the image (in pixels).
    - `getProjectedOverlapWidth(self)`: Returns the overlap width for image blending.
    - `getGamma(self)`: Returns the gamma correction factor.
    - `getImageSide(self)`: Returns an integer indicating which side of the image is being processed (0 for left, 1 for right).
    - `getTransparencyFactor(self)`: Returns the transparency factor for blending, defaulting to `1.0` if unspecified.

  1. 2. `MainDisplay` Class
    Handles loading images and preparing them for processing by other components.
  1. Methods:
    - `readImage(self, image_path)`: Loads an image from the specified file path. Returns the image as an array with 3 channels (BGR).
    - `setImage(self, image)`: Placeholder for potential image modifications before processing, returning the image array.

  1. 3. `MaskCreator` Class
    Handles image transformations such as gradient mask creation, gamma correction, and alpha blending. This class is used to create smooth transitions between two images.
  1. Methods:
    - `__init__(self, image, transparency_factor)`: Initializes `MaskCreator` with the image array and transparency factor.
    - `smoothstep(self, edge0, edge1, x)`: Creates a smooth gradient transition using the smoothstep function.
    - `create_mask(self, image_side, mask_width, image_width)`: Creates a gradient mask for the specified image side and width, adjusting the gradient strength based on the transparency factor.
    - `gammaCorrection(self, gamma)`: Applies gamma correction to the image, enhancing its brightness or contrast based on the gamma value.
    - `alpha_blending(self, image_side)`: Blends the gamma-corrected image with a black background based on the gradient mask, producing a smooth transition effect for the specified side (left or right).

  1. 4. `process_image` Function
    Orchestrates the image processing workflow by loading configurations, applying transformations, and preparing the image for saving.
  1. Arguments:
    - `config_path`: Path to the configuration file for the image.
    - `main_display`: An instance of `MainDisplay` used to load and set the image for processing.
  1. Returns:
    - Tuple: The processed image and its corresponding name (left or right).
  1. Workflow:
    1. Loads configuration parameters via `ConfigReader`.
    2. Reads the image, applies gamma correction and alpha blending.
    3. Returns the processed image.

  1. 5. `save_image` Function
    Saves a processed image to a dedicated folder in the project directory.
  1. Arguments:
    - `image`: The processed image to be saved.
    - `name`: Designation of the image side (left or right).
  1. Details:
    - Creates a folder named `processed_images` if it doesn’t exist.
    - Saves the image with a filename indicating its side (e.g., `processed_image_left.png`).

  1. 6. `ImageProcessingApp` Class
    Defines the main GUI application, allowing users to select configuration files, process images, and view results.
  1. Attributes:
    - `root`: Root window of the GUI.
    - `config_left`: Path to the left image configuration file.
    - `config_right`: Path to the right image configuration file.
    - `image_display`: Label for displaying processed images in the GUI.
  1. Methods:
    - `__init__(self, root)`: Initializes the GUI components and layout.
    - `select_left_config(self)`: Prompts the user to select a configuration file for the left image.
    - `select_right_config(self)`: Prompts the user to select a configuration file for the right image.
    - `enable_process_button(self)`: Enables the "Process Images" button once both configuration files are selected.
    - `process_images(self)`: Processes the selected images based on configuration files, updating the progress bar as each image completes. Saves and displays processed images, notifying the user upon completion.
    - `display_image(self, processed_images)`: Displays processed images in the GUI window.

  1. 7. `main()` Function
    Initializes the main application window and runs the `ImageProcessingApp`.

  1. User Flow
    1. Start Application: The user opens the application, which initializes the GUI components.
    2. Select Configurations: The user selects the configuration files for the left and right images.
    3. Process Images: The user clicks "Process Images," initiating a series of transformations based on configuration values. Each processed image is saved and displayed.
    4. Completion: A message box notifies the user of successful completion, with images available in the `processed_images` folder.

  1. Example Configuration File (`config.ini`)
    This file provides parameter values for processing each image. Below is an example of the configuration structure expected by the application:

```ini
[DEFAULT]
image_name = example_image.jpg
projected_image_width = 800
projected_overlap_width = 100
gamma = 1.2
image_side = 0 # 0 for left, 1 for right
transparency_factor = 0.5
```


This documentation covers the primary components and interactions in the application. Each section of code is designed to manage specific tasks, from loading configurations to applying transformations and managing the user interface. The application's modular structure supports easy modification or extension if additional image processing features are needed.

Files