0% found this document useful (0 votes)
4 views

Lab-exercises-v9

Uploaded by

abrahamdsl
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lab-exercises-v9

Uploaded by

abrahamdsl
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

A Practical Introduction to the Methods and Applications

of Digital Image Processing

To run and compile:


Go to the ImageLab directory: cd Desktop/imagelab
To compile the program gray1.cpp and create the executable file gray1.out:
make gray1.out <Enter>
To run the program: ./gray1.out <Enter>

Part A: Image Fundamentals, Filtering and Enhancement

Exercise A-1: Converting a color image to gray scale (gray1.cpp)


Study the program – how a color JPEG image is read, how a color image is created, how
pixels are accessed and modified, and how to write the output to a color JPEG image. The
program also shows how to create a function that takes an image as input a gives an output.

Exercise A-2: Convert a rectangular PART of a color image to gray scale (part1.cpp)
The program converts a rectangular part of the image to gray scale. This rectangle is
defined by (startX,startY) and (endX,endY). Adjust the rectangle and see the change in the
output image.

Exercise A-3: Drawing a box on an image canvas (box1.cpp)


Shapes and special effects can be embedded on images. The program draws a colored box
on an image. Try changing the boundaries of the box and also its color.

Exercise A-4: Drawing the intensity histogram of an image (hist1.cpp)


The image histogram is a graph showing the frequency of the different pixel values. The
histogram is useful for analyzing the image intensity distribution. The effect of brightness and
contrast modification is evident when comparing the histogram of the input and that of the
output. Compare the histogram of different images. For the next exercises, observe what
happens to the intensity histogram after applying the method.
./hist1.out <input image> <histogram image>

Exercise A-5: Changing the image brightness (bright1.cpp)


The overall image brightness can be linearly adjusted. This is demonstrated in the program.
The parameter brightAdjust , whose range is –1.0 to 1.0, brightens or darkens the image.
If brightAdjust > 0, the image is brightened. If brightAdjust < 0, the image darkens.
Adjust this parameter and see the effect.

Exercise A-6: Changing the image contrast using gamma adjustment (gamma1.cpp)
Gamma adjustment is one way of adjusting the overall contrast of an image. If the parameter
gamma is less than 1.0 but greater than 0, then the lower intensities are stretched up,
resulting in a brighter image but with greater contrast for the lower intensities. On the other
hand, a gamma that is greater than 1.0 stretches the high intensities downward, resulting in
a darker image but with greater contrast for the higher intensities. Play around with the value
of gamma on different input images and observe the result. Modify the program such that a
small region is enhanced instead of the whole image.

Exercise A-7: Increasing the image contrast using histogram equalization (histeq1.cpp)
Histogram equalization is a contrast-enhancing technique. It modifies the intensity histogram
to match the uniform distribution as closely as possible. The parameters startX, startY,
endX, and endY define the region that will contrast-enhanced. The parameter percent
determines the amount of contrast enhancement, where a value of percent=100 maximizes
the contrast. Find images with low-contrast regions and bring out the image details in these
regions using histogram equalization.

Exercise A-8: Increasing the image contrast using histogram stretching (histstretch1.cpp)
Another method for increasing the image contrast is by stretching the intensity histogram.
This time, the left end (parameter lowerPercentile) of the histogram is “pulled” to black and
the right end (parameter upperPercentile) is “pulled” to the white end. The parameters
startX, startY, endX, and endY define the region that will contrast-enhanced. Adjust these
parameters to see the effect on the region’s contrast. Try this on other images.

Exercise A-9: Mean and median filtering (filter1.cpp)


The program demonstrates two common methods for filtering – the mean filter and the
median filter. These two filters work by averaging the neighborhood of each pixel. The
parameter filterWidth controls the size of the averaged neighborhood, or the amount of
filtering. Try increasing this parameter and observe its effect on the output. Compare the
output of the median filter and mean filter.

Exercise A-10: Edge detection using the image gradient and zero crossings (edge1.cpp)
One way of finding significant edges in an image is using the edge magnitude. Applying a
threshold on the gradient magnitude separates the significant edges from the rest of the
image. In the program, adjust gradientMagnitudeThreshold and observe the edges that
were picked out. Did the method also pick out the noise? Another method for finding edges
is by applying a second-derivative operator (ex. Laplacian) and detecting the zero-crossings.
The program applies the Laplacian operator and marks the edges that mark the location of
the zero-crossings.

Exercise A-11: Sharpening an image using an unsharp mask (sharp1.cpp)


This exercise is not yet finished.

Exercise A-12: Translating, rotating, and scaling an image (warp1.cpp)


Translation, rotation and scaling are three examples of 2-D image transformations. What
should be the order of the three operations? Try re-arranging the three operations and see
which sequence is better. Create an image sequence of a rotating image.
Part B: Binary Image Processing

Exercise B-1: Separating objects from plain background (binary1.cpp)


The intensity threshold is a simple way for creating a binary image, separating the object
pixels from the background. The program outputs the black and white visualization of a
binary image that was created using the threshold intensityThreshold applied on a
grayscale image. Adjust the value of this threshold and observe what happens to the binary
image. If the background is not of a single plain color, what would be a good strategy for
separating the background from the foreground objects?

Exercise B-2: Cleaning binary images (clean1.cpp)


In most cases, a binary image needs to be cleaned before further processing. The program
creates a binary image which can be cleaned using methods such as erosion, dilation,
opening, closing, etc. Explore these methods by combining, repeating or adjusting these
methods. The parameter strucWidth is the size of the structuring element which can be
adjusted.

Exercise B-3: Character segmentation in document images (charseg1.cpp)


One aspect of document image analysis is recognition of individual characters. The program
finds each character in the document image using the steps of binarizing, cleaning, and
connected component labeling. Each character is then isolated into a single JPEG image,
ready for character recognition. Try to apply the method on other document images, such as
digits.jpg. What are the critical parameters in this program?

Exercise B-4: Counting objects and measuring their sizes (count1.cpp)


The area of an object can be computed as the number of 1-pixels of its connected
component. The program puts an orange box around each object whose area is between
minimumArea and maximumArea. Adjust the values of these parameters and observe
what objects get picked. Apply the object counter to the image “coins1.jpg” and adjust the
parameters such that it will pick the 25-centavo coins.

Exercise B-5: Tracing the boundary of an object (boundary1.cpp)


One way to analyze an object’s shape is by looking at it’s boundary. Features such as
corners, convexities, concavities and inflection points can be computed from the boundary
and can be used to characterize and classify the object’s shape. The program implements a
boundary-tracing algorithm, which finds each object and extracts its boundary. One shape
feature you can compute is compactness = perimeter^2 / area. What is the most compact
shape?

Exercise B-6: Finding words, lines and paragraphs in a document image (page1.cpp)
Page layout analysis is an area of document image analysis where the system groups
characters horizontally to find words, words are grouped horizontally to find text lines, and
text lines are grouped vertically to find paragraphs. In this program, hierarchical grouping is
done by horizontal or vertical “smearing”, followed by connected component analysis.
Adjust the “smearing” parameters (structuring element’s dimensions for dilation) to get good
grouping at each level of the hierarchy.
Exercise B-7: A document form reader: optical mark recognition
Write a program that reads the answers from the attached 30 forms (forms30.zip). Put a
green box on each input field. Put a red box on the input fields that are shaded. The field
locations are found in the attached file fields39.csv. Each row of the CSV file corresponds
to a question with seven input fields (choices) whose locations are arranged x1 y1 x2 y2 x3
y3 x4 y4 x5 y5 x6 y6 x7 y7. As a bonus, put a blue box around answers with an “X”.
Part C: Color Image Processing

Exercise C-1: Coloring a gray scale image (pseudo1.cpp)


The program assigns colors to different ranges of the gray scale. This is also known as
pseudo-coloring. Try to change the ranges as well as the assigned colors. How does this
color image compare to the original gray image?

Exercise C-2: Modifying Hue, Saturation and Intensity components (hsi1.cpp)


The program demonstrates the ability to modify hue, saturation and intensity components
independently. Try reducing the saturation to 0.5, 0.25, and 0.0. What happened to the
picture?

Exercise C-3: Finding specific colors (color1.cpp)


The program looks for pixels whose hue and saturation are within a certain range. Modify
the bounds of these ranges and see what pixels are selected. Change the input image and
try to isolate uniform-colored regions using the hue and saturation ranges.

Exercise C-4: Finding the major colors in an image (kmeans1.cpp)


Note: To run the program, use the command example
./kmeans1.out images/kristen.jpg 8
where the first parameter is the input image and the second parameter is K

K-means clustering is a pattern recognition technique for finding the K natural groupings, or
clusters, in a given data set. The clustering algorithm is applied to the pixels of a color
image, where each pixel is a point in the RGB color space. Try the method on different types
of images. For each image, try to find the best value of K. Assuming that K is NOT initially
known, how would you modify the program to automatically find the best value of K?
Part D: Image Sequence Processing

Exercise D-1: Change detection (change1.cpp)


Detection of changes in a scene is an important problem in many vision applications. The
program shows a simple method for detecting pixels that have changed significantly between
the two images. The parameter threshold is used to adjust the “sensitivity” of the change
detector.

Exercise D-2: Tracking a moving object (mtrack1.cpp)


The image sequence in the directory images/car1/ contain a moving object. The program
follows the moving object by computing frame-to-frame intensity differences, and using the
difference image to track the moving object. Change the variable followCar=1 to
followCar=0 to switch to the image sequence images/kids1/ showing walking kids. The
output of the motion tracker is found in images/motiontrack/. What are the possible
situations that could confuse a motion tracker?

Exercise D-3: Tracking a colored object using Histogram Backprojection (ctrack1.cpp)


The image sequence in the directory images/redblue/ contains two colored objects moving
around. Given the location of an object in the first frame, the tracking algorithm learns its
color and follows the object throughout the image sequence. The parameter trackBlue
allows you to set whether you want to track the blue toy (trackBlue = 1) or the red ball
(trackBlue = 0). Run the program and examine the output in the directory
images/colortrack/ . What are the possible situations where the tracker can get confused?

Exercise D-4: Background subtraction (backsub1.cpp)


In many video analysis applications, transient objects such as persons or vehicles are
separated from the background scene before their behavior is analyzed. The program
computes the image of the background scene using a temporal median technique. Each
frame is then “subtracted” from the background image to separate the foreground object
pixels. The program uses the image sequence in images/student as input and writes the
output JPEG sequence in images/backsub/.

Exercise D-5: Event detection using the image correlation (corr1.cpp)


A reliable way to detect the presence or absence of objects is by comparing a region of the
current frame with the same region in the computed background. The image correlation is
useful for computing the degree-of-match between two image regions. Object detection can
then be extended to detection of events that happen over time, such as the passing of a car
or the opening of a door. The program implements a lane-based car detector, which can be
later be extended to counting cars, measuring speed, detecting stalled vehicles and
measuring traffic congestion.

You might also like