31 #include <gsl/gsl_rng.h>
40 CentroidApolloPan::CentroidApolloPan(
double pixelSizeMicrons)
42 if( pixelSizeMicrons > 0)
43 this->m_pixelSize = pixelSizeMicrons;
45 this->m_pixelSize = 5.0;
48 CentroidApolloPan::~CentroidApolloPan(){};
50 bool CentroidApolloPan::setPixelSize(
double microns)
52 if( microns <= 0)
return false;
53 this->m_pixelSize = microns;
57 int CentroidApolloPan::selectAdaptive(Chip *inputChip,Chip *selectionChip) {
73 double minDN,maxDN,temp;
77 lines = inputChip->Lines();
78 samples = inputChip->Samples();
81 if (lines <= 0 || samples <= 0)
85 minDN = this->getMinDN();
86 maxDN = this->getMaxDN();
89 for (i=1;i<=lines;i++) {
90 if (i == 1 || i == lines) {
96 for(j=1;j<=samples;j+=step) {
97 dn.push_back(inputChip->GetValue(j,i));
107 for (k=1;k<int(dn.size());k++) {
114 if (i <
int(j/10)) dn.erase(dn.begin()+l);
118 if( temp > minDN) this->setDNRange(temp,maxDN);
122 this->select(inputChip,selectionChip);
124 this->setDNRange(minDN,maxDN);
130 int CentroidApolloPan::elipticalReduction(
Chip *selectionChip,
double percent_selected,
double play,
int patience_limit)
158 std::vector< std::vector<int> > pts;
159 std::vector< std::vector<double> > cen_pts;
161 std::vector<double> pt(2);
165 double a = 60.0*5.0/m_pixelSize,
166 b = 60.0*5.0/m_pixelSize,
170 gsl_rng *randGen = gsl_rng_alloc(gsl_rng_taus);
171 gsl_rng_set(randGen, time(NULL));
173 samples = selectionChip->
Samples();
174 lines = selectionChip->
Lines();
178 k = int(ceil(
double(samples) - a));
179 l = int(ceil(
double(lines ) - b));
185 double searchStep = 5.0*5.0/m_pixelSize;
186 double aSearch,centerSample,centerLine,delta,cSearch;
187 cSearch = searchStep/5.0;
188 centerSample = double((k+i)/2.0);
189 centerLine = double((l+j)/2.0);
190 delta = (centerSample-double(i))*(centerSample-
double(i)) + (centerLine -
double(l))*(centerLine -
double(l));
192 aSearch = (searchStep-cSearch)/delta;
194 for (pt[0]=floor(a+1.0); pt[0]<k; pt[0]+=searchStep) {
195 for (pt[1]=floor(b+1.0); pt[1]<l; pt[1]+=searchStep) {
196 cen_pts.push_back(pt);
197 delta = (centerSample-double(pt[0]))*(centerSample-
double(pt[0])) + (centerLine-
double(pt[1]))*(centerLine-
double(pt[1]));
198 searchStep = aSearch*delta + cSearch;
199 if (searchStep > l - pt[1] && l - pt[1] > 1e-4)
200 searchStep = l - pt[1];
202 if (searchStep > k - pt[0] && k - pt[0] > 1e-4)
203 searchStep = k - pt[0];
207 selectionEdge(selectionChip,&pts);
210 if (pts.size() ==0)
return 0;
215 while (emptySets < patience_limit && cen_pts.size()>0) {
218 randPt = gsl_rng_uniform_int( randGen ,cen_pts.size() );
219 dpt[0] = cen_pts[randPt][0];
220 dpt[1] = cen_pts[randPt][1];
222 cen_pts.erase( cen_pts.begin() + randPt);
225 ellipseFromCenterAxesAngle(&ellNew, dpt[0], dpt[1], a, b, 0.0);
229 if (!bestFitEllipse(&ellNew, &pts, play, 50)) {
235 if (ellNew.area < ellBest.area) {
240 if (!ellipseInChip(&ellNew,selectionChip)) {
246 if (elipsePercentSelected(selectionChip,&ellNew) < percent_selected) {
254 ellBest.area = ellNew.area;
255 ellBest.A[0] = ellNew.A[0];
256 ellBest.A[1] = ellNew.A[1];
257 ellBest.A[2] = ellNew.A[2];
259 ellBest.cen[0] = ellNew.cen[0];
260 ellBest.cen[1] = ellNew.cen[1];
262 ellBest.semiMajor = ellNew.semiMajor;
263 ellBest.semiMinor = ellNew.semiMinor;
264 ellBest.majorAxis[0] = ellNew.majorAxis[0];
265 ellBest.majorAxis[1] = ellNew.majorAxis[1];
266 ellBest.minorAxis[0] = ellNew.minorAxis[0];
267 ellBest.minorAxis[1] = ellNew.minorAxis[1];
270 if( ellBest.area == 0)
276 for (i=1;i<=samples;i++) {
277 for (j=1;j<=lines;j++) {
281 if (!pointInEllipse(&ellBest,dpt,play)) {
282 if( selectionChip->
GetValue(i,j) == 1)
A small chip of data used for pattern matching.
int Samples() const
Return the number of samples in the chip.
void SetValue(int sample, int line, const double &value)
Sets a value in the chip.
int Lines() const
Return the number of lines in the chip.
double GetValue(int sample, int line)
Loads a Chip with a value.