public static double fraction( GrowQueue_F64 list , double fraction ) { int k = (int)((list.size-1)*fraction+0.5); return QuickSelect.select(list.data,k,list.size); } }
@Override public int select(double[] variance) { // invert so that the largest variances will be at the bottom for( int i = 0; i < N; i++ ) variance[i] = -variance[i]; // find the largest ones QuickSelect.selectIndex(variance, actualConsiderSplit-1,N,indexes); // select on of the largests return indexes[ rand.nextInt(actualConsiderSplit) ]; } }
public static double fraction( GrowQueue_F64 list , double fraction ) { int k = (int)((list.size-1)*fraction+0.5); return QuickSelect.select(list.data,k,list.size); } }
@Override public int select(double[] variance) { // invert so that the largest variances will be at the bottom for( int i = 0; i < N; i++ ) variance[i] = -variance[i]; // find the largest ones QuickSelect.selectIndex(variance, actualConsiderSplit-1,N,indexes); // select on of the largests return indexes[ rand.nextInt(actualConsiderSplit) ]; } }
/** * Uses quick-select to find the median value */ private void quickSelect(List<P> points, int splitAxis, int medianNum) { int numPoints = points.size(); if( tmp.length < numPoints ) { tmp = new double[numPoints]; indexes = new int[ numPoints ]; } for( int i = 0; i < numPoints; i++ ) { tmp[i] = distance.valueAt(points.get(i),splitAxis); } QuickSelect.selectIndex(tmp, medianNum, numPoints, indexes); } }
/** * <p> * Robust median estimator of the noise standard deviation. Typically applied to the HH<sub>1</sub> subband. * </p> * * <p> * σ = Median(|Y<sub>ij</sub>|)/0.6745<br> * where σ is the estimated noise standard deviation, and Median(|Y<sub>ij</sub>|) * is the median absolute value of all the pixels in the subband. * </p> * * <p> * D. L. Donoho and I. M. Johnstone, "Ideal spatial adaption via wavelet shrinkage." * Biometrika, vol 81, pp. 425-455, 1994 * </p> * * @param subband The subband the image is being computed from. Not modified. * @param storage Used to temporarily store the absolute value of each element in the subband. * @return estimated noise variance. */ public static float estimateNoiseStdDev(GrayF32 subband , float storage[] ) { storage = subbandAbsVal(subband, storage ); int N = subband.width*subband.height; return QuickSelect.select(storage, N / 2, N)/0.6745f; }
/** * Uses quick-select to find the median value */ private void quickSelect(List<P> points, int splitAxis, int medianNum) { int numPoints = points.size(); if( tmp.length < numPoints ) { tmp = new double[numPoints]; indexes = new int[ numPoints ]; } for( int i = 0; i < numPoints; i++ ) { tmp[i] = distance.valueAt(points.get(i),splitAxis); } QuickSelect.selectIndex(tmp, medianNum, numPoints, indexes); } }
float median = QuickSelect.select(storage,index/2,index); output.set(x,y, median );
private void computeInlierSet(List<Point> dataSet, int n) { int numPts = (int)(n *inlierFrac); if( inlierFrac > 0 && numPts > sampleSize ) { inlierSet.clear(); errorMetric.setModel(bestParam); errorMetric.computeDistance(dataSet,errors); int []indexes = new int[n]; QuickSelect.selectIndex(errors,numPts, n,indexes); for( int i = 0; i < numPts; i++ ) { int origIndex = indexes[i]; inlierSet.add( dataSet.get(origIndex) ); matchToInput[i] = origIndex; } } else { inlierSet = dataSet; } }
int median = QuickSelect.select(storage, index / 2, index); output.set(x,y, median );
private void computeInlierSet(List<Point> dataSet, int n) { int numPts = (int)(n *inlierFrac); if( inlierFrac > 0 && numPts > sampleSize ) { inlierSet.clear(); errorMetric.setModel(bestParam); errorMetric.computeDistance(dataSet,errors); int []indexes = new int[n]; QuickSelect.selectIndex(errors,numPts, n,indexes); for( int i = 0; i < numPts; i++ ) { int origIndex = indexes[i]; inlierSet.add( dataSet.get(origIndex) ); matchToInput[i] = origIndex; } } else { inlierSet = dataSet; } }
errorMetric.computeDistance(_dataSet,errors); double median = QuickSelect.select(errors, (int)(N*errorFraction+0.5), N);
/** * compute the probability that each region is the target conditional upon this image * the sumP and sumN are needed for image conditional probability * * NOTE: This is a big change from the original paper */ protected void selectBestRegionsFern(double totalP, double totalN) { for( int i = 0; i < fernInfo.size; i++ ) { TldRegionFernInfo info = fernInfo.get(i); double probP = info.sumP/totalP; double probN = info.sumN/totalN; // only consider regions with a higher P likelihood if( probP > probN ) { // reward regions with a large difference between the P and N values storageMetric.add(-(probP-probN)); storageRect.add( info.r ); } } // Select the N regions with the highest fern probability if( config.maximumCascadeConsider < storageMetric.size ) { int N = Math.min(config.maximumCascadeConsider, storageMetric.size); storageIndexes.resize(storageMetric.size); QuickSelect.selectIndex(storageMetric.data, N - 1, storageMetric.size, storageIndexes.data); for( int i = 0; i < N; i++ ) { fernRegions.add(storageRect.get(storageIndexes.get(i))); } } else { fernRegions.addAll(storageRect); } }
errorMetric.computeDistance(_dataSet,errors); double median = QuickSelect.select(errors, (int)(N*errorFraction+0.5), N);
@Override public void process(GrayU8 gray) { detector.process(gray); synchronized ( lockGui ) { List<FiducialDetector.Detected> found = detector.getDetected(); // Select the largest quadrilaterals if( found.size() <= detected.length ) { numDetected = found.size(); for (int i = 0; i < numDetected; i++) { detected[i].binary.setTo(found.get(i).binary); detected[i].location.set(found.get(i).location); } } else { indexes.resize( found.size() ); area.resize( found.size()); for (int i = 0; i < found.size(); i++) { area.set(i, -Area2D_F64.quadrilateral(found.get(i).location)); } QuickSelect.selectIndex(area.data, detected.length, found.size(), indexes.data); numDetected = detected.length; for (int i = 0; i < numDetected; i++) { int index = indexes.data[i]; detected[i].binary.setTo(found.get(index).binary); detected[i].location.set(found.get(index).location); } } } }
float median = QuickSelect.select(storage, index / 2, index); output.set(x,y, median ); float median = QuickSelect.select(storage,index/2,index); output.set(x,y, median ); float median = QuickSelect.select(storage,index/2,index); output.set(x,y, median ); float median = QuickSelect.select(storage,index/2,index); output.set(x,y, median );
private static List<double[]> findNeighbors( List<double[]> data , double[]target , double maxDistance , int maxN ) { List<double[]> ret = new ArrayList<double[]>(); List<double[]> found = new ArrayList<double[]>(); GrowQueue_F64 distances = new GrowQueue_F64(); GrowQueue_I32 indexes = new GrowQueue_I32(); for( int i = 0; i < data.size(); i++ ) { double[] d = data.get(i); double dx = d[0] - target[0]; double dy = d[1] - target[1]; double dist = dx*dx + dy*dy; if( dist <= maxDistance ) { distances.add(dist); found.add(d); } } indexes.resize(distances.size); maxN = Math.min(maxN,distances.size); QuickSelect.selectIndex(distances.data,maxN,distances.size,indexes.data); for( int i = 0; i < maxN; i++ ) { ret.add( found.get( indexes.data[i])); } return ret; }
int median = QuickSelect.select(storage,index/2,index); output.set(x,y, median ); int median = QuickSelect.select(storage,index/2,index); output.set(x,y, median ); int median = QuickSelect.select(storage,index/2,index); output.set(x,y, median ); int median = QuickSelect.select(storage,index/2,index); output.set(x,y, median );
/** * Select the two lines with the greatest change in Y and the closest to the bottom */ private void selectRoadLines() { LineSegment2D_I32 a,b; if( candidates.size == 2 ) { a = candidates.get( 0 ); b = candidates.get( 1 ); } else { double score[] = new double[ candidates.size ]; int indexes[] = new int[ score.length ]; for( int i = 0; i < score.length; i++ ) { LineSegment2D_I32 l = candidates.get(i); int maxY = Math.max(l.a.y , l.b.y); score[i] = -(Math.abs(l.a.y - l.b.y));// - (labeled.height - maxY)); } QuickSelect.selectIndex(score,2,score.length,indexes); a = candidates.get( indexes[0] ); b = candidates.get( indexes[1] ); } if( bottomX(a) < bottomX(b) ) { left = a; right = b; } else { left = b; right = a; } }