Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Khush Patel CS5004 Object-Oriented Design Final Project: GRIME (Graphical Image Manipulation and Enhancement)

SAMPLE SCREENSHOT OF PROGRAM IN GUI MODE (WITH AN IMAGE LOADED) in "res/GUIExamples/" folder**

Sample Image of Program

Sample Images

  • inside the res folder
    • MyExamples/
      • contains an image in different image formats(BMP, PPM, PNG, JPEG)
    • NewExamples/
      • meant to serve as an optional destinal path for transformed images

Sample Script File: "script.text"

  • sample script that runs the text-view version of the image processing program from beginning to end
    • first loads an image: res/MyExamples/Land.bmp and applies each of the available operations (brighten, darken, and the 6 grayscale operations). It then saves each of the different in the various formats (BMP, PPM, PNG, JPEG) and quits.

Image Citations:

############## Image Processing Program

Overview

This Image Processing Program allows users to load, transform, and save images in various formats (PPM, JPEG, PNG). It demonstrates a modular, extensible architecture using design patterns such as Factory, Command, and Strategy to separate concerns and make the system easy to maintain and extend. In the Main class, a user can either invoke a text-view controller and either use command-line arguments via interactive mode, or a script file with all commands at once. A third option is to go into GUI mode and interact with a graphical user interface.

How to use the program (From the Main Class)

  1. Interactive text mode:
  • enter command line argument "-text" in the command line
    • it will construct a Reader object using InputStreamReader and System.in
    • uses the default System.out Appendable of the ImageController class which takes in additionally Readable and Database
  • executes a script one line at a time
  • type 'help' to learn how to format your commands to invoke the available operations
  • type 'quit' to end the program
  1. Scripted text Mode
  • enter command line argument "-file path-of-file"
    • it will construct a Reader object using FileReader and pass the reader object to ImageController class (text-based) which takes in Readable, Appendable and Database
    • it will execute each line of command from the script from beginning to the end
  1. GUI mode
    • enter no command line arguments or empty line
      • launches GUI application using the GUIImageController which takes in IView(represents GUI) and database

Key Design Changes: New patterns and components to program

In this final project, I added a GUI mode using Java Swing package to allow the user to interface with a graphical user interface to perform graphical image manipulation and enhancement.

- IViewFeatureinterface

  • I first createdIViewFeature interface for Controller which lists the set of features and operations that can be performed from a GUI-based view. The methods are called by the View and implemented in Controller to execute the backend functionality of a specific user action like if user wants to load,save, delete image or apply some image transformation. I kept the functional signatures simple with minimal inputs so it can be used by easily implemented by different controllers.
    • The benefits of IViewFeature is to list high level operations that need to be done like loading and saving image and allow the view to call the necessary method to handle the user input as the view should only exist to transmit user input and display information IViewinterface
  • I created also IViewinterface for GUI view-specific operations and provides functionalities like updating view, displaying prompts, handling user inputs through button events. For example, I created a method promptUserInput() that opens a dialog box with a title and message and is important to the IViewFeatures methods when trying to ask in response to some button actions to define a new image name.
    • The benefits of an IView interface is to encapsulate any low level interactions and allow the controller to invoke view-specific operations. IView class
  • It is the visual interface for the user interactions. It implements IView and IViewFeatures
  • It notifies the controller through IViewFeatures in response to user interactions through components such as button actions and list selection.
    • Modular design:
      • UI Components:
        • set up methods like "setUpBrightenSubPanel" to set up the appearance and layout of the the two major panels and the 4 subpanels of the right-sided editor panel
        • set up the action listeners and action commands for various buttons
      • 2 main panels: Display Panel and Editor Panel
        • Display Panel (left center):
        • incorporates its own Drawing Panel class to display and refresh image using a BufferedImage object
        • Editor Panel (right):
          • a yellow box subpanel shows the file operations: Save, Load, and Delete
          • "Choose Image to Display" subpanel
            • contains a list of loaded images and new image IDs post-transfomrations
            • user can click on list and the display panel will automatically refresh
          • "Image Operations" subpanel
            • contains the image transformation operations: Brighten, Darken, and 6 various grayscale type operations
      • Handling User Interaction:
        • IView implements IActionlistener.
        • implements IActionListener so for each button action, it call the appropriate IViewFeature method from the controller to initiate the correct sequence of events. I kept a main display center panel where it displays the current active image and refreshes when a user loads new image, deletes images or applies an operation. I have an editor panel on the right for load, save, delete and operations buttons. It contains a list of all active images that are loaded and being worked on.
      • Error handling:
        • showError() method is key for both the View and Controller to display error messages and allow program to run

GUIImageController class

  • Main controller for the graphical user interface of this image processing application
  • coordinates between specified IView and IDatabse, handle user inputs from view and execute image related operations using view-specific methods from IView and the ICommand classes that both apply operations to images and update the database(IDatabase)

High-Level Architecture

The application is organized into several key components:

1. Controllers (Text-View and GUI)

  • Class: ImageController (IController interface)
  • Design Pattern:
    • Command Pattern with the command classes, IController
  • Responsibility: Assembles the Database and view components and starts the text based image processing program

This class is a text-view controller optimized for text-based inputs from some Readable either from a script file or keyboard input. It takes in a Readable, Appendable(default System.out), and a database to store and manage images. From the readable, it constructs a scanner object that reads user input, dispatches commands from a Map<String, ICommand>, and routes execution results or error messages to an output. The Command classes will further read the arguments, fetch the image data as needed from the database, and possibly load and save to a filepath. Any errors caught in the controller are transmitted to the Appendable. The user can specify 'help' to learn the string formats for each of the operations for the command line interface. If the user wants to quit the program, it specifies 'quit'.

  • Class: GUIImageControllerImp (IController)
  • Design Pattern:
    • Command Pattern with the command classes
    • IViewFeaturesinterface to allow high level interactions between view and controller. It also prevents the entire controller being passed to the view and limits it to specific controller actions the view only needs. IViewFeatures provide a way to implement more controllers as well so controller is specific to any single View.
    • IViewencapsulates key view operations that the controller can call and allows high level interaction so other GUI type views can be invoked in the future
  • Responsibility: Serves as the main entry point to interact with a graphical user interface.

It serves as the main controller for the graphical user interface (GUI) of the image processing application. It handles user interactions from the View by implementing IViewFeatures. Overall, the controller implements the features defined in IViewFeatures and IController and interacts with the GUI's IViewto handle and update the user interface. Like the text-based ImageController, it maps specific GUI actions and their corresponding command
implementations. For example, if a user chooses to "load image" from the GUI, the load button
in the GUI will call its implementing method of IViewFeature's "loadImage()" that will then call the necessary view-specific actions via IView and database actions from the specific ICommand class. More specifically, it would load image from file path, store it in database, and display it in the view. The controller should be handling the events and necessary logic while the View only displays information. Any errors caught are given in a pop-up dialog box and the application ends once the user decides to.

2. View Class

  • Class: View
  • Interface: IView, IActionListener
  • Responsibility: Represents the GUI component of the application acting as the visual interface
  • Image Library: Java Swing

It sets up the necessary UI elements using Java Swing. It handles user action events and calls the controller via IViewFeatures to handle the implementing logic.

3. Main Class (Entry point to start Program)

  • Class: Main
  • Responsibility: Serves as the entry point of the program. It determines mode of operation based on the command-line arguments. The modes are:
    • GUI Mode: empty or no command line argument
    • Interactive Text Mode: "-text"
    • Scripted Text Mode: "-file path-of-script-file"

4. Image Database

  • Interface: IImageDatabase
  • Responsibility: Stores loaded and processed images in memory, keyed by user-defined names. Provides lookup and insertion and remove operations for IImage objects.

5. Image Readers & Writers

Interfaces: IImageReader, IImageWriter

  • Abstract Class: AbstractByteEncodedImageReader implements IImageReader
  • Abstract Class: AbstractByteEncodedImagereader implements IImageWriter Responsibility: Handle file I/O for different image formats directly.

Each reader/writer implementation (e.g., PPMImageReader, JPEGImageWriter) is invoked by the corresponding command (LoadCommand or SaveCommand) based on file extension parsing within the command logic. The abstract classes help to reduce duplicate code by providing formatted generalizable methods and are key to the byte-encoded image formats (PNG, BMP and JPEG). The PPM format only requires some readable since it is a text-based image format.

6. Image Representation

  • Abstract Class: AbstractImage implements IImage; used for byte-encoded image formats
  • Responsibility: Provides a common in-memory representation: width, height,
  • max value, and an RGB pixel grid (List<Integer>[height][width]).
  • Implements pixel-level getters/setters and deep-copy for safety.
  • PPM class does not use AbstractImage because it is text-based file

7. Operations

  • Interface: IOperation
  • Implementations: BrightenOperation, DarkenOperation, LumaOperation, etc.
  • Responsibility: Encapsulate individual pixel-wise transformations. Each operation defines how to compute new RGB values from existing ones.
  • Pattern: Strategy

These operations take in and return a new IImage with the specified operation. These operations are invoked in the controller's command classes.

8. Commands

  • Interface: ICommand
  • Implementations: LoadCommand, SaveCommand, BrightenCommand, VisualizeRedCommand, etc.
  • Responsibility: Encapsulates both image transformation and database operations.
  • Pattern: Command

The command classes are a key component for the controllers. For the text view controllers, they are key to mapping the user-defined string inputs to the correct set of operations. For the image-based controllers, it does the portion of what it does in text which is update the database as necessary and apply the specified operational strategy to the image. It is used as part of the IViewFeatures methods to allow the controller to listen to user events from the View.

About

GRIME(Graphical Image Processing & Enhancement) is an advanced image editing app that provides dual support (CLI + GUI). It is implemented using Java and Java Swing Graphics Library.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages