Homework 1

Due Monday 9/10 @ 11:59pm

Learning Objective

The learning objective of this assignment is:


Background and Tools

You may complete this assignment using Java, C/C++, C#, Python, or another language with my approval. You may use built-in file I/O and image classes for this assignment, but the required tasks should not rely on built-in functions.

The following pages may be helpful:

Assignment

For this assignment, you will create a program that performs Green Screen image composting.

In addition, your program will demonstrate working with binary images, color spaces, grayscale conversion, morphological operations, and blurring.

Getting started - create a composed image:

  1. Before diving into the entire main task, your first version should create the composed greenscreen image directly. Iterate over all pixels and use the pixel color to decide which input image pixel to use in the output image. Once you have this working, you can modify your program to build in the functionality of the main task below.

    The specifics of the main task are as follows:

    1. Image input: read your input image (person in front of a green screen) and background scene. Store each image in a data structure or class.
    2. Compute a binary image mask of the foreground.
      • Do this once for a default RGB color space.
      • Do this a second time after converting the image or pixel values into either HSV or YUV color space.
      • Save output images of both examples, but you only need to continue with one.
    3. Apply morphological operations as needed to fill gaps or remove noise in your binary image masks.
    4. Use the binary image mask to compose a new image consisting of pixels of the person in the foreground image, and pixels of the scene from the other image.
    5. Output the resulting image to a file.

    Secondary task:

    1. Convert your output image to grayscale. Your program should compute the grayscale value of each pixel (do not use a built-in conversion function). Use the appropriate equation rather than simple average of color values.
    2. Write a blur method that averages pixel values in an output image based on the average value of pixels in a square. For example blur(3) should result in an output image that averages pixels in a 3x3 region, while blur(5) would average pixels in a 5x5 region.

    Sample Result Page

    Here is a example results web page. This web page only contains example results for the main task, so make sure you include results for all tasks. Brandon Guo's Results from 2012

    You can use the HTML for your own web page. Just "view page source" and copy the HTML into a text editor like Notepad++ or TextWrangler. Then change the images and text to show off your results.

    Starter Code

    Here is a zip file of some Java starter code: SimpleImage.

    This code contains a "wrapper" SimpleImage class, as well as some sample code that reads and writes images. From the SimpleImage class, you an request a pixel at any x,y coordinate which will be of the class java.awt.Color. Use it's getRed() method to get the red value, etc.

    Java-SimpleImageProc.zip is an expanded version of this code that can display images and was originally used to access a webcam on Windows PCs, so there is some extra stuff in there that you don't need, but you can play with if you wish. The ImageViewer class can respond to keypresses, but you'll have to add some things to the code if you want the changes to show up in your static images (versus a webcam video, which would be redrawn with the changes on the next frame of the video).

    Feel free to modify anything in this code. You don't have to use this if you don't want to

    Green-Background Images

    Use your cell phone camera to take a picture in front of the green screen. You probably want to crop/rotate the green image using an image editor before using your image as input to your program. Be aware of issues you might encounter if you try to process images of different dimensions, so either have your program deal with it or crop both input images to the same sizes.

    What to Submit

    Create a web page that showcases all the work you did for this assignment. Resize images as appropriate for the web.

    The web page should contain:

    • The two original input images
    • The binary images from both RGB color space and either HSV or YUV.
      • Explain your approach for determining foreground from background in both RGB and your alternative color space.
    • The binary image after application of morphological operations.
      • Explain which morphological operations you applied, why you chose them, and your opinion of their effectiveness.
    • The final color output image.
    • The converted grayscale output image.
    • Two images blurred using your blur method with different parameters. Explain which parameters were used.
    Zip up your code in a file named "hw01-username.zip"
    Submit this on the submission site (To be announced and updated later). The code you submit should be capable of being executed on your input image and produce ALL of your output images. Your code must have appropriate style

    Grading Criteria

    Refer to the grading criteria file: hw01.criteria.

    Academic Honesty and Collaboration

    Cooperation is recommended in understanding programming concepts and system features. But the actual solution of the assignments including all programming must be your individual work. For example, copying without attribution any part of someone else's program is plagiarism, even if you have modified the code. The University takes acts of cheating and plagiarism very seriously.

    For this HW01 assignment specifically:
    You may discuss the following with your classmates: Image I/O, data structures, and approaches to implementing morphological operations. It is ok to work on code, for these topics only, with someone who is in the same room. It is not permitted to share code that you did not actively participate in developing.

    The remainder of the assignment should be done on your own. Specifically including but not limited to: creation of resulting images, foreground segmentation, use of morphological operations, grayscale and color space conversions, image blurring.