Beispiel #1
0
def kernelSmoothing(x, X, Y, weightFunc, halfwidth):
    '''Returns the smoothed estimate of (X,Y) at x
    Sum_x weight(sample_x,x) * y(x)'''
    from numpy import zeros, array
    weights = array([weightFunc(x,observedx, halfwidth) for observedx in X])
    if sum(weights)>0:
        return sum(weights*Y)/sum(weights)
    else:
        return 0
    def getMask(self):
        try:
            values = [int(val.get()) for val in self.maskVar]
        except ValueError:  #AKTUALNIE NIE POTRZEBNE BO POLA SĄ READONLY
            return None

        mask = reshape(values, (3, 3))
        if all(mask == 0):
            return None
        else:
            if sum(mask) != 0:
                mask = int64(mask) / sum(mask)

            return mask
Beispiel #3
0
 def var(self, mean = None):
     if not mean:
         m = self.mean()
     else:
         m = mean
     result = 0.
     squares = [float((x-m)*(x-m)*y) for x,y in zip(self.categories, self.counts)]
     return sum(squares)/(self.nSamples()-1)
Beispiel #4
0
    def get_probability_label(self, label):
        try:
            return self.prob_labels[label]
        except Exception:
            self.prob_labels = {}
            self.prob_labels[AFTER] = self.sum_histogram[
                "((u'AFTER', u'BEFORE'), u'AFTER')"]
            self.prob_labels[BEFORE] = self.sum_histogram[
                "((u'AFTER', u'BEFORE'), u'BEFORE')"]
            self.prob_labels[SIMULTANEOUS] = self.sum_histogram[
                "((u'SIMULTANEOUS', u'BEFORE'), u'SIMULTANEOUS')"]

            prob_labels_sum = sum(self.prob_labels.values())
            for key in self.prob_labels:
                self.prob_labels[key] = float(
                    self.prob_labels[key]) / prob_labels_sum
            return self.prob_labels[label]
Beispiel #5
0
    def computeTranslation(img1,
                           img2,
                           img1Points,
                           maxTranslation2,
                           minNMatches,
                           windowSize=(5, 5),
                           level=5,
                           criteria=(cv2.TERM_CRITERIA_EPS, 0, 0.01)):
        '''Computes the translation of img2 with respect to img1
        (loaded using OpenCV as numpy arrays)
        img1Points are used to compute the translation

        TODO add diagnostic if data is all over the place, and it most likely is not a translation (eg zoom, other non linear distortion)'''
        from numpy.core.multiarray import array
        from numpy.lib.function_base import median
        from numpy.core.fromnumeric import sum

        nextPoints = array([])
        (img2Points, status,
         track_error) = cv2.calcOpticalFlowPyrLK(img1,
                                                 img2,
                                                 img1Points,
                                                 nextPoints,
                                                 winSize=windowSize,
                                                 maxLevel=level,
                                                 criteria=criteria)
        # calcOpticalFlowPyrLK(prevImg, nextImg, prevPts[, nextPts[, status[, err[, winSize[, maxLevel[, criteria[, derivLambda[, flags]]]]]]]]) -> nextPts, status, err
        delta = []
        for (k, (p1, p2)) in enumerate(zip(img1Points, img2Points)):
            if status[k] == 1:
                dp = p2 - p1
                d = sum(dp**2)
                if d < maxTranslation2:
                    delta.append(dp)
        if len(delta) >= minNMatches:
            return median(delta, axis=0)
        else:
            print(dp)
            return None
Beispiel #6
0
 def referenceCounts(self, probability):
     '''probability is a function that returns the probability of the random variable for the category values'''
     refProba = [probability(c) for c in self.categories]
     refProba[-1] = 1-sum(refProba[:-1])
     refCounts = [r*self.nSamples() for r in refProba]
     return refCounts, refProba
Beispiel #7
0
 def mean(self):
     result = [float(x*y) for x,y in zip(self.categories, self.counts)]
     return sum(result)/self.nSamples()
Beispiel #8
0
 def nSamples(self):
     return sum(self.counts)