Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 4f45e7bdfd4a5ff17f5f8eaab90d017f > files > 1507

albumshaper-2.1-6mdv2010.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>AlbumShaper: redEye.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.9 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>redEye.cpp</h1><a href="redEye_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">//==============================================</span>
<a name="l00002"></a>00002 <span class="comment">//  copyright            : (C) 2003-2005 by Will Stokes</span>
<a name="l00003"></a>00003 <span class="comment">//==============================================</span>
<a name="l00004"></a>00004 <span class="comment">//  This program is free software; you can redistribute it</span>
<a name="l00005"></a>00005 <span class="comment">//  and/or modify it under the terms of the GNU General</span>
<a name="l00006"></a>00006 <span class="comment">//  Public License as published by the Free Software</span>
<a name="l00007"></a>00007 <span class="comment">//  Foundation; either version 2 of the License, or</span>
<a name="l00008"></a>00008 <span class="comment">//  (at your option) any later version.</span>
<a name="l00009"></a>00009 <span class="comment">//==============================================</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="comment">//Systemwide includes</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;qimage.h&gt;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;qstring.h&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;qapplication.h&gt;</span>
<a name="l00015"></a>00015 
<a name="l00016"></a>00016 <span class="comment">//Projectwide includes</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include "<a class="code" href="redEye_8h.html">redEye.h</a>"</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include "<a class="code" href="redEye__internal_8h.html">redEye_internal.h</a>"</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include "../../gui/statusWidget.h"</span>
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 <span class="comment">//----------------------------------------------</span>
<a name="l00022"></a>00022 <span class="comment">// Inputs:</span>
<a name="l00023"></a>00023 <span class="comment">// -------</span>
<a name="l00024"></a>00024 <span class="comment">// QString filename - location of original image on disk</span>
<a name="l00025"></a>00025 <span class="comment">// QPoint topLeftExtreme - top left constraint</span>
<a name="l00026"></a>00026 <span class="comment">// QPoint bottomRightExtreme - botth right constraint</span>
<a name="l00027"></a>00027 <span class="comment">// StatusWidget* status - widget for making progress visible to user</span>
<a name="l00028"></a>00028 <span class="comment">//</span>
<a name="l00029"></a>00029 <span class="comment">// Outputs:</span>
<a name="l00030"></a>00030 <span class="comment">// --------</span>
<a name="l00031"></a>00031 <span class="comment">// QImage* returned - enhanced image</span>
<a name="l00032"></a>00032 <span class="comment">//</span>
<a name="l00033"></a>00033 <span class="comment">// Description:</span>
<a name="l00034"></a>00034 <span class="comment">// ------------</span>
<a name="l00035"></a>00035 <span class="comment">// There are a lot of programs out there that provide some sort of</span>
<a name="l00036"></a>00036 <span class="comment">// red eye tool, but to put it bluntly, most of them really suck.</span>
<a name="l00037"></a>00037 <span class="comment">// To be fair, the red-eye flash function on most digital cameras (my own</span>
<a name="l00038"></a>00038 <span class="comment">// Olympus 3030z included) suck too. </span>
<a name="l00039"></a>00039 <span class="comment">//</span>
<a name="l00040"></a>00040 <span class="comment">// "Such foolishness, what can men do against such reckless stupidity?"</span>
<a name="l00041"></a>00041 <span class="comment">//                                         -unknown</span>
<a name="l00042"></a>00042 <span class="comment">//</span>
<a name="l00043"></a>00043 <span class="comment">// Well, here I try to provide a better red-eye tool by studying those that suck,</span>
<a name="l00044"></a>00044 <span class="comment">// those that suck less, drawing some conclusions, and coming up with a few tricks</span>
<a name="l00045"></a>00045 <span class="comment">// of my own...</span>
<a name="l00046"></a>00046 <span class="comment">//</span>
<a name="l00047"></a>00047 <span class="comment">// The worst red eye tools suck for two reasons:</span>
<a name="l00048"></a>00048 <span class="comment">// -False positives</span>
<a name="l00049"></a>00049 <span class="comment">// -Horrid red channel desaturation</span>
<a name="l00050"></a>00050 <span class="comment">//</span>
<a name="l00051"></a>00051 <span class="comment">// I've encountered red eye tools that claim to just work </span>
<a name="l00052"></a>00052 <span class="comment">// by clicking a single button. Guess what, they don't. The sad thing is that</span>
<a name="l00053"></a>00053 <span class="comment">// while you can do a pretty good job figuring out where the red eyes are</span>
<a name="l00054"></a>00054 <span class="comment">// in a picture, the programs to provide these brain-dead interfaces usually don't</span>
<a name="l00055"></a>00055 <span class="comment">// do anything complicated at all and gunk up non-red eye regions all over the place!</span>
<a name="l00056"></a>00056 <span class="comment">//</span>
<a name="l00057"></a>00057 <span class="comment">// The second problem I'd say most programs suffer from is doing a poor job of actually</span>
<a name="l00058"></a>00058 <span class="comment">// correcting the red eye region, which is a shame but also stems from their generally</span>
<a name="l00059"></a>00059 <span class="comment">// poor understanding of where the red eyes are.</span>
<a name="l00060"></a>00060 <span class="comment">//</span>
<a name="l00061"></a>00061 <span class="comment">// Algorithm:</span>
<a name="l00062"></a>00062 <span class="comment">// ----------</span>
<a name="l00063"></a>00063 <span class="comment">// I've developed my own red-eye reduction algorithm that tries to surpass all</span>
<a name="l00064"></a>00064 <span class="comment">// others by:</span>
<a name="l00065"></a>00065 <span class="comment">// -finding the red eyes and</span>
<a name="l00066"></a>00066 <span class="comment">// -carefully fixing the color of these regions only</span>
<a name="l00067"></a>00067 <span class="comment">//</span>
<a name="l00068"></a>00068 <span class="comment">// The second step involving desaturing the red channel of offending pixels</span>
<a name="l00069"></a>00069 <span class="comment">// is largely based on Gaubtz and Ulichney's 2002 IEEE paper titled:</span>
<a name="l00070"></a>00070 <span class="comment">// "Automatic Red-Eye Detection and Correction"</span>
<a name="l00071"></a>00071 <span class="comment">//</span>
<a name="l00072"></a>00072 <span class="comment">// http://www.crl.hpl.hp.com/who/people/ulichney/bib/papers/2002-redeye%20-%20ICIP.pdf</span>
<a name="l00073"></a>00073 <span class="comment">// </span>
<a name="l00074"></a>00074 <span class="comment">// Gaubtz and Ulichney base their techinque on a complicated face-detection model.</span>
<a name="l00075"></a>00075 <span class="comment">// I know such approaches are error prone, and guess what, we have a semi (if not</span>
<a name="l00076"></a>00076 <span class="comment">// very) intelligent user sitting in front of the screen, why not put them to work!</span>
<a name="l00077"></a>00077 <span class="comment">//</span>
<a name="l00078"></a>00078 <span class="comment">// Instead of detecting face elements automatically, we first have the user select</span>
<a name="l00079"></a>00079 <span class="comment">// a region of the image that two red eyes exist within. Before continuing, we</span>
<a name="l00080"></a>00080 <span class="comment">// attempt to shrink this selection as much as possible by thresholding pixels and</span>
<a name="l00081"></a>00081 <span class="comment">// tightening the boundary as long as no above threshold pixels are cut out.</span>
<a name="l00082"></a>00082 <span class="comment">// </span>
<a name="l00083"></a>00083 <span class="comment">// threshmet = r &gt; 2*g AND r &gt; MIN_RED_VAL</span>
<a name="l00084"></a>00084 <span class="comment">//</span>
<a name="l00085"></a>00085 <span class="comment">// Red eyes tend to be red, but not nearly as green or blue. The second</span>
<a name="l00086"></a>00086 <span class="comment">// half of the threshold helps throw out low-lying noise by requiring </span>
<a name="l00087"></a>00087 <span class="comment">// the red channel to be above a minimum threshold.</span>
<a name="l00088"></a>00088 <span class="comment">//</span>
<a name="l00089"></a>00089 <span class="comment">// Many programs JUST use the first half of this test (r &gt; 2*g) to pick pixels</span>
<a name="l00090"></a>00090 <span class="comment">// within a region to fix. I suppose you can get away without the noise test but</span>
<a name="l00091"></a>00091 <span class="comment">// fudging up all these other pixels, even if it isn't very noticable, really bugs me.</span>
<a name="l00092"></a>00092 <span class="comment">// I did extensive testing and tuned that second paramters to filter such changes out.</span>
<a name="l00093"></a>00093 <span class="comment">//</span>
<a name="l00094"></a>00094 <span class="comment">// Once we've shrunk the selected area, we proceed with the heart of the algorithm:</span>
<a name="l00095"></a>00095 <span class="comment">// 1.) finding blobs</span>
<a name="l00096"></a>00096 <span class="comment">// 2.) sorting blobs</span>
<a name="l00097"></a>00097 <span class="comment">// 3.) picking best two blobs</span>
<a name="l00098"></a>00098 <span class="comment">//</span>
<a name="l00099"></a>00099 <span class="comment">// and finally...</span>
<a name="l00100"></a>00100 <span class="comment">//</span>
<a name="l00101"></a>00101 <span class="comment">// 4.) desaturating the best two blobs OR desaturating the entire selected</span>
<a name="l00102"></a>00102 <span class="comment">//     region if good blobs could not be found.</span>
<a name="l00103"></a>00103 <span class="comment">//</span>
<a name="l00104"></a>00104 <span class="comment">// Under the best conditions (most cases) the algorithm finds the offending</span>
<a name="l00105"></a>00105 <span class="comment">// eyes and reduces them only. In the worst case scenario the algorithm</span>
<a name="l00106"></a>00106 <span class="comment">// applying the desaturing procedure of all thresholded pixels within the</span>
<a name="l00107"></a>00107 <span class="comment">// selected area, which is still better than other algorithms in the wild</span>
<a name="l00108"></a>00108 <span class="comment">// since we'll employ a smarter desaturating techinque, but more on that in a bit.</span>
<a name="l00109"></a>00109 <span class="comment">//</span>
<a name="l00110"></a>00110 <span class="comment">// Let's examine each step in detail:</span>
<a name="l00111"></a>00111 <span class="comment">//</span>
<a name="l00112"></a>00112 <span class="comment">// Finding Blobs:</span>
<a name="l00113"></a>00113 <span class="comment">// --------------</span>
<a name="l00114"></a>00114 <span class="comment">// The finding blobs algorithm is actually pretty straight forward.</span>
<a name="l00115"></a>00115 <span class="comment">// An initial pass over the selected region constructs a integer mask where</span>
<a name="l00116"></a>00116 <span class="comment">// 0 indicates a pixel did not met and 1 indictes a pixel that did met the </span>
<a name="l00117"></a>00117 <span class="comment">// same red threshold test we applied earlier.</span>
<a name="l00118"></a>00118 <span class="comment">//</span>
<a name="l00119"></a>00119 <span class="comment">// If the integer mask is set to 0 move on.</span>
<a name="l00120"></a>00120 <span class="comment">// If the integer mask is set to 1 assign the next unique ID, push all 8 neighbors</span>
<a name="l00121"></a>00121 <span class="comment">// that are 1's in the integer masl into a list and asssociate that pixel in </span>
<a name="l00122"></a>00122 <span class="comment">// the list with the unique ID we just set.</span>
<a name="l00123"></a>00123 <span class="comment">//</span>
<a name="l00124"></a>00124 <span class="comment">// At the top of the loop we pop pixels off the list while the list is not empty. For each</span>
<a name="l00125"></a>00125 <span class="comment">// pixel we check the current integer mask value it has. If it is 1 we set it to the </span>
<a name="l00126"></a>00126 <span class="comment">// tagged unique ID and push all it's neighbors that have 1's in the integer </span>
<a name="l00127"></a>00127 <span class="comment">// mask and move. Below is an example of what the integer mask might look like</span>
<a name="l00128"></a>00128 <span class="comment">// before and after blobs are found.</span>
<a name="l00129"></a>00129 <span class="comment">//</span>
<a name="l00130"></a>00130 <span class="comment">// 0000000000000000000      0000000000000000000</span>
<a name="l00131"></a>00131 <span class="comment">// 0011000111100000100      0022000333300000400</span>
<a name="l00132"></a>00132 <span class="comment">// 0111100000111000110  --&gt; 0222200000333000440</span>
<a name="l00133"></a>00133 <span class="comment">// 0100000000110000010      0200000000330000040</span>
<a name="l00134"></a>00134 <span class="comment">// 0000000000000000000      0000000000000000000</span>
<a name="l00135"></a>00135 <span class="comment">//</span>
<a name="l00136"></a>00136 <span class="comment">// Every time a new pixel is used to start a new blob the old</span>
<a name="l00137"></a>00137 <span class="comment">// blob and a few statistics are pushed into a list. In addition to</span>
<a name="l00138"></a>00138 <span class="comment">// knowledge of the blob ID and inherantly all tagged pixels (we keep around</span>
<a name="l00139"></a>00139 <span class="comment">// the integer mask), we also store the pixel count and the blobs aspect ratio (w/h).</span>
<a name="l00140"></a>00140 <span class="comment">// These stats are useful during the next step.</span>
<a name="l00141"></a>00141 <span class="comment">//</span>
<a name="l00142"></a>00142 <span class="comment">// Sorting Blobs:</span>
<a name="l00143"></a>00143 <span class="comment">// --------------</span>
<a name="l00144"></a>00144 <span class="comment">// At this point we've found all the above threshold blobs which consist of</span>
<a name="l00145"></a>00145 <span class="comment">// connected above threshold pixels, but it is often the case not all blobs</span>
<a name="l00146"></a>00146 <span class="comment">// are eyes. Acne, lipstick, moles, or plain old poor selection by the user, can</span>
<a name="l00147"></a>00147 <span class="comment">// result in a number of false positive blobs getting pushed into our lists.</span>
<a name="l00148"></a>00148 <span class="comment">// Fortunately, eyes are:</span>
<a name="l00149"></a>00149 <span class="comment">// -round</span>
<a name="l00150"></a>00150 <span class="comment">// -roughly the same size and shape</span>
<a name="l00151"></a>00151 <span class="comment">//</span>
<a name="l00152"></a>00152 <span class="comment">// To make actually picking blobs easier, we first sort the blob list by </span>
<a name="l00153"></a>00153 <span class="comment">// decreasing size, so the biggest ones are up front. You tend to run into a lot more</span>
<a name="l00154"></a>00154 <span class="comment">// small false positives than large ones, and the large ones tend to not be</span>
<a name="l00155"></a>00155 <span class="comment">// very round at all (like lips), so thorwing them out is a lot easier.</span>
<a name="l00156"></a>00156 <span class="comment">//</span>
<a name="l00157"></a>00157 <span class="comment">// Picking Blobs:</span>
<a name="l00158"></a>00158 <span class="comment">// --------------</span>
<a name="l00159"></a>00159 <span class="comment">// Picking the two best blobs is fairly straight forward. If only two </span>
<a name="l00160"></a>00160 <span class="comment">// blobs are found use those. If more blobs are found then start walking </span>
<a name="l00161"></a>00161 <span class="comment">// down the list of blobs starting with the largest ones. The first two </span>
<a name="l00162"></a>00162 <span class="comment">// consequtive blobls that are roughly circular (0.75 &lt; aspect ratio &lt; 2.0), </span>
<a name="l00163"></a>00163 <span class="comment">// roughly similar in shape (larger aspect ratio / smaller aspect ratio &lt; 2), </span>
<a name="l00164"></a>00164 <span class="comment">// roughly similar in size (biggerSize / smallersize &lt; 1.5), and both blobs </span>
<a name="l00165"></a>00165 <span class="comment">// meet a minimum size threshold (20 pixels) are chosen as the best two blobs.</span>
<a name="l00166"></a>00166 <span class="comment">//</span>
<a name="l00167"></a>00167 <span class="comment">// That's all just fine and dandy, but what if two blobs can't be found that</span>
<a name="l00168"></a>00168 <span class="comment">// meet those constraints? Easy, we'll work on the entire region, but usually we</span>
<a name="l00169"></a>00169 <span class="comment">// find the eyes without much trouble, while throwing out the other stuff</span>
<a name="l00170"></a>00170 <span class="comment">// like lips etc.</span>
<a name="l00171"></a>00171 <span class="comment">//</span>
<a name="l00172"></a>00172 <span class="comment">// Desaturing:</span>
<a name="l00173"></a>00173 <span class="comment">// -----------</span>
<a name="l00174"></a>00174 <span class="comment">// There are two aspects of the desaturation process that make</span>
<a name="l00175"></a>00175 <span class="comment">// the results provided by this techinque far better than most of the</span>
<a name="l00176"></a>00176 <span class="comment">// other programs out there.</span>
<a name="l00177"></a>00177 <span class="comment">//</span>
<a name="l00178"></a>00178 <span class="comment">// First, we only desaturate the red channel. A lot of programs convert</span>
<a name="l00179"></a>00179 <span class="comment">// the pixcel color to grayscale, then dim is slightly. This is bad for two</span>
<a name="l00180"></a>00180 <span class="comment">// reasons. First, you lose the true pupil color. Second, dimming the pixel</span>
<a name="l00181"></a>00181 <span class="comment">// causes you to lose the glint that often reflects off the center of the</span>
<a name="l00182"></a>00182 <span class="comment">// eyeball. Instead, we desaturate the red channel only, and instead</span>
<a name="l00183"></a>00183 <span class="comment">// of simply decreasing it, we estimate it's true value using the green and</span>
<a name="l00184"></a>00184 <span class="comment">// and blue components, which tends to look more natural:</span>
<a name="l00185"></a>00185 <span class="comment">//</span>
<a name="l00186"></a>00186 <span class="comment">// r' = 0.05*r + 0.6*g + 0.3*b</span>
<a name="l00187"></a>00187 <span class="comment">//</span>
<a name="l00188"></a>00188 <span class="comment">// The problem with directly desaturing the red channel is that you get seams at</span>
<a name="l00189"></a>00189 <span class="comment">// the blob border. To prevent seams from occuring, we blend the updated</span>
<a name="l00190"></a>00190 <span class="comment">// red channel color with the original using an alpha term based on</span>
<a name="l00191"></a>00191 <span class="comment">// the percentage of pixels within a centered 5x5 grid that were marked as</span>
<a name="l00192"></a>00192 <span class="comment">// blob pixels.</span>
<a name="l00193"></a>00193 <span class="comment">//</span>
<a name="l00194"></a>00194 <span class="comment">// The result of seamless red channel correction for the offending red eyes only.</span>
<a name="l00195"></a>00195 <span class="comment">// The glint in a persons eyes are preserved mainly because of the blob based </span>
<a name="l00196"></a>00196 <span class="comment">// approach we take (pixels in the center of a blob are not necessary tagged</span>
<a name="l00197"></a>00197 <span class="comment">// since the white glint does not pass the intial threshold test).</span>
<a name="l00198"></a>00198 <span class="comment">//</span>
<a name="l00199"></a>00199 <span class="comment">// A final note, in the situation where two good blobs could not be found</span>
<a name="l00200"></a>00200 <span class="comment">// we simply desaturate all pixels that meet the less stringent r &gt; 2*g</span>
<a name="l00201"></a>00201 <span class="comment">// test using the same r' approach techinque.</span>
<a name="l00202"></a>00202 <span class="comment">//</span>
<a name="l00203"></a>00203 <span class="comment">//----------------------------------------------</span>
<a name="l00204"></a>00204 
<a name="l00205"></a>00205 <span class="comment">//==============================================</span>
<a name="l00206"></a><a class="code" href="redEye_8h.html#9800b402cdeacfa7e0e9ec756c0b54dc">00206</a> QImage* <a class="code" href="redEye_8cpp.html#08c3ef4b07c510049d36c6b0825d2455">removeRedeyeRegions</a>( QString filename, 
<a name="l00207"></a>00207                              QPoint topLeftExtreme, QPoint bottomRightExtreme,
<a name="l00208"></a>00208                              <a class="code" href="classStatusWidget.html">StatusWidget</a>* statusWidget )
<a name="l00209"></a>00209 {
<a name="l00210"></a>00210   <span class="comment">//store handle to status widget</span>
<a name="l00211"></a>00211   <a class="code" href="redEye__internal_8h.html#65b682074aef9e63bb1dad48c3e9e9df">status</a> = statusWidget;
<a name="l00212"></a>00212   
<a name="l00213"></a>00213   <span class="comment">//load original image</span>
<a name="l00214"></a>00214   <a class="code" href="redEye__internal_8h.html#5ff9c5ed4b72841b490d7a3ce1602423">rawImage</a> = QImage( filename );
<a name="l00215"></a>00215   
<a name="l00216"></a>00216   <span class="comment">//sanity check: unable to load image</span>
<a name="l00217"></a>00217   <span class="keywordflow">if</span>(<a class="code" href="redEye__internal_8h.html#5ff9c5ed4b72841b490d7a3ce1602423">rawImage</a>.isNull()) { <span class="keywordflow">return</span> NULL; }
<a name="l00218"></a>00218 
<a name="l00219"></a>00219   <span class="comment">//convert to 32-bit depth if necessary</span>
<a name="l00220"></a>00220   <span class="keywordflow">if</span>( <a class="code" href="redEye__internal_8h.html#5ff9c5ed4b72841b490d7a3ce1602423">rawImage</a>.depth() &lt; 32 ) { <a class="code" href="redEye__internal_8h.html#5ff9c5ed4b72841b490d7a3ce1602423">rawImage</a> = <a class="code" href="redEye__internal_8h.html#5ff9c5ed4b72841b490d7a3ce1602423">rawImage</a>.convertDepth( 32, Qt::AutoColor ); }
<a name="l00221"></a>00221    
<a name="l00222"></a>00222   <span class="comment">//sanity check: make sure topLeftExtreme and bottomRightExtreme are within image boundary</span>
<a name="l00223"></a>00223   topLeftExtreme.setX( QMAX( topLeftExtreme.x(), 0 ) );
<a name="l00224"></a>00224   topLeftExtreme.setY( QMAX( topLeftExtreme.y(), 0 ) );
<a name="l00225"></a>00225   bottomRightExtreme.setX( QMIN( bottomRightExtreme.x(), <a class="code" href="redEye__internal_8h.html#5ff9c5ed4b72841b490d7a3ce1602423">rawImage</a>.width()-1 ) );
<a name="l00226"></a>00226   bottomRightExtreme.setY( QMIN( bottomRightExtreme.y(), <a class="code" href="redEye__internal_8h.html#5ff9c5ed4b72841b490d7a3ce1602423">rawImage</a>.height()-1 ) );
<a name="l00227"></a>00227 
<a name="l00228"></a>00228   <span class="comment">//setup progress bar</span>
<a name="l00229"></a>00229   QString statusMessage = qApp-&gt;translate( <span class="stringliteral">"removeRedeyeRegions"</span>, <span class="stringliteral">"Removing Red-Eye:"</span> );
<a name="l00230"></a>00230   <a class="code" href="redEye__internal_8h.html#65b682074aef9e63bb1dad48c3e9e9df">status</a>-&gt;<a class="code" href="classStatusWidget.html#57d461014070b9d651c36bd157cab9c1" title="Initializes the progress bar.">showProgressBar</a>( statusMessage, 100 );
<a name="l00231"></a>00231   qApp-&gt;processEvents();  
<a name="l00232"></a>00232   
<a name="l00233"></a>00233   <span class="comment">//update progress bar for every 1% of completion</span>
<a name="l00234"></a>00234   <a class="code" href="redEye__internal_8h.html#32598f506d413f48cda8e1c930dae6b3">updateIncrement</a> = (int) ( 0.01 * 
<a name="l00235"></a>00235                             ( bottomRightExtreme.x() - topLeftExtreme.x() + 1 ) *
<a name="l00236"></a>00236                             ( bottomRightExtreme.y() - topLeftExtreme.y() + 1 ) );
<a name="l00237"></a>00237   <a class="code" href="redEye__internal_8h.html#caa08422437cae250a76ca488cbe1567">newProgress</a> = 0;   
<a name="l00238"></a>00238 
<a name="l00239"></a>00239   <span class="comment">//find region of interest: constrain search box to boundary that actually contains red enough pixels</span>
<a name="l00240"></a>00240   <a class="code" href="redEye_8cpp.html#bf1a28f820dfa8bba3056128a76e2b31">findRegionOfInterest</a>(topLeftExtreme, bottomRightExtreme);
<a name="l00241"></a>00241 
<a name="l00242"></a>00242   <span class="comment">//if no pixels were found then immediately return a NULL pointer signaling no change</span>
<a name="l00243"></a>00243   <span class="keywordflow">if</span>(<a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.x() == -1) 
<a name="l00244"></a>00244   { 
<a name="l00245"></a>00245     <span class="comment">//hide progress bar</span>
<a name="l00246"></a>00246     <a class="code" href="redEye__internal_8h.html#65b682074aef9e63bb1dad48c3e9e9df">status</a>-&gt;<a class="code" href="classStatusWidget.html#02084869ff1c15dab4bc922a49b31808" title="Update message.">setStatus</a>( <span class="stringliteral">""</span> );
<a name="l00247"></a>00247     qApp-&gt;processEvents();
<a name="l00248"></a>00248 
<a name="l00249"></a>00249     <span class="keywordflow">return</span> NULL; 
<a name="l00250"></a>00250   }
<a name="l00251"></a>00251 
<a name="l00252"></a>00252   <span class="comment">//load an editing image</span>
<a name="l00253"></a>00253   <span class="comment">//two images mus be loaded becuase pixel values are replaced</span>
<a name="l00254"></a>00254   <span class="comment">//using a compbination of niehgbors and their own in order</span>
<a name="l00255"></a>00255   <span class="comment">//to avoid sharp lines at the edge of the saturated region</span>
<a name="l00256"></a>00256   <a class="code" href="redEye__internal_8h.html#63116a8b94b4ed0e99ddcb7f6f3bd919">editedImage</a> = <span class="keyword">new</span> QImage( filename );
<a name="l00257"></a>00257   
<a name="l00258"></a>00258   <span class="comment">//sanity check: unable to allocated edited image</span>
<a name="l00259"></a>00259   <span class="keywordflow">if</span>( <a class="code" href="redEye__internal_8h.html#63116a8b94b4ed0e99ddcb7f6f3bd919">editedImage</a> == NULL) 
<a name="l00260"></a>00260   { 
<a name="l00261"></a>00261     <span class="comment">//hide progress bar</span>
<a name="l00262"></a>00262     <a class="code" href="redEye__internal_8h.html#65b682074aef9e63bb1dad48c3e9e9df">status</a>-&gt;<a class="code" href="classStatusWidget.html#02084869ff1c15dab4bc922a49b31808" title="Update message.">setStatus</a>( <span class="stringliteral">""</span> );
<a name="l00263"></a>00263     qApp-&gt;processEvents();
<a name="l00264"></a>00264 
<a name="l00265"></a>00265     <span class="keywordflow">return</span> NULL; 
<a name="l00266"></a>00266   }
<a name="l00267"></a>00267 
<a name="l00268"></a>00268   <span class="comment">//convert to 32-bit depth if necessary</span>
<a name="l00269"></a>00269   <span class="keywordflow">if</span>( <a class="code" href="redEye__internal_8h.html#63116a8b94b4ed0e99ddcb7f6f3bd919">editedImage</a>-&gt;depth() &lt; 32 )
<a name="l00270"></a>00270   {
<a name="l00271"></a>00271     QImage* tmp = <a class="code" href="redEye__internal_8h.html#63116a8b94b4ed0e99ddcb7f6f3bd919">editedImage</a>;
<a name="l00272"></a>00272     <a class="code" href="redEye__internal_8h.html#63116a8b94b4ed0e99ddcb7f6f3bd919">editedImage</a> = <span class="keyword">new</span> QImage( tmp-&gt;convertDepth( 32, Qt::AutoColor ) );
<a name="l00273"></a>00273     <span class="keyword">delete</span> tmp; tmp=NULL;
<a name="l00274"></a>00274   }
<a name="l00275"></a>00275   
<a name="l00276"></a>00276   <a class="code" href="redEye_8cpp.html#ee8db73b8ae2738abf7e7d45530e2aea">findBlobs</a>();
<a name="l00277"></a>00277   <a class="code" href="redEye_8cpp.html#3aaacc5ca86e794b9b1eb5cbae4b33c0">sortBlobsByDecreasingSize</a>();
<a name="l00278"></a>00278   <a class="code" href="redEye_8cpp.html#7f1ea49f9377698b39bbe4c95d3dfacf">findBestTwoBlobs</a>();
<a name="l00279"></a>00279 
<a name="l00280"></a>00280   <span class="comment">//if we found two good blobs then desaturate those only</span>
<a name="l00281"></a>00281   <span class="keywordflow">if</span>(<a class="code" href="redEye__internal_8h.html#0c133898e18cb9e8871148f231b91499">id1</a> != -1)
<a name="l00282"></a>00282   {
<a name="l00283"></a>00283     <a class="code" href="redEye_8cpp.html#58dd38d7509fe0a51a8f364190018018">desaturateBlobs</a>();
<a name="l00284"></a>00284   }
<a name="l00285"></a>00285   <span class="comment">//else desaturate all pixels above thresh within selection area</span>
<a name="l00286"></a>00286   <span class="keywordflow">else</span>
<a name="l00287"></a>00287   {
<a name="l00288"></a>00288     <a class="code" href="redEye_8cpp.html#f4dcda43e955d647a9c8e1f00056a41c">desaturateEntireImage</a>(topLeftExtreme, bottomRightExtreme);
<a name="l00289"></a>00289   }
<a name="l00290"></a>00290 
<a name="l00291"></a>00291   <span class="comment">//remove status bar</span>
<a name="l00292"></a>00292   <a class="code" href="redEye__internal_8h.html#65b682074aef9e63bb1dad48c3e9e9df">status</a>-&gt;<a class="code" href="classStatusWidget.html#02084869ff1c15dab4bc922a49b31808" title="Update message.">setStatus</a>( <span class="stringliteral">""</span> );
<a name="l00293"></a>00293   qApp-&gt;processEvents();
<a name="l00294"></a>00294 
<a name="l00295"></a>00295   <span class="comment">//return pointer to edited image</span>
<a name="l00296"></a>00296   <span class="keywordflow">return</span> <a class="code" href="redEye__internal_8h.html#63116a8b94b4ed0e99ddcb7f6f3bd919">editedImage</a>;      
<a name="l00297"></a>00297 }
<a name="l00298"></a>00298 <span class="comment">//==============================================</span>
<a name="l00299"></a>00299 
<a name="l00300"></a>00300 <span class="comment">// 40 = 15.6% of red channel, a good heuristic for false positives</span>
<a name="l00301"></a>00301 <span class="comment">//at border of face on a dark background.</span>
<a name="l00302"></a><a class="code" href="redEye_8cpp.html#d7ed4710f681643ffc38eedbd4523dcc">00302</a> <span class="preprocessor">#define MIN_RED_VAL 40</span>
<a name="l00303"></a>00303 <span class="preprocessor"></span>
<a name="l00304"></a>00304 <span class="comment">//==============================================</span>
<a name="l00305"></a><a class="code" href="redEye__internal_8h.html#bf1a28f820dfa8bba3056128a76e2b31">00305</a> <span class="keywordtype">void</span> <a class="code" href="redEye_8cpp.html#bf1a28f820dfa8bba3056128a76e2b31">findRegionOfInterest</a>(QPoint topLeftExtreme, QPoint bottomRightExtreme)
<a name="l00306"></a>00306 {
<a name="l00307"></a>00307   <a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a> = QPoint(-1,-1);
<a name="l00308"></a>00308   <a class="code" href="redEye__internal_8h.html#75e80edb449bc9a0925be60719132bd0">bottomRight</a> = QPoint(-1,-1);
<a name="l00309"></a>00309   
<a name="l00310"></a>00310   <span class="keywordtype">int</span> x, y;
<a name="l00311"></a>00311   QRgb* rgb;
<a name="l00312"></a>00312   uchar* scanLine;
<a name="l00313"></a>00313   <span class="keywordflow">for</span>( y=topLeftExtreme.y(); y&lt;=bottomRightExtreme.y(); y++)
<a name="l00314"></a>00314   {
<a name="l00315"></a>00315     scanLine = <a class="code" href="redEye__internal_8h.html#5ff9c5ed4b72841b490d7a3ce1602423">rawImage</a>.scanLine(y);
<a name="l00316"></a>00316     <span class="keywordflow">for</span>( x=topLeftExtreme.x(); x&lt;=bottomRightExtreme.x(); x++)
<a name="l00317"></a>00317     {
<a name="l00318"></a>00318       rgb = ((QRgb*)scanLine+x);
<a name="l00319"></a>00319       
<a name="l00320"></a>00320       <span class="keywordtype">bool</span> threshMet = qRed(*rgb) &gt; 2*qGreen(*rgb) &amp;&amp;
<a name="l00321"></a>00321                       qRed(*rgb) &gt; <a class="code" href="redEye_8cpp.html#d7ed4710f681643ffc38eedbd4523dcc">MIN_RED_VAL</a>;
<a name="l00322"></a>00322       <span class="keywordflow">if</span>(threshMet)
<a name="l00323"></a>00323       {
<a name="l00324"></a>00324         <span class="comment">//first pixel</span>
<a name="l00325"></a>00325         <span class="keywordflow">if</span>(<a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.x() == -1) 
<a name="l00326"></a>00326         {
<a name="l00327"></a>00327           <a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a> = QPoint(x,y);
<a name="l00328"></a>00328           <a class="code" href="redEye__internal_8h.html#75e80edb449bc9a0925be60719132bd0">bottomRight</a> = QPoint(x,y);
<a name="l00329"></a>00329         }
<a name="l00330"></a>00330         
<a name="l00331"></a>00331         <span class="keywordflow">if</span>(x &lt; <a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.x() ) <a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.setX( x );
<a name="l00332"></a>00332         <span class="keywordflow">if</span>(y &lt; <a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.y() ) <a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.setY( y );
<a name="l00333"></a>00333         <span class="keywordflow">if</span>(x &gt; <a class="code" href="redEye__internal_8h.html#75e80edb449bc9a0925be60719132bd0">bottomRight</a>.x() ) <a class="code" href="redEye__internal_8h.html#75e80edb449bc9a0925be60719132bd0">bottomRight</a>.setX( x );
<a name="l00334"></a>00334         <span class="keywordflow">if</span>(y &gt; <a class="code" href="redEye__internal_8h.html#75e80edb449bc9a0925be60719132bd0">bottomRight</a>.y() ) <a class="code" href="redEye__internal_8h.html#75e80edb449bc9a0925be60719132bd0">bottomRight</a>.setY( y );
<a name="l00335"></a>00335       }
<a name="l00336"></a>00336       
<a name="l00337"></a>00337       <span class="comment">//update status bar if significant progress has been made since last update</span>
<a name="l00338"></a>00338       <a class="code" href="redEye__internal_8h.html#caa08422437cae250a76ca488cbe1567">newProgress</a>++;
<a name="l00339"></a>00339       <span class="keywordflow">if</span>(<a class="code" href="redEye__internal_8h.html#caa08422437cae250a76ca488cbe1567">newProgress</a> &gt;= <a class="code" href="redEye__internal_8h.html#32598f506d413f48cda8e1c930dae6b3">updateIncrement</a>)
<a name="l00340"></a>00340       {
<a name="l00341"></a>00341         <a class="code" href="redEye__internal_8h.html#caa08422437cae250a76ca488cbe1567">newProgress</a> = 0;
<a name="l00342"></a>00342         <a class="code" href="redEye__internal_8h.html#65b682074aef9e63bb1dad48c3e9e9df">status</a>-&gt;<a class="code" href="classStatusWidget.html#de18735223ae40506c32c96b9c9c5476" title="Updates the progress bar by one step.">incrementProgress</a>();
<a name="l00343"></a>00343         qApp-&gt;processEvents();  
<a name="l00344"></a>00344       }
<a name="l00345"></a>00345       
<a name="l00346"></a>00346     }
<a name="l00347"></a>00347   }  
<a name="l00348"></a>00348 }
<a name="l00349"></a>00349 <span class="comment">//==============================================</span>
<a name="l00350"></a><a class="code" href="redEye__internal_8h.html#53e8ae2ad8b93ea9947e891d10471862">00350</a> <span class="keywordtype">void</span> <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>(<span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y, <span class="keywordtype">int</span> <span class="keywordtype">id</span>)
<a name="l00351"></a>00351 {
<a name="l00352"></a>00352   <span class="comment">//if pixel off image or below thresh ignore push attempt</span>
<a name="l00353"></a>00353   <span class="keywordflow">if</span>(  x &lt; 0  || 
<a name="l00354"></a>00354        y &lt;  0 ||
<a name="l00355"></a>00355        x &gt;= <a class="code" href="redEye__internal_8h.html#0ec7142cbb09aaf2b806440129c0884c">regionWidth</a> ||
<a name="l00356"></a>00356        y &gt;= <a class="code" href="redEye__internal_8h.html#d61f84d3753db9df2a7ecee3c3323770">regionHeight</a> ||
<a name="l00357"></a>00357        <a class="code" href="redEye__internal_8h.html#670ca124358ed2ce8380d0b335dedda1">regionOfInterest</a>[ x + y*<a class="code" href="redEye__internal_8h.html#0ec7142cbb09aaf2b806440129c0884c">regionWidth</a> ] != 1 )
<a name="l00358"></a>00358     <span class="keywordflow">return</span>;
<a name="l00359"></a>00359   
<a name="l00360"></a>00360   <span class="comment">//passes! set id and actually put pixel onto stack</span>
<a name="l00361"></a>00361   <a class="code" href="redEye__internal_8h.html#670ca124358ed2ce8380d0b335dedda1">regionOfInterest</a>[ x + y*<a class="code" href="redEye__internal_8h.html#0ec7142cbb09aaf2b806440129c0884c">regionWidth</a>] = id;  
<a name="l00362"></a>00362   <a class="code" href="redEye__internal_8h.html#2c631e95efba7b4f9f3100c70b51dab5">spreadablePixels</a>.push( QPoint( x, y ) );
<a name="l00363"></a>00363   
<a name="l00364"></a>00364   <span class="comment">//increase blob pixel count and update topLeft and bottomRight</span>
<a name="l00365"></a>00365   <a class="code" href="redEye__internal_8h.html#9ca3db90b1887965fb41c967436c63d8">blobPixelCount</a>++;
<a name="l00366"></a>00366   <a class="code" href="redEye__internal_8h.html#8ab8b83c4822f5950cb6b7c17ce2d740">blobTopLeft</a>.setX( QMIN( x, <a class="code" href="redEye__internal_8h.html#8ab8b83c4822f5950cb6b7c17ce2d740">blobTopLeft</a>.x() ) );
<a name="l00367"></a>00367   <a class="code" href="redEye__internal_8h.html#8ab8b83c4822f5950cb6b7c17ce2d740">blobTopLeft</a>.setY( QMIN( y, <a class="code" href="redEye__internal_8h.html#8ab8b83c4822f5950cb6b7c17ce2d740">blobTopLeft</a>.y() ) );
<a name="l00368"></a>00368   <a class="code" href="redEye__internal_8h.html#d1ca7aedb85d44e293176769bdfea6c8">blobBottomRight</a>.setX( QMAX( x, <a class="code" href="redEye__internal_8h.html#d1ca7aedb85d44e293176769bdfea6c8">blobBottomRight</a>.x() ) );
<a name="l00369"></a>00369   <a class="code" href="redEye__internal_8h.html#d1ca7aedb85d44e293176769bdfea6c8">blobBottomRight</a>.setY( QMAX( y, <a class="code" href="redEye__internal_8h.html#d1ca7aedb85d44e293176769bdfea6c8">blobBottomRight</a>.y() ) );
<a name="l00370"></a>00370 }
<a name="l00371"></a>00371 <span class="comment">//==============================================</span>
<a name="l00372"></a><a class="code" href="redEye__internal_8h.html#ee8db73b8ae2738abf7e7d45530e2aea">00372</a> <span class="keywordtype">void</span> <a class="code" href="redEye_8cpp.html#ee8db73b8ae2738abf7e7d45530e2aea">findBlobs</a>()
<a name="l00373"></a>00373 {
<a name="l00374"></a>00374   <span class="comment">//create small matrix for region of interest</span>
<a name="l00375"></a>00375   <a class="code" href="redEye__internal_8h.html#0ec7142cbb09aaf2b806440129c0884c">regionWidth</a> = <a class="code" href="redEye__internal_8h.html#75e80edb449bc9a0925be60719132bd0">bottomRight</a>.x() - <a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.x() + 1;
<a name="l00376"></a>00376   <a class="code" href="redEye__internal_8h.html#d61f84d3753db9df2a7ecee3c3323770">regionHeight</a> = <a class="code" href="redEye__internal_8h.html#75e80edb449bc9a0925be60719132bd0">bottomRight</a>.y() - <a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.y() + 1;  
<a name="l00377"></a>00377   <a class="code" href="redEye__internal_8h.html#670ca124358ed2ce8380d0b335dedda1">regionOfInterest</a> = <span class="keyword">new</span> <span class="keywordtype">int</span>[ <a class="code" href="redEye__internal_8h.html#0ec7142cbb09aaf2b806440129c0884c">regionWidth</a> * <a class="code" href="redEye__internal_8h.html#d61f84d3753db9df2a7ecee3c3323770">regionHeight</a> ];
<a name="l00378"></a>00378   
<a name="l00379"></a>00379   <span class="comment">//set all pixels that meet thresh to 1, all others to 0</span>
<a name="l00380"></a>00380   <span class="keywordtype">int</span> x, y;
<a name="l00381"></a>00381   <span class="keywordtype">int</span> x2, y2;
<a name="l00382"></a>00382   QRgb* rgb;
<a name="l00383"></a>00383   uchar* scanLine;
<a name="l00384"></a>00384   <span class="keywordflow">for</span>( y=<a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.y(); y&lt;=<a class="code" href="redEye__internal_8h.html#75e80edb449bc9a0925be60719132bd0">bottomRight</a>.y(); y++)
<a name="l00385"></a>00385   {
<a name="l00386"></a>00386     y2 = y - <a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.y();
<a name="l00387"></a>00387     
<a name="l00388"></a>00388     scanLine = <a class="code" href="redEye__internal_8h.html#5ff9c5ed4b72841b490d7a3ce1602423">rawImage</a>.scanLine(y);
<a name="l00389"></a>00389     <span class="keywordflow">for</span>( x=<a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.x(); x&lt;=<a class="code" href="redEye__internal_8h.html#75e80edb449bc9a0925be60719132bd0">bottomRight</a>.x(); x++)
<a name="l00390"></a>00390     {
<a name="l00391"></a>00391     
<a name="l00392"></a>00392       x2 = x - <a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.x();
<a name="l00393"></a>00393       
<a name="l00394"></a>00394       rgb = ((QRgb*)scanLine+x);
<a name="l00395"></a>00395       
<a name="l00396"></a>00396       <span class="keywordtype">bool</span> threshMet = qRed(*rgb) &gt; 2*qGreen(*rgb) &amp;&amp;
<a name="l00397"></a>00397                        qRed(*rgb) &gt; <a class="code" href="redEye_8cpp.html#d7ed4710f681643ffc38eedbd4523dcc">MIN_RED_VAL</a>;
<a name="l00398"></a>00398       
<a name="l00399"></a>00399       <span class="keywordflow">if</span>(threshMet)
<a name="l00400"></a>00400         <a class="code" href="redEye__internal_8h.html#670ca124358ed2ce8380d0b335dedda1">regionOfInterest</a>[ x2 + y2*<a class="code" href="redEye__internal_8h.html#0ec7142cbb09aaf2b806440129c0884c">regionWidth</a> ] = 1;
<a name="l00401"></a>00401       <span class="keywordflow">else</span>
<a name="l00402"></a>00402         <a class="code" href="redEye__internal_8h.html#670ca124358ed2ce8380d0b335dedda1">regionOfInterest</a>[ x2 + y2*<a class="code" href="redEye__internal_8h.html#0ec7142cbb09aaf2b806440129c0884c">regionWidth</a> ] = 0;
<a name="l00403"></a>00403     }
<a name="l00404"></a>00404   } 
<a name="l00405"></a>00405   
<a name="l00406"></a>00406   <span class="comment">//walk over region of interest and propogate blobs</span>
<a name="l00407"></a>00407   <span class="keywordtype">int</span> nextValidID = 2;
<a name="l00408"></a>00408   <span class="keywordflow">for</span>(x = 0; x&lt;<a class="code" href="redEye__internal_8h.html#0ec7142cbb09aaf2b806440129c0884c">regionWidth</a>; x++)
<a name="l00409"></a>00409   {
<a name="l00410"></a>00410     <span class="keywordflow">for</span>(y = 0; y&lt;<a class="code" href="redEye__internal_8h.html#d61f84d3753db9df2a7ecee3c3323770">regionHeight</a>; y++)
<a name="l00411"></a>00411     {
<a name="l00412"></a>00412       <span class="comment">//if any blobs can be propogated handle them first</span>
<a name="l00413"></a>00413       <span class="keywordflow">while</span>( !<a class="code" href="redEye__internal_8h.html#2c631e95efba7b4f9f3100c70b51dab5">spreadablePixels</a>.empty() )
<a name="l00414"></a>00414       {
<a name="l00415"></a>00415         QPoint point = <a class="code" href="redEye__internal_8h.html#2c631e95efba7b4f9f3100c70b51dab5">spreadablePixels</a>.pop();
<a name="l00416"></a>00416         <span class="keywordtype">int</span> <span class="keywordtype">id</span> = <a class="code" href="redEye__internal_8h.html#670ca124358ed2ce8380d0b335dedda1">regionOfInterest</a>[ point.x() + point.y()*regionWidth ];
<a name="l00417"></a>00417         
<a name="l00418"></a>00418         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( point.x()-1, point.y()-1, id );
<a name="l00419"></a>00419         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( point.x(),   point.y()-1, id );
<a name="l00420"></a>00420         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( point.x()+1, point.y()-1, id );
<a name="l00421"></a>00421         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( point.x()-1, point.y(), id );
<a name="l00422"></a>00422         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( point.x()+1, point.y(), id );
<a name="l00423"></a>00423         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( point.x()-1, point.y()+1, id );
<a name="l00424"></a>00424         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( point.x(),   point.y()+1, id );
<a name="l00425"></a>00425         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( point.x()+1, point.y()+1, id );
<a name="l00426"></a>00426       }
<a name="l00427"></a>00427       
<a name="l00428"></a>00428       <span class="comment">//if this pixel has met thresh and has not yet been assigned a unique ID,</span>
<a name="l00429"></a>00429       <span class="comment">//assign it the next unique id and push all valid neighbors</span>
<a name="l00430"></a>00430       <span class="keywordflow">if</span>( <a class="code" href="redEye__internal_8h.html#670ca124358ed2ce8380d0b335dedda1">regionOfInterest</a>[ x + y*regionWidth ] == 1 )
<a name="l00431"></a>00431       {
<a name="l00432"></a>00432         <span class="comment">//print last blob stats</span>
<a name="l00433"></a>00433         <span class="keywordflow">if</span>( nextValidID &gt; 2)
<a name="l00434"></a>00434         {
<a name="l00435"></a>00435           <a class="code" href="redEye__internal_8h.html#f55dfde32d7c01326d7fba53fc627296">blobIDs</a>.push( (nextValidID - 1) );
<a name="l00436"></a>00436           <a class="code" href="redEye__internal_8h.html#9da65c9567b26aa798fbd74c220a6322">blobSizes</a>.push( <a class="code" href="redEye__internal_8h.html#9ca3db90b1887965fb41c967436c63d8">blobPixelCount</a> );
<a name="l00437"></a>00437           <a class="code" href="redEye__internal_8h.html#4e2f76562964b5c6e1224f547cff0be7">blobAspectRatios</a>.push( ((<span class="keywordtype">double</span>)(<a class="code" href="redEye__internal_8h.html#d1ca7aedb85d44e293176769bdfea6c8">blobBottomRight</a>.x() - <a class="code" href="redEye__internal_8h.html#8ab8b83c4822f5950cb6b7c17ce2d740">blobTopLeft</a>.x()+1)) / 
<a name="l00438"></a>00438                                           (<a class="code" href="redEye__internal_8h.html#d1ca7aedb85d44e293176769bdfea6c8">blobBottomRight</a>.y() - <a class="code" href="redEye__internal_8h.html#8ab8b83c4822f5950cb6b7c17ce2d740">blobTopLeft</a>.y()+1) );
<a name="l00439"></a>00439         }
<a name="l00440"></a>00440         
<a name="l00441"></a>00441         <a class="code" href="redEye__internal_8h.html#670ca124358ed2ce8380d0b335dedda1">regionOfInterest</a>[x + y*regionWidth] = nextValidID;
<a name="l00442"></a>00442         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( x-1, y-1, nextValidID );
<a name="l00443"></a>00443         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( x,   y-1, nextValidID );
<a name="l00444"></a>00444         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( x+1, y-1, nextValidID );
<a name="l00445"></a>00445         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( x-1, y, nextValidID );
<a name="l00446"></a>00446         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( x+1, y, nextValidID );
<a name="l00447"></a>00447         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( x-1, y+1, nextValidID );
<a name="l00448"></a>00448         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( x,   y+1, nextValidID );
<a name="l00449"></a>00449         <a class="code" href="redEye_8cpp.html#53e8ae2ad8b93ea9947e891d10471862">pushPixel</a>( x+1, y+1, nextValidID );
<a name="l00450"></a>00450         nextValidID++;        
<a name="l00451"></a>00451         
<a name="l00452"></a>00452         <a class="code" href="redEye__internal_8h.html#9ca3db90b1887965fb41c967436c63d8">blobPixelCount</a> = 1;
<a name="l00453"></a>00453         <a class="code" href="redEye__internal_8h.html#8ab8b83c4822f5950cb6b7c17ce2d740">blobTopLeft</a> = QPoint( x, y );
<a name="l00454"></a>00454         <a class="code" href="redEye__internal_8h.html#d1ca7aedb85d44e293176769bdfea6c8">blobBottomRight</a> = QPoint( x, y );
<a name="l00455"></a>00455       }
<a name="l00456"></a>00456     } <span class="comment">//y</span>
<a name="l00457"></a>00457   } <span class="comment">//x</span>
<a name="l00458"></a>00458   
<a name="l00459"></a>00459   <span class="comment">//insert last blob stats</span>
<a name="l00460"></a>00460   <span class="keywordflow">if</span>( nextValidID &gt; 2)
<a name="l00461"></a>00461   {
<a name="l00462"></a>00462     <a class="code" href="redEye__internal_8h.html#f55dfde32d7c01326d7fba53fc627296">blobIDs</a>.push( (nextValidID - 1) );
<a name="l00463"></a>00463     <a class="code" href="redEye__internal_8h.html#9da65c9567b26aa798fbd74c220a6322">blobSizes</a>.push( <a class="code" href="redEye__internal_8h.html#9ca3db90b1887965fb41c967436c63d8">blobPixelCount</a> );
<a name="l00464"></a>00464     <a class="code" href="redEye__internal_8h.html#4e2f76562964b5c6e1224f547cff0be7">blobAspectRatios</a>.push( ((<span class="keywordtype">double</span>)(<a class="code" href="redEye__internal_8h.html#d1ca7aedb85d44e293176769bdfea6c8">blobBottomRight</a>.x() - <a class="code" href="redEye__internal_8h.html#8ab8b83c4822f5950cb6b7c17ce2d740">blobTopLeft</a>.x()+1)) / (<a class="code" href="redEye__internal_8h.html#d1ca7aedb85d44e293176769bdfea6c8">blobBottomRight</a>.y() - <a class="code" href="redEye__internal_8h.html#8ab8b83c4822f5950cb6b7c17ce2d740">blobTopLeft</a>.y()+1) );
<a name="l00465"></a>00465   }
<a name="l00466"></a>00466 }
<a name="l00467"></a>00467 <span class="comment">//==============================================</span>
<a name="l00468"></a><a class="code" href="redEye__internal_8h.html#3aaacc5ca86e794b9b1eb5cbae4b33c0">00468</a> <span class="keywordtype">void</span> <a class="code" href="redEye_8cpp.html#3aaacc5ca86e794b9b1eb5cbae4b33c0">sortBlobsByDecreasingSize</a>()
<a name="l00469"></a>00469 {
<a name="l00470"></a>00470   <a class="code" href="redEye__internal_8h.html#a46d418947b61aba8afc97ea215333a6">blobCount</a> = <a class="code" href="redEye__internal_8h.html#f55dfde32d7c01326d7fba53fc627296">blobIDs</a>.count();
<a name="l00471"></a>00471   <a class="code" href="redEye__internal_8h.html#6081d5fc46a8899b4beb60b0df7dd190">ids</a> = <span class="keyword">new</span> <span class="keywordtype">int</span>[<a class="code" href="redEye__internal_8h.html#a46d418947b61aba8afc97ea215333a6">blobCount</a>];
<a name="l00472"></a>00472   <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a> = <span class="keyword">new</span> <span class="keywordtype">int</span>[<a class="code" href="redEye__internal_8h.html#a46d418947b61aba8afc97ea215333a6">blobCount</a>];
<a name="l00473"></a>00473   <a class="code" href="redEye__internal_8h.html#6cb43dbc00001c7da1b1a22be982a58a">ratios</a> = <span class="keyword">new</span> <span class="keywordtype">double</span>[<a class="code" href="redEye__internal_8h.html#a46d418947b61aba8afc97ea215333a6">blobCount</a>];
<a name="l00474"></a>00474   
<a name="l00475"></a>00475   <span class="keywordtype">int</span> i,j;
<a name="l00476"></a>00476   <span class="keywordflow">for</span>(i=0; i&lt;<a class="code" href="redEye__internal_8h.html#a46d418947b61aba8afc97ea215333a6">blobCount</a>; i++)
<a name="l00477"></a>00477   {
<a name="l00478"></a>00478     <a class="code" href="redEye__internal_8h.html#6081d5fc46a8899b4beb60b0df7dd190">ids</a>[i] = <a class="code" href="redEye__internal_8h.html#f55dfde32d7c01326d7fba53fc627296">blobIDs</a>.pop();
<a name="l00479"></a>00479     <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[i] = <a class="code" href="redEye__internal_8h.html#9da65c9567b26aa798fbd74c220a6322">blobSizes</a>.pop();
<a name="l00480"></a>00480     <a class="code" href="redEye__internal_8h.html#6cb43dbc00001c7da1b1a22be982a58a">ratios</a>[i] = <a class="code" href="redEye__internal_8h.html#4e2f76562964b5c6e1224f547cff0be7">blobAspectRatios</a>.pop();
<a name="l00481"></a>00481   }
<a name="l00482"></a>00482   
<a name="l00483"></a>00483   <span class="comment">//quick and dirty bubble sort</span>
<a name="l00484"></a>00484   <span class="keywordflow">for</span>(j = blobCount-1; j&gt;0; j--)
<a name="l00485"></a>00485   {
<a name="l00486"></a>00486     <span class="keywordflow">for</span>(i=0; i&lt;j; i++)
<a name="l00487"></a>00487     {
<a name="l00488"></a>00488       <span class="keywordflow">if</span>( <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[i+1] &gt; <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[i] )
<a name="l00489"></a>00489       {
<a name="l00490"></a>00490         <span class="keywordtype">int</span> t = <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[i+1];
<a name="l00491"></a>00491         <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[i+1] = <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[i];
<a name="l00492"></a>00492         <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[i] = t;
<a name="l00493"></a>00493         
<a name="l00494"></a>00494         t = <a class="code" href="redEye__internal_8h.html#6081d5fc46a8899b4beb60b0df7dd190">ids</a>[i+1];
<a name="l00495"></a>00495         <a class="code" href="redEye__internal_8h.html#6081d5fc46a8899b4beb60b0df7dd190">ids</a>[i+1] = <a class="code" href="redEye__internal_8h.html#6081d5fc46a8899b4beb60b0df7dd190">ids</a>[i];
<a name="l00496"></a>00496         <a class="code" href="redEye__internal_8h.html#6081d5fc46a8899b4beb60b0df7dd190">ids</a>[i] = t;
<a name="l00497"></a>00497         
<a name="l00498"></a>00498         <span class="keywordtype">double</span> tR = <a class="code" href="redEye__internal_8h.html#6cb43dbc00001c7da1b1a22be982a58a">ratios</a>[i+1];
<a name="l00499"></a>00499         <a class="code" href="redEye__internal_8h.html#6cb43dbc00001c7da1b1a22be982a58a">ratios</a>[i+1] = <a class="code" href="redEye__internal_8h.html#6cb43dbc00001c7da1b1a22be982a58a">ratios</a>[i];
<a name="l00500"></a>00500         <a class="code" href="redEye__internal_8h.html#6cb43dbc00001c7da1b1a22be982a58a">ratios</a>[i] = tR;        
<a name="l00501"></a>00501       }
<a name="l00502"></a>00502     }
<a name="l00503"></a>00503   }
<a name="l00504"></a>00504 }
<a name="l00505"></a>00505 <span class="comment">//==============================================</span>
<a name="l00506"></a><a class="code" href="redEye__internal_8h.html#7f1ea49f9377698b39bbe4c95d3dfacf">00506</a> <span class="keywordtype">void</span> <a class="code" href="redEye_8cpp.html#7f1ea49f9377698b39bbe4c95d3dfacf">findBestTwoBlobs</a>()
<a name="l00507"></a>00507 {
<a name="l00508"></a>00508   <a class="code" href="redEye__internal_8h.html#0c133898e18cb9e8871148f231b91499">id1</a> = -1;
<a name="l00509"></a>00509   <a class="code" href="redEye__internal_8h.html#bff687cb542be70b85afa82d0c3496d0">id2</a> = -1;
<a name="l00510"></a>00510   <span class="keywordtype">int</span> i;
<a name="l00511"></a>00511   
<a name="l00512"></a>00512   <span class="comment">//special case: 2 blobs found, both larger than 1 pixel</span>
<a name="l00513"></a>00513   <span class="keywordflow">if</span>(<a class="code" href="redEye__internal_8h.html#a46d418947b61aba8afc97ea215333a6">blobCount</a> == 2 &amp;&amp;
<a name="l00514"></a>00514      <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[0] &gt; 1 &amp;&amp;
<a name="l00515"></a>00515      <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[1] &gt; 1)
<a name="l00516"></a>00516   {
<a name="l00517"></a>00517     <a class="code" href="redEye__internal_8h.html#0c133898e18cb9e8871148f231b91499">id1</a> = <a class="code" href="redEye__internal_8h.html#6081d5fc46a8899b4beb60b0df7dd190">ids</a>[0];
<a name="l00518"></a>00518     <a class="code" href="redEye__internal_8h.html#bff687cb542be70b85afa82d0c3496d0">id2</a> = <a class="code" href="redEye__internal_8h.html#6081d5fc46a8899b4beb60b0df7dd190">ids</a>[1];
<a name="l00519"></a>00519   }
<a name="l00520"></a>00520   <span class="keywordflow">else</span>
<a name="l00521"></a>00521   {
<a name="l00522"></a>00522     <span class="keywordflow">for</span>(i=0; i&lt;<a class="code" href="redEye__internal_8h.html#a46d418947b61aba8afc97ea215333a6">blobCount</a>-2; i++)
<a name="l00523"></a>00523     {
<a name="l00524"></a>00524       <span class="comment">//once we hit blobs that are only one pixel large stop because they are probably just noise</span>
<a name="l00525"></a>00525       <span class="keywordflow">if</span>( <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[i+1] &lt;= 1 ) <span class="keywordflow">break</span>;
<a name="l00526"></a>00526       
<a name="l00527"></a>00527       <span class="keywordtype">double</span> as1 = <a class="code" href="redEye__internal_8h.html#6cb43dbc00001c7da1b1a22be982a58a">ratios</a>[i];
<a name="l00528"></a>00528       <span class="keywordtype">double</span> as2 = <a class="code" href="redEye__internal_8h.html#6cb43dbc00001c7da1b1a22be982a58a">ratios</a>[i+1];
<a name="l00529"></a>00529 
<a name="l00530"></a>00530       <span class="keywordflow">if</span>(as1 &lt; 1) as1 = 1.0/as1;
<a name="l00531"></a>00531       <span class="keywordflow">if</span>(as2 &lt; 1) as2 = 1.0/as2;
<a name="l00532"></a>00532       
<a name="l00533"></a>00533       <span class="keywordflow">if</span>( <span class="comment">//both blobs must be semi-circular, prefer those that are wider</span>
<a name="l00534"></a>00534           <a class="code" href="redEye__internal_8h.html#6cb43dbc00001c7da1b1a22be982a58a">ratios</a>[i] &gt; 0.75 &amp;&amp;   <a class="code" href="redEye__internal_8h.html#6cb43dbc00001c7da1b1a22be982a58a">ratios</a>[i] &lt; 2 &amp;&amp;
<a name="l00535"></a>00535           <a class="code" href="redEye__internal_8h.html#6cb43dbc00001c7da1b1a22be982a58a">ratios</a>[i+1] &gt; 0.75 &amp;&amp; <a class="code" href="redEye__internal_8h.html#6cb43dbc00001c7da1b1a22be982a58a">ratios</a>[i+1] &lt; 2 &amp;&amp;
<a name="l00536"></a>00536           <span class="comment">//both blobs must be similar in shape</span>
<a name="l00537"></a>00537           QMAX(as2,as1)/QMIN(as2,as1) &lt; 2 &amp;&amp;
<a name="l00538"></a>00538           <span class="comment">//both blobs must be similar in size</span>
<a name="l00539"></a>00539           ((<span class="keywordtype">double</span>)QMAX( <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[i], <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[i+1] )) / QMIN( <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[i], <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[i+1] ) &lt; 1.5 &amp;&amp;
<a name="l00540"></a>00540           <span class="comment">//both blobs must be above a certain thresh size, this prevents selecting blobs that are very very tiny</span>
<a name="l00541"></a>00541           <span class="comment">//if only tiny blobs are around we'll end up desaturating entire region</span>
<a name="l00542"></a>00542           QMAX( <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[i], <a class="code" href="redEye__internal_8h.html#fcc291f06aa904173ea1ada4741707f6">sizes</a>[i+1] ) &gt; 20 )
<a name="l00543"></a>00543       {
<a name="l00544"></a>00544         <a class="code" href="redEye__internal_8h.html#0c133898e18cb9e8871148f231b91499">id1</a> = <a class="code" href="redEye__internal_8h.html#6081d5fc46a8899b4beb60b0df7dd190">ids</a>[i];
<a name="l00545"></a>00545         <a class="code" href="redEye__internal_8h.html#bff687cb542be70b85afa82d0c3496d0">id2</a> = <a class="code" href="redEye__internal_8h.html#6081d5fc46a8899b4beb60b0df7dd190">ids</a>[i+1];
<a name="l00546"></a>00546         <span class="keywordflow">break</span>;
<a name="l00547"></a>00547       }    
<a name="l00548"></a>00548     }
<a name="l00549"></a>00549   }
<a name="l00550"></a>00550   
<a name="l00551"></a>00551   <span class="comment">//Comment this sectionin to see what blobs were found and selected</span>
<a name="l00552"></a>00552 <span class="comment">/* cout &lt;&lt; "-----\n";</span>
<a name="l00553"></a>00553 <span class="comment">  for(i=0; i&lt;blobCount-1; i++)</span>
<a name="l00554"></a>00554 <span class="comment">  {</span>
<a name="l00555"></a>00555 <span class="comment">    if( ids[i] == id1 || ids[i] == id2 )</span>
<a name="l00556"></a>00556 <span class="comment">      cout &lt;&lt; "---&gt;";</span>
<a name="l00557"></a>00557 <span class="comment">    cout &lt;&lt; "ID: " &lt;&lt; ids[i] &lt;&lt; "count: " &lt;&lt; sizes[i] &lt;&lt; " w:h: " &lt;&lt; ratios[i] &lt;&lt; "\n";      </span>
<a name="l00558"></a>00558 <span class="comment">  }*/</span>
<a name="l00559"></a>00559 }
<a name="l00560"></a>00560 <span class="comment">//==============================================</span>
<a name="l00561"></a><a class="code" href="redEye__internal_8h.html#996bbc1105cce6820c704c4b1174981c">00561</a> <span class="keywordtype">bool</span> <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>( <span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y)
<a name="l00562"></a>00562 {
<a name="l00563"></a>00563   <span class="keywordflow">if</span>( x &lt; <a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.x() || y &lt; <a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.y() ||
<a name="l00564"></a>00564       x &gt; <a class="code" href="redEye__internal_8h.html#75e80edb449bc9a0925be60719132bd0">bottomRight</a>.x() || y &gt; <a class="code" href="redEye__internal_8h.html#75e80edb449bc9a0925be60719132bd0">bottomRight</a>.y() )
<a name="l00565"></a>00565     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00566"></a>00566   
<a name="l00567"></a>00567   <span class="keywordtype">int</span> <a class="code" href="blur_8cpp.html#66793d4213f628c343f1b318e1026b73">regionIndex</a> = x - <a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.x() + (y-<a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.y())*<a class="code" href="redEye__internal_8h.html#0ec7142cbb09aaf2b806440129c0884c">regionWidth</a>;
<a name="l00568"></a>00568   <span class="keywordflow">return</span> ( <a class="code" href="redEye__internal_8h.html#670ca124358ed2ce8380d0b335dedda1">regionOfInterest</a>[regionIndex] == <a class="code" href="redEye__internal_8h.html#0c133898e18cb9e8871148f231b91499">id1</a> ||
<a name="l00569"></a>00569            <a class="code" href="redEye__internal_8h.html#670ca124358ed2ce8380d0b335dedda1">regionOfInterest</a>[regionIndex] == <a class="code" href="redEye__internal_8h.html#bff687cb542be70b85afa82d0c3496d0">id2</a> );
<a name="l00570"></a>00570 }
<a name="l00571"></a>00571 <span class="comment">//==============================================</span>
<a name="l00572"></a><a class="code" href="redEye__internal_8h.html#7a6d47eeb0f1fbac201599af4bda8719">00572</a> <span class="keywordtype">double</span> <a class="code" href="redEye_8cpp.html#7a6d47eeb0f1fbac201599af4bda8719">desaturateAlpha</a>(<span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y)
<a name="l00573"></a>00573 {
<a name="l00574"></a>00574   <span class="keywordtype">int</span> n = 0;
<a name="l00575"></a>00575   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x  ,y  ) ) n++;
<a name="l00576"></a>00576   
<a name="l00577"></a>00577   <span class="keywordflow">if</span>(n == 1)
<a name="l00578"></a>00578     <span class="keywordflow">return</span> 1.0;
<a name="l00579"></a>00579   
<a name="l00580"></a>00580   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x-1,y-1) ) n++;
<a name="l00581"></a>00581   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x  ,y-1) ) n++;
<a name="l00582"></a>00582   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x+1,y-1) ) n++;
<a name="l00583"></a>00583   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x-1,y  ) ) n++;
<a name="l00584"></a>00584   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x+1,y  ) ) n++;
<a name="l00585"></a>00585   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x-1,y+1) ) n++;
<a name="l00586"></a>00586   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x  ,y+1) ) n++;
<a name="l00587"></a>00587   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x+1,y+1) ) n++;
<a name="l00588"></a>00588   
<a name="l00589"></a>00589   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x-2,y-2) ) n++;
<a name="l00590"></a>00590   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x-1,y-2) ) n++;
<a name="l00591"></a>00591   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x  ,y-2) ) n++;
<a name="l00592"></a>00592   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x+1,y-2) ) n++;
<a name="l00593"></a>00593   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x+2,y-2) ) n++;
<a name="l00594"></a>00594   
<a name="l00595"></a>00595   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x-2,y-1) ) n++;
<a name="l00596"></a>00596   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x+2,y-1) ) n++;
<a name="l00597"></a>00597   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x-2,y  ) ) n++;
<a name="l00598"></a>00598   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x+2,y  ) ) n++;
<a name="l00599"></a>00599   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x-2,y+1) ) n++;
<a name="l00600"></a>00600   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x+2,y+1) ) n++;
<a name="l00601"></a>00601   
<a name="l00602"></a>00602   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x-2,y+2) ) n++;
<a name="l00603"></a>00603   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x-1,y+2) ) n++;
<a name="l00604"></a>00604   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x  ,y+2) ) n++;
<a name="l00605"></a>00605   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x+1,y+2) ) n++;
<a name="l00606"></a>00606   <span class="keywordflow">if</span>( <a class="code" href="redEye_8cpp.html#996bbc1105cce6820c704c4b1174981c">IDedPixel</a>(x+2,y+2) ) n++;
<a name="l00607"></a>00607   
<a name="l00608"></a>00608   
<a name="l00609"></a>00609   <span class="keywordflow">return</span> ((<span class="keywordtype">double</span>)n) / 25;
<a name="l00610"></a>00610 }
<a name="l00611"></a>00611 <span class="comment">//==============================================</span>
<a name="l00612"></a><a class="code" href="redEye__internal_8h.html#58dd38d7509fe0a51a8f364190018018">00612</a> <span class="keywordtype">void</span> <a class="code" href="redEye_8cpp.html#58dd38d7509fe0a51a8f364190018018">desaturateBlobs</a>()
<a name="l00613"></a>00613 {
<a name="l00614"></a>00614   <span class="comment">//desaturate bad pixels</span>
<a name="l00615"></a>00615   <span class="keywordtype">int</span> x, y;
<a name="l00616"></a>00616   <span class="keywordtype">double</span> r;
<a name="l00617"></a>00617   QRgb* rgb;
<a name="l00618"></a>00618   uchar* scanLine;
<a name="l00619"></a>00619   <span class="keywordflow">for</span>( y = QMAX( <a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.y()-1, 0); 
<a name="l00620"></a>00620        y&lt;= QMIN( <a class="code" href="redEye__internal_8h.html#75e80edb449bc9a0925be60719132bd0">bottomRight</a>.y()+1, <a class="code" href="redEye__internal_8h.html#63116a8b94b4ed0e99ddcb7f6f3bd919">editedImage</a>-&gt;height()-1 ); 
<a name="l00621"></a>00621        y++)
<a name="l00622"></a>00622   {
<a name="l00623"></a>00623     scanLine = <a class="code" href="redEye__internal_8h.html#63116a8b94b4ed0e99ddcb7f6f3bd919">editedImage</a>-&gt;scanLine(y);
<a name="l00624"></a>00624     <span class="keywordflow">for</span>( x =  QMAX( <a class="code" href="redEye__internal_8h.html#6a9aebec61b1a6732045c187a6156f4f">topLeft</a>.x()-1, 0); 
<a name="l00625"></a>00625          x &lt;= QMIN( <a class="code" href="redEye__internal_8h.html#75e80edb449bc9a0925be60719132bd0">bottomRight</a>.x()+1, <a class="code" href="redEye__internal_8h.html#63116a8b94b4ed0e99ddcb7f6f3bd919">editedImage</a>-&gt;width()-1 ); 
<a name="l00626"></a>00626          x++)
<a name="l00627"></a>00627     {      
<a name="l00628"></a>00628       <span class="keywordtype">double</span> alpha = <a class="code" href="redEye_8cpp.html#7a6d47eeb0f1fbac201599af4bda8719">desaturateAlpha</a>( x, y );
<a name="l00629"></a>00629       <span class="keywordflow">if</span>( alpha &gt; 0)
<a name="l00630"></a>00630       {
<a name="l00631"></a>00631         rgb = ((QRgb*)scanLine+x);
<a name="l00632"></a>00632         
<a name="l00633"></a>00633         r = alpha*(0.05*qRed(*rgb) + 0.6*qGreen(*rgb) + 0.3*qBlue(*rgb)) +
<a name="l00634"></a>00634           (1-alpha)*qRed(*rgb);
<a name="l00635"></a>00635         *rgb = qRgb( (<span class="keywordtype">int</span>)r,
<a name="l00636"></a>00636                      qGreen(*rgb),
<a name="l00637"></a>00637                      qBlue(*rgb) );
<a name="l00638"></a>00638       } <span class="comment">//alpha &gt; 0</span>
<a name="l00639"></a>00639     } <span class="comment">//x</span>
<a name="l00640"></a>00640   } <span class="comment">//y  </span>
<a name="l00641"></a>00641 }
<a name="l00642"></a>00642 <span class="comment">//==============================================</span>
<a name="l00643"></a><a class="code" href="redEye__internal_8h.html#f4dcda43e955d647a9c8e1f00056a41c">00643</a> <span class="keywordtype">void</span> <a class="code" href="redEye_8cpp.html#f4dcda43e955d647a9c8e1f00056a41c">desaturateEntireImage</a>(QPoint topLeftExtreme, QPoint bottomRightExtreme)
<a name="l00644"></a>00644 {
<a name="l00645"></a>00645   <span class="comment">//desaturate bad pixels</span>
<a name="l00646"></a>00646   <span class="keywordtype">int</span> x, y;
<a name="l00647"></a>00647   QRgb* rgb;
<a name="l00648"></a>00648   uchar* scanLine;
<a name="l00649"></a>00649   <span class="keywordflow">for</span>( y=topLeftExtreme.y(); y&lt;=bottomRightExtreme.y(); y++)
<a name="l00650"></a>00650   {
<a name="l00651"></a>00651     scanLine = <a class="code" href="redEye__internal_8h.html#63116a8b94b4ed0e99ddcb7f6f3bd919">editedImage</a>-&gt;scanLine(y);
<a name="l00652"></a>00652     <span class="keywordflow">for</span>( x=topLeftExtreme.x(); x&lt;=bottomRightExtreme.x(); x++)
<a name="l00653"></a>00653     {
<a name="l00654"></a>00654       rgb = ((QRgb*)scanLine+x);
<a name="l00655"></a>00655       <span class="keywordflow">if</span>( qRed(*rgb) &gt; 2*qGreen(*rgb) )
<a name="l00656"></a>00656       {
<a name="l00657"></a>00657         *rgb = qRgb( (<span class="keywordtype">int</span>) (0.05*qRed(*rgb) + 0.6*qGreen(*rgb) + 0.3*qBlue(*rgb)),
<a name="l00658"></a>00658                      qGreen(*rgb),
<a name="l00659"></a>00659                      qBlue(*rgb) );
<a name="l00660"></a>00660       } <span class="comment">// &gt; thresh</span>
<a name="l00661"></a>00661     } <span class="comment">//x</span>
<a name="l00662"></a>00662   } <span class="comment">//y</span>
<a name="l00663"></a>00663 }
<a name="l00664"></a>00664 <span class="comment">//==============================================</span>
<a name="l00665"></a>00665 
<a name="l00666"></a>00666 
<a name="l00667"></a>00667 
<a name="l00668"></a>00668 
<a name="l00669"></a>00669 
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Aug 23 02:34:27 2009 for AlbumShaper by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
</body>
</html>