Explore
My Project
There are various ways for you to explore my project. Please feel free to download anything from this site to use and alter to best fit your needs. If you have questions beyond the explanation found here, you are welcome to contact me. Enjoy!
OpenCV
If you are interested in running the executable files or compiling and running a new version of them, you will need to install the OpenCV (Intel® Open Source Computer Vision Library) that is utilized in these programs. Directions for doing so can be found here.
A very simple program that would be a great starting place for processing webcam images using OpenCV can be downloaded here. This program is a stripped-down version of a demo from the sample programs packaged with the OpenCV library. This program reads images from the webcam and displays them in a window until the user presses Esc.
view_webcam.cpp
(C++ code)
view_webcam.exe (executable program)
Sample Programs
The sample programs that I developed and used for analysis of my project can be downloaded here. The ones that use still images (cmp_threshold.cpp, diff_cv.cpp, and rescale_cmp.cpp) are written to open the file mexico.jpg. Feel free to use your own picture by altering the code and re-compiling. Be sure to see the instructions for installing OpenCV before attempting to execute any of these programs on your computer. Also, just added to the project is an interface that offers a menu and option to enter a file name for a still image when applicable; this program can be found following the Sample Programs section.
The first program was used for analyzing what affect the threshold value had on the Bresenham algorithm. The scroll bar on the top of the window labeled Original changes the value of the threshold so that it can range anywhere from 0 to 1. This is the threshold that aids in the decision of whether to take the average of neighboring pixels or snap to (do a straight copy of) the next pixel. I did not visually notice a difference with various threshold values until it was set to 1. In this case the image became much sharper than the other, which maintained a threshold of .5 as in the original version of the Bresenham image scaling algorithm of Thiadmer Riemersma. This result makes sense because with a threshold = 1, the algorithm becomes the coarse Bresenham algorithm which simply does a nearest neighbor interpolation and does not do any averaging. The code and executable are available here.
cmp_threshold.cpp
(C++ code)
cmp_threshold.exe (executable program)
The second program was used to compare the smooth Bresenham image scaling algorithm to various forms of interpolation already a part of the OpenCV library. The OpenCV library includes a function, cvResize(), that will resize an image using one of the following interpolation methods: nearest-neighbor, bilinear, bicubic, or re-sampling using pixel area relation. This program allows the user to switch among these various interpolation methods by adjusting the scroll bar labeled Method on the top of the window labeled Original. The other scroll bar on this window, labeled Scale, allows the user to zoom in and out to be able to compare the methods at various scales (zooming in vs. zooming out and by what amount, i.e. 150% vs. 235%).
diff_cv.cpp
(C++ code)
diff_cv.exe (executable program)
The third program is used for
analysis of the smooth Bresenham algorithm and how it recreates the original
image from a scaled image. This program also compares the smooth Bresenham
scaling algorithm to the nearest neighbor algorithm in the same area of
analysis. It does this by first scaling the original image by the scale
dictated from the scroll bar on top of the window labeled Original; it
then takes that scaled image and uses the same algorithm on it to scale back to
the original size. Then the original image as well as the "unscaled" or
"rescaled" images from the two algorithms are displayed. The program also does
minimal calculations for analysis of the image recreation. On the standard
output screen, the black command window, it will display the average difference
in pixels from the original and the "rescaled" image to show how close the
algorithm got to recreating the original. In my experiments, these numbers were
always the same for the two algorithms; this was not a good analysis for
comparing the two, but it was a start.
I also wrote a similar program to perform a slightly different analysis; this
is the second one listed below. This version simply adds up the difference
between all the pixels of the original to the "rescaled" images and outputs
this total to a default file called comparison.txt. It also compares the total
difference in pixel values from the smooth Bresenham algorithm to that of the
nearest neighbor interpolation performed by the OpenCV function and prints the
algorithm with the lower difference. This is to assume that the one with the
lower difference, or most pixels the same as the original, is a "better"
algorithm. This may not always be true. I would say that from a human's visual
perspective, there were times when I thought the Bresenham algorithm provided a
better image than the nearest neighbor interpolation even though the difference
of pixel values was smaller with the nearest neighbor algorithm. I believe that
this is because the Bresenham algorithm provides a smoother interpolation when
it uses the averages so the image looses the sharp jagged edges that can appear
in a nearest neighbor interpolation. This offers a more visually-appealing
image, despite the greater difference in pixel values.
Displays average difference
of pixels:
rescale_cmp.cpp (C++ code)
rescale_cmp.exe (executable program)
Outputs total difference of
pixels to a file:
rescale_cmp2.cpp (C++ code)
rescale_cmp2.exe (executable program)
The final program presented here uses the webcam to run the algorithm on streaming video. The scroll bar on the top of the window labeled Original sets the scale by which the image is scaled. This allows the user to zoom in and out as the video continues to stream from the webcam. To run this program, first make sure that your webcam drivers are installed and the webcam is working properly. As mentioned in the "How to" for OpenCV installation, this program should work with any webcam.
scroll_webcam.cpp
(C++ code)
scroll_webcam.exe (executable program)
Menu Interface
The finished product from this project is an interface that offers a menu to the user allowing them to choose which "program" they want to run from those samples above. It loops infinitely so the user can choose to zoom in and out of a still image, and then on streaming video from their webcam without exiting the program. It also allows the user to enter a file name for the functions that use still images. This offers a bit of flexibility so the user can zoom in and out of their own picture, rather than accepting the default one I chose to hard-code into the program. Each of the functions work as the above programs were described.
To choose an option, the user simply presses the number located next to the appropriate option. To open a still image, it is best to make sure the image file is in the same folder as the executable (interface.exe) file (or the interface.cpp code file if running through Visual Studio). Be sure to enter both the file name and its extension (i.e. mexico.jpg or jackie.jpg). For the function that rescales the images and compares them to the original, I chose to compare with my second version, the total difference in pixel values, because I felt it gave a better basis for comparison. I still hope to find a better method of analysis, including a more accurate statistical comparison as well as a visual aesthetic test with artists (art majors and professors).
A slight disclaimer is that not all file formats and image sizes seem to be scaling correctly with the Bresenham algorithm. I have tested a variety of options, but have yet to solve this problem (see my Journal for more information).
interface.cpp
(C++ code)
interface.exe (executable program)
Presentation
The PowerPoint I used in my presentation can be downloaded by clicking here. A brief outline of the presentation follows:
Project Description
Demonstration
Learning & Development Process
Q & A
Return to Top of Page