CSC 342 - Project 6 - Fast Image Processing
In this project you will build an image processing application supporting a number of standard, pixel-level and local operations to be applied to images. This will be a mulitple-document interface (MDI) permitting the manipulation of multiple images each displayed in separate child windows. Finally this project will ue
"unsafe" code methods to achieve a significant speed-up in processing.
Introduction - Image processing is any form of signal processing for which the input is an image. Image processing is an important part of a wide variety of computer disciplines including biomedical research and diagnosis, geosciences, graphics and animation, surveillance & security, machine vision, and automatic target recognition.
A digital image can be represented as a two-dimensional array of pixels. The location of a pixel in the image is defined by it's row and column index. A pixel is thought of as an individual point in the image.Actually a pixel is comprised of red, green, and blue sub-pixels. When the image is captured (by a digital camera) the color components are arranged in a two-by-two pattern generated by placing an optical color filter over the camera's CCD (charge-coupled device) or image collection element. When displayed, the arrangement of RGB dots in each pixel may vary among monitors from different manufacturers, but the original aspect ratio (height to width ratio) of the pixels is usually maintained.
Pixel-Level Operation - A pixel-level operation is a change in the image that is applied to every pixel in an image in the same way. An example of a pixel-level operation is invert in which the RGB values of each pixel P, in an image is altered in the following manner:
where each color component (R,G, B) is represented as an unsigned byte with a range of 0 to 255.
Local Operation - In a local operation on an image the new value of each pixel can depend on its own value as well as the values of pixels in its neighborhood. An example of a local operation is smoothing, in which the value of each pixel is replaced with the average value of itself and its eight nearest neighbors.
where P(i,j) represents the R,G, and B color components with the indicated operations being applied to each color component separately. It is also important to note that smoothing requires a temporary copy of the image to prevent modified pixels in a row from affecting operations in the next row.
Implementation - Use the following step-by-step instructions as a guide to building your program.
Step 1 - Create a New Windows Forms project with an appropriate name (e.g. FastImageProcessing).
Step 2 - Set isMdiContainer = true and WindowState = Maximized.
Step 3 - Add a new Item to this project of type Windows Form and name it childForm (or similar).
Step 4 - Establish this Window as a child of the parent Form by changing its constructor as follows:
Step 5 - Include a MenuStrip an openFileDialog and a saveFileDialog on the parent Form. Be sure to add using System.IO; to the using list.
Step 6 - Add a panel to the child Form with Dock = fill, and AutoScroll = true.
Step 7 - Drop a pictureBox (example name picBox) into the child Form panel and position it in the upper left corner of the panel. Set pictureBox properties Dock = none, and SizeMode = AutoSize.
Step 8 - Create a File Main Menu Item on the MenuStrip of the parent Form and include an Open, Save, and SaveAs List Items under this Menu Item.
Step 9 - Add the following Open method to the child Form:
Step 10 - In the parent Form, double-click Open to create an openMenuItem_Click( ) methods and insert the following code.
At this point, you should test the program to verify that images can be opened and displayed. Verify that multiple images of different types can be open simultaneously, and that you can scroll to view images larger than the viewing window.
Step 11 - Download the ImgPro.cs class from the Instructor's Web page and place it in the folder that contains the other source code of your project. Add this class as an existing item. Be sure that the namespace designation matches that of your project.
Step 12 - The ImgPro.cs class uses unsafe to permit the conversion of a bitmap to a byte array, allowing direct access to pixel RGB components with array bounds checking. This results in significanly faster processing. To use this class you must modify your project to permit the use of unsafe code. Right-click the Project name, choose Properties, select the Build tab and check Allow unsafe code.
Step 13 - On the parent Form MenuStrip, create a Main Menu Item called Filters. Under Filters include List Items for Erode, Grayscale, and Invert. Double-click each to create a click method for these filters. Implement each of these three filters by the following procedure in which implementation of the Invert filter is illustrated.
Step 14 - Add the following code to the parent Form click-method for the Invert filter:
Step 15 - Add the following method to the childForm.
publicvoid Invert()
{
Bitmap copy = newBitmap((Bitmap)this.picBox.Image);
ImgPro bg = newImgPro(copy);
bg.Invert();
picBox.Image = bg.Bitmap;
picBox.Update();
}
Test your program to verify that the Invert method operates correctly.
Step 16 - Add the following methods to the childForm for Save( ) and SaveAs( ).
Step 17 - Complete the baseline project by implementing the Save and SaveAs operations. Add code in the click-event methods of the parent Form that call the Save( ) and SaveAs( ) methods in the childForm.
Submission - Implement the other two filters included in the ImpPro.cs class, and create and implement a filter of your own design. Debug you project and submit a Word or PDF document showing example images with an explanation of the operation of your project. Submit this document along with a zipped copy of your entire project. Zip file should inlude your name.