EN161 - Image Processing and Understanding
Lab 2: Image Region Processing 
Due Tuesday, 9/17
NOTE: Problems should be done in MATLAB.  Type up your solutions for each one including: (1) The answer to any questions posed, (2) any resulting images (include in document), and (3) the name of any function(s) (testfunc.m, threshold.m, etc.) you used. 

Zip or tar your document with your source code (m-files) into a file called [Lastname_FirstInitial_Lab2.zip/tar] and email it to mcchang@lems.brown.edu with the subject "EN161 Lab2".

Overview:
This lab takes the tools you used in lab1 to manipulate the regions of various images.  It will also give you a chance to become familiar with the digital camera.  Come by the lab (BH317) or set up a time to check out the digital camera, take a few pictures, and upload them to the computer.  You will use the images in this lab.

NOTE: Any coordinates given in this handout are in the form of  [x, y].  MATLAB, however, is reversed in its array handling, it uses IMAGE(height_coordinate, width_coordinate), be careful with this.  Also remember that the point (1,1) in an image is the upper left corner.

Data:
draw_line.m - Function which draws a line (using the parametric equation) between passed in points. 
Takes as input: x1, y1, x2, y2, image where [x1, y1] and [x2, y2] are the end points and image is the image to draw the lines (sets the line to 255) in. It returns the updated image.  So to draw a vertical line 20 pixels in from the left edge and 40 pixels down from the top, and 100 pixels long:
I2 = draw_line(20, 40, 20, 140, I);
imshow(I2);
Image A
Image B
Image C
Image D
Problem 1:
Load image A, copy the window between [135, 135] and [220, 180] into a new region (i.e. copy the pixels from this region into a new image array), save it as a new image.  Rotate the new image by 180 degrees and save this new rotated version as another image.  Now insert the rotated image back into the original spot in the original image.


the region [135, 135]->[220, 180]

To rotate, you need to multiply the current pixel coordinates by a rotation matrix to determine the new pixel coordinates, then set the intensity at the resulting new coordinates to the intensity at the original coordinates.

Rotation Matrix:
   cos(theta)     -sin(theta) 
   sin(theta)        cos(theta) 

Be sure you adjust where the center of the region you are rotating is to be the center of the region and not the top left corner of the image.  i.e. subtract 1/2 Height and 1/2 width from the points, rotate it, then add the values back.

Problem 2:
Take region [45, 95] -> [105, 125] from image B and rotate it 90 degrees (clockwise) and translate it [80, -60] to fit into the missing section in the top right corner.
Problem 3:
Take two pictures that you took with the digital camera and load them into matlab.  Use the function rgb2gray to covert them to grayscale.  You will also have to change the class of the image from uint8 to double in order to perform operations with the data.  You will then have to change it back in order to view it with imshow.  For example:

myImage = imread('myPhoto.jpg');
grayImage = rgb2gray(myImage);
doubleImage = double(grayImage);

...perform operations with doubleImage...
processedImage = someFunction(doubleImage);

finalImage = uint8(processedImage);
imshow(finalImage)

Perform the following operations on the two images: ADDITION, SUBTRACTION, MULTIPLICATION, and DIVISION (The images must be exactly the same size, use .* and ./ instead of * and / for multiply and devide).  Include the original images as well as the resulting images in your report and be sure to indicate which image goes with which operation.  If you want, you can control the contribution of each image in the operation.  For example:

Addition: C = A + k * B, where k is a single value.
Use whatever looks the best.

[note:  make sure that the resulting intensities are within the correct range, if they are not, rescale the values or just cap them to 255 or 0].


 
Problem 4:
Perform the following operations on the binary images C and D: AND, OR and XOR. 

[Remember, instead of 0 and 1, the binary values of the image are 255 and 0, that is 0-->255 and 1-->0].  


 
Problem 5:
Create a series of images (8 exactly), of different shapes (about 100x100 in size), create a square, a circle, a triangle, and an ellipse, both filled and unfilled.


example shapes