Computes and stores the average and current value
| 112 | |
| 113 | |
| 114 | class AverageMeter(object): |
| 115 | """Computes and stores the average and current value""" |
| 116 | def __init__(self): |
| 117 | self.initialized = False |
| 118 | self.val = None |
| 119 | self.avg = None |
| 120 | self.sum = None |
| 121 | self.count = None |
| 122 | |
| 123 | def initialize(self, val, count, weight): |
| 124 | self.val = val |
| 125 | self.avg = val |
| 126 | self.count = count |
| 127 | self.sum = val * weight |
| 128 | self.initialized = True |
| 129 | |
| 130 | def update(self, val, count=1, weight=1): |
| 131 | if not self.initialized: |
| 132 | self.initialize(val, count, weight) |
| 133 | else: |
| 134 | self.add(val, count, weight) |
| 135 | |
| 136 | def add(self, val, count, weight): |
| 137 | self.val = val |
| 138 | self.count += count |
| 139 | self.sum += val * weight |
| 140 | self.avg = self.sum / self.count |
| 141 | |
| 142 | def value(self): |
| 143 | return self.val |
| 144 | |
| 145 | def average(self): |
| 146 | return self.avg |
| 147 | |
| 148 | def ImageValStretch2D(img): |
| 149 | img = img*255 |