| 1 | # Euclid Eraser Notes # |
| 2 | |
| 3 | ## Overview ## |
| 4 | This is about the Euclid Eraser mixer. |
| 5 | |
| 6 | |
| 7 | ## Description ## |
| 8 | |
| 9 | This class is intended to operate as a mixer, taking two inputs and |
| 10 | yielding one output. |
| 11 | |
| 12 | The first input is a reference input, such as a single image or a |
| 13 | stretched video of a single image. |
| 14 | |
| 15 | The second input is the video stream to operate on. |
| 16 | |
| 17 | The output is a clone of the RGB data of the second input, but with |
| 18 | the alpha channel modified. |
| 19 | |
| 20 | This mixer takes the (first) reference input, such as a static |
| 21 | background, and removes it from every frame in the video stream of the |
| 22 | second input. |
| 23 | |
| 24 | The alpha channel on the output is based on the euclidean distance of |
| 25 | the two input coordinates in 3-d RGB space. If the calculated distance |
| 26 | between the two inputs for a given pixel is less than a provided |
| 27 | (variable) threshold amount, that indicates the pixel in the |
| 28 | background (reference) image is the same or similar enough to the |
| 29 | operational (second) input that is part of the background to be |
| 30 | removed, and the transparency is set to fully transparent via the |
| 31 | alpha channel (set to 0). |
| 32 | |
| 33 | If the calculated distance exceeds the threshold, then that pixel is |
| 34 | part of the foreground image to be retained, and the transparency |
| 35 | of it is set to be fully opaque (alpha channel for that pixel set |
| 36 | to 255). |
| 37 | |
| 38 | ## Basic Algorithm ## |
| 39 | The basic comparison algorithm is: |
| 40 | |
| 41 | |
| 42 | x is reference image |
| 43 | y is comparison image to remove reference image from |
| 44 | |
| 45 | |
| 46 | ``` |
| 47 | float euclidDistance (int x_r, int x_g, int x_b, int y_r, int y_g, int y_b) |
| 48 | { |
| 49 | //calculating color channel differences for next steps |
| 50 | float red_d = x_r - y_r; |
| 51 | float green_d = x_g - y_g; |
| 52 | float blue_d = x_b - y_b; |
| 53 | |
| 54 | float sq_sum, dist; |
| 55 | |
| 56 | //calculating Euclidean distance |
| 57 | sq_sum = pow(red_d, 2) + pow(green_d, 2) + pow (blue_d) |
| 58 | dist = sqrt(sq_sum); |
| 59 | |
| 60 | return dist; |
| 61 | } |
| 62 | ``` |
| 63 | |
| 64 | ## Note ## |
| 65 | |
| 66 | Here's a handy reminder on how the bits map up. |
| 67 | |
| 68 | ``` |
| 69 | red_src1 = src1[0]; |
| 70 | green_src1 = src1[1]; |
| 71 | blue_src1 = src1[2]; |
| 72 | alpha_src1 = src1[3] |
| 73 | |
| 74 | red_src2 = src2[0]; |
| 75 | green_src2 = src2[1]; |
| 76 | blue_src2 = src2[2]; |
| 77 | alpha_src2 = src2[3] |
| 78 | ``` |
| 79 | ## Further Work ## |
| 80 | |
| 81 | Some potential improvements are: |
| 82 | |
| 83 | - Faster performance (math calculations, others) |
| 84 | - Options beyond binary for alpha |
| 85 | |
| 86 | |
| 87 | |
| 88 |