Last active
December 15, 2015 14:39
-
-
Save danking/5276541 to your computer and use it in GitHub Desktop.
scala shit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def dominantOri(hist: Histogram) = { | |
| hist.reduceLeft ( _ max _ ) | |
| } | |
| def goodOriFeatures(hist: Histogram, magThr: Double, feat: Feature) = { | |
| val n = hist.length | |
| def isGoodP(i: Int) = { | |
| val l = if (i == 0) n - 1 else i - 1 | |
| val r = (i + 1) % n | |
| hist(i) > hist(l) && hist(i) > hist(r) && hist(i) >= magThr | |
| } | |
| for(i <- 0 until n | |
| if isGoodP(i)) yield { | |
| val l = if (i == 0) n - 1 else i - 1 | |
| val r = (i + 1) % n | |
| val bin = i + interpHistPeak( hist(l), hist(i), hist(r) ) | |
| val bin2 = { | |
| if ( bin < 0 ) n + bin | |
| else if ( bin >= n ) bin - n | |
| else bin } | |
| val ori = ((Math.PI * 2 * bin) / n) - Math.PI | |
| Feature(feat.dd, feat.x, feat.y, feat.scl, ori) | |
| } | |
| } | |
| def normalizeDescr(descr: Histogram) = { | |
| val lenSq = descr foldLeft(0)((x y) => x*x + y) | |
| val ledInv = 1.0 / Math.sqrt(lenSq) | |
| feat.descr map (x => x * lenInv) | |
| } | |
| def featureCmp(f1: Feature, f2: Feature) = { | |
| if (f1.scl < f2.scl) | |
| 1 | |
| else if (f1.scl > f2.scl) | |
| -1 | |
| else | |
| 0 | |
| } | |
| def histToDescr(hist: Histogram, d: Int, n: Int, feat: Feature) = { | |
| val flat = hist.flatMap(x => x).flatMap(x => x).flatMap(x => x) | |
| val normed1 = normalizeDescr(flat) | |
| val clipped = normed1.map(x => { if( x > SIFT_DESCR_MAG_THR ) | |
| SIFT_DESCR_MAG_THR}) | |
| val normed2 = normalizeDescr(clipTop) | |
| val intHist = normed2.map(x => min(255, (x * SiftIntDescrFctr).toInt)) | |
| Feature(feat.dd, feat.x, feat.y, feat.scl, feat.ori, intHist) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment