The application will receive the input file in ppm format and perform certain operations over the image and save it when the users wants. The input commands are provided by user either using text-based scripting or using a text script that contains. If the user provides an invalid command, the program will throw an exception and continue to wait for the correct input command.
The application has adopted the MVC design pattern. The model consists of all the methods that deal with load the PPM file , saving as PPM file and performing operations over the image, the controller connects the model with view and decided which function to execute based on the input command.
- A new interface EnhancedImageProcessingModel has been created that extends the old interface ImageProcessingModel.
- This new interface has new methods for adding and fetching images from HashMap. Features is a new class that holds commands that links GUI with controller is created and extended by the controller.
- For view a new interface and implementation is created. This imlpmentation is resposible for the GUI working.
- Another class called Histogram is used for displaying the histogram(bar graph) in the GUI. This class extends the JPanel
- All parts of the program is completed.
- To follow the solid principle of not changing the interface we created two interfaces one in model and other in controller which is extending the old interfaces.
- In view we created a new interface for GUI and kept old interface for performing Command line things.
This pixel class is made for storing the rgb value of a pixel in an image. Each object of this pixel class is made up of three integers, each one representing a channel's value. This class has two methods.
- int get(int channel): This method takes the channel number (0-red,1-green,2-blue) as an argument and returns the value of that channel.
- void set(int channel,int value) : This methods takes the channel number and the an integer value as arguments and change the corrensponding channel's value with the new value.
Both the methods will throw an illegal argument exception if an invalid channel number ( >2) is provided.
This class extends the Pixel class, apart from the three channels from the pixel class, the pixel enhanced not also has another channel for alpha value.
This class is used for reading the ppm file and storing it. We create a 2D array of pixel objects to store the pixel values from the PPM file. This class has the following methods.
- Pixel[][] readPPM(String filename): This method the path of the ppm file as an argument. It will read the PPM file and create a 2D array of pixel objects to store the pixel values from the PPM file. The size of the array will be equal to the dimensions of the image. The first triplet of rgb values will be the 1st element in the array and so on.
This class consits of all the operations that can be performed over the image. These operations are defined as methods and they are described as below.
- void loadImage(String filePath, String fileName): This method takes the path of the ppm file and the name under which image object has to be stored and calls the readPPM method from ImageUtil class. After reading the PPM document the method will return all the pixel values in the ppm file as a 2D array of pixel objects.
- void createRed(Pixel[][] image): This method will take an image as a pixel array object and convert it into a red-tinted image.
- void createGreen(Pixel[][] image): This method will take an image as a pixel array object and convert it into a green-tinted image.
- void createBlue(Pixel[][] image): This method will take an image as a pixel array object and convert it into a green-tinted image.
- void valueGrayScale(String searchImageKey, String storeKey): This method will take searchImageKey which searches for image object and storeKey which stores the manipulated image under that name and convert it into a grayscale image using the value component.
- void lumaGrayScale(String searchImageKey, String storeKey): This method will take searchImageKey which searches for image object and storeKey which stores the manipulated image under that name and convert it into a luma grayscale image using the luma component.
- void intensityGrayScale(String searchImageKey, String storeKey): This method will take searchImageKey which searches for image object and storeKey which stores the manipulated image under that name and convert it into an intensity grayscale image using the intensity component.
- void flipVertically(String searchImageKey, String storeKey): This method will take searchImageKey which searches for image object and storeKey which stores the manipulated image under that name and flip it vertically.
- void flipHorizontally(String searchImageKey, String storeKey): This method will take searchImageKey which searches for image object and storeKey which stores the manipulated image under that name and flip it vertically.
- void imageBrightenDarken(String searchImageKey, String storeKey, int value): The method will take an image and a positive or a negative value, and it will brighten or darken all the pixels in the image respectively by adding or subtracting the value to it.
- void splitImage(String searchImageKey, String[] storeKeys): This method will take searchImageKey which searches for image object and an array of storeKeys which contains the key names which is the red-grayscale, green-grayscale and blue-grayscale.
- void combineImage(String[] searchImageKeys, String storeKey): This method performs the opposite of split method. This method search for the image keys of all three red, green, blue greyscale and store it under name passed to storeKey.
- void saveFile(String filePath, String searchImageKey): This method search the image object using searchImageKey and stores it in the provided path on a provided format.
- void createRedGray(String searchImageKey, String storeKey): This method searches image object using searchImageKey , creates a red-tinted version and then generate a grayscale version based on value component.
- void createGreenGray(String searchImageKey, String storeKey): This method searches image object using searchImageKey , creates a green-tinted version and then generate a grayscale version based on value component.
- void createBlueGray(String searchImageKey, String storeKey): This method searches image object using searchImageKey , creates a blue-tinted version and then generate a grayscale version based on value component.
This class contains methods for creating a key value pair, where value being a pixel array object and key being a string, a name for referencing the pixel array object. The methods under this class are as follows:
- addImage(String imageName, Pixel[][] inputImage): This method creates a key value pair in Hashmap where the pixel array object inputImage is the value and the string imageName is the key that acts as a reference for the inputImage.
- fetchImage(String imageName): This method takes the string as a key and returns the pixel array object it references to.
- boolean search(String imageName): This method takes the string as a key and searches if any such key is present in the hashmap.
This class decides the sequence of methods to be executed. This class contains the method that matches the methods with the user command.
void inputSelection(): This method decides the input mode. The input mode can be either loading a text file with commands or using terminal to enter commands.
commandExecution(Scanner input): This methods takes the scanner object as an argument and consists of various cases. Each case executes one of the methods found in ImageProcessingModelImpl. Based on the input, these cases will be executed. If a valid command is not provided, this method will throw an exeception. This function end only when quit command is passed.
This class performs sepia-tone of an image. This class constructor takes commands and perform sepia if correct commands are passed.
This class performs dithering on an image. This class constructor takes dithering commands.
This class performs two commands. The filter constructor takes commands as input and checks which filter has been called and perform it on image. blur: This filter blurs the image. sharpen: This filter sharpens the image.
This class performs six commands. The greyscale constructor takes commands as input and checks which greyscale component has been called and perform it on image. red-component: This gives the red greyscale component of an image. green-component: This gives the green greyscale component of an image. blue-component: This gives the blue greyscale component of an image. luma-component: This gives the luma greyscale component of an image. intensity-component: This gives the intensity greyscale component of an image. value-component: This gives the value greyscale component of an image.
This class calls the model to perform horizontal flip on an image.
This class calls the model to perform vertical flip on an image.
This class calls the model to perform horizontal flip on an image.
The class calls the model of brighten image on getting the brighten command.
The class calls the model of load image on getting the load command.
The class calls the model of combine image on getting the combine command.
The class calls the model of split image on getting the split command.
The class calls the model of save image on getting the save command.
The class runs the .txt file on getting the run command.
This class consists of load and save method for the BMP format images.
This class consists of load and save method for the PNG format images.
This class consists of load and save method for the PPM format images.
This class consists of load and save method for the JPEG/JPG format images.
A class for displaying histogram of iamges in the GUI.
void paintComponent(Graphics g): A method to create the histogram.
int findMaxValue(int[] data): The method to find the max value from the data.
This class holds all the GUI implementation of view.
void addFeatures(Features features):This method adds all the features used to present image on GUI.
String load(): This method loads the image from the system and return the imagePath of the image.
String save():This forms the actual command for executing the operations. The method returns the actual formed command.
void displayImage(String imageName):This displays the image on GUI. The parameter takes the image name.
void displayError(): This displays the error encountered while working on image.
String display(String s): This displays the error encountered while working on image.
This is the interface for the ImageProcessingModelImpl class which contains all the methods for image manipulation, loading a PPM file and saving data as a PPM file.
This is the interface for the HashStorageImpl class which contains the methods for adding pixel array objects and strings as value and key pair respectively.
An interface add some extra methods on ImageProcessingModel.
This is the interface for the ImageProcessingControllerImpl class which contains the method that decides which method to execute when a command is entered.
This is the interface for all the commands which contains method that takes model as an arguement and performs all the commands.
This is the interface contains load and save methods to perform on all the different format options available.
This interface represents the operations that can be done using the GUI that will be handled by controller.
This interface represents the operations of view that will be handled by controller.
This is the older view class to display output in command line.
The main method consists of an model and controller object and calls the inputSelection() method in ImageProcessingControllerImpl class.
To run the application.
- Run the Main program from the src folder.
- The program will wait for user commands.
- The user can either type input commands in the IntelliJ terminal or use the load command in the terminal to load the text file that contains the commands.
Our application can perform the following operations:
- Load : The application can read a ppm file
- Save : The application can write an image into a ppm file format.
- Flip vertical: The application can flip an image vertically.
- Flip Horizontal: The application can flip an image horizontally.
- Gray scale images: The application can generate a gray scale version of the image based on value, intensity or luma component
- Channel Gray scale image: The application can also generate a gray scale of tinted images based on value component
- Brighten an image: The application can brighten an image or darken an image.
- Sepia tone an image: The application can generate sepia tone of an image.
- Dithering an image: The application can generate dithered image.
- blur: The filter can blur an image.
- sharpen: The filter can sharpen an image.
Link: https://www.cs.cornell.edu/courses/cs664/2003fa/images/