User:Mws08/HW-2

Abstract
The assignment here was broken up into five parts. The first part was to simulate a bluescreen environment. The second part was to modify an image in four ways:


 * 1) Shrinking it by a factor of 4 by choosing 1 pixel within a 2x2 block and ignoring the rest.
 * 2) Shrinking it by a factor of 4 by averaging the pixels in a 2x2 block
 * 3) Flipping it vertically
 * 4) Flipping it horizontally

Bluescreening
Since the background was a fairly consistent shade of blue, I iterated through the pixels, and replaced blue pixels with the corresponding pixel from my background image. Since not all blue pixels were the same shade, I had to accept a range of blues as valid.

Code to check if pixel is a background (LOW_RED, etc. are constants): bool isBackground(int r, int g, int b) { if ((r &gt;= LOW_RED &amp;&amp; r &lt;= HIGH_RED) &amp;&amp; (g &gt;= LOW_GREEN &amp;&amp; g &lt;= HIGH_GREEN) &amp;&amp; (b &gt;= LOW_BLUE &amp;&amp; b &lt;= HIGH_BLUE)) return true; return false; } Main code that iterates through the list: for (i=0;i&lt;width;i++){ for (j=0;j&lt;height;j++){ if (isBackground(in1[i+j*width].r, in1[i+j*width].g, in1[i+j*width].b)) {   		output1[i+j*width].r=background[i+j*width].r;    		output1[i+j*width].g=background[i+j*width].g;    		output1[i+j*width].b=background[i+j*width].b;    	} } }

Lossy scaling
I created a smaller image, and then iterated through the smaller image, copying the every 2nd pixel horizontally and vertically (RATIO = 2, since both the vertical and horizontals are halved): for (i=0; i&lt;newWidth; i++){ for (j=0; j&lt;newHeight; j++){ output1[i+j*newWidth].r=in1[i*RATIO+j*width*RATIO].r;   		output1[i+j*newWidth].g=in1[i*RATIO+j*width*RATIO].g;    		output1[i+j*newWidth].b=in1[i*RATIO+j*width*RATIO].b;    } }