                         
                         if !isMaxima { continue }
                         let idx   = index(r,green:g,blue:b)
-                        let r     = cell.reds/cell.count
-                        let g     = cell.greens/cell.count
-                        let b     = cell.blues/cell.count
+                        let r     = cell.reds/cell.count/Float(kIMP_HistogramSize-1)
+                        let g     = cell.greens/cell.count/Float(kIMP_HistogramSize-1)
+                        let b     = cell.blues/cell.count/Float(kIMP_HistogramSize-1)
                         let brightnes = max(max(r, g), b)
                         let local = LocalMaximum(count: Int(count), index: idx, color: float3(r,g,b), brightnes: brightnes)
 

        get{
            var v = [float3]()
            for lm in self{
                v.append(lm.color/255)
            }
            return v
        }

            
            var filtered = maxima
            var temp     = [LocalMaximum]()
            var threshold = Float(0.1)
            
            for var k = 0 ; k<10 ; k++ {
                temp = distinctMaxima(filtered, threshold: threshold)
                if temp.count <= count {
                    break
                }
                filtered = temp
                threshold += 0.05
            }
            
            return [LocalMaximum](filtered[0..<count])
