def test_smooth(self): s1 = Smoother([[0, 1], [1, 0]]) s1.smooth() self.assertEqual(s1._bmp, [[0 | SE, 1 | NW | SE], [1 | NW | SE, 0 | NW]]) s2 = Smoother([[1, 0, 0], [1, 0, 0], [1, 1, 1]]) s2.smooth() self.assertEqual(s2._bmp, [[1, 0, 0], [1, 0, 0], [1, 1, 1]]) s3 = Smoother([[0, 1, 1, 0], [1, 0, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0]]) s3.smooth() self.assertEqual(s3._bmp, [[0 | SE, 1 | NW, 1 | NE, 0 | SW], [1 | NW, 0 | NW, 0 | NE, 1 | NE], [1 | SW, 0 | SW, 0 | SE, 1 | SE], [0 | NE, 1 | SW, 1 | SE, 0 | NW]])
def test_draw_black(self): s = Smoother([[0]]) pb = PathBuilder() s._draw_black(pb, 20, 30, BLACK) pb.optimize() self.assertEqual(pb.generate_paths(), [[(20, 30), (30, 30), (30, 40), (20, 40)]])
def gauss_smooth(mask, FILTER_SIZE): SIGMA = 0.3 * ( (FILTER_SIZE - 1) * 0.5 - 1) + 0.8 #0.3*(FILTER_SIZE-1) + 0.8 smoother = Smoother({'data': mask}, FILTER_SIZE, SIGMA) new_mask = smoother.get_output() return new_mask
def test_draw_white2(self): s = Smoother([[0]]) pb = PathBuilder() s._draw_white(pb, 0, 0, NW | NE | SE | SW) pb.optimize() self.assertEqual(pb.generate_paths(), [[(0, 0), (10, 0), (10, 10), (0, 10)], [(2, 5), (5, 8), (8, 5), (5, 2)]])
def test_draw_black2(self): s = Smoother([[0]]) pb = PathBuilder() s._draw_black(pb, 0, 0, BLACK | NW | NE | SE | SW) pb.optimize() self.assertEqual(pb.generate_paths(), [[(0, 3), (3, 0), (7, 0), (10, 3), (10, 7), (7, 10), (3, 10), (0, 7)]])
def test_getitem(self): s = Smoother([[0, 1], [1, 0], [1, 1]]) self.assertEqual(s.width, 2) self.assertEqual(s.height, 3) self.assertFalse(s[(0, 0)]) self.assertTrue(s[(1, 2)]) self.assertFalse(s[(1, -1)]) self.assertFalse(s[(-1, 1)]) self.assertFalse(s[(2, 1)])
def main(filepath, start, end, alpha): print(f'Start\t\n') print(f'{filepath}\t{start}\t{end}\t{alpha}') smoother = Smoother(filepath, start, end, alpha) if start is None and end is None and alpha is None: smoother.plot(isRaw=True).savefig('Raw.png') else: smoother.plot(isRaw=False, alpha=alpha, start=start, end=end).savefig( f'smoothed_from_{start}_to_{end}_with_{alpha}.png') print(f'End\t\n') return 0
def gauss_smooth(self, mask, FILTER_SIZE): ''' A tensorflow gauss smooth function. Args: mask: A 'Tensor' that to be smoothed FILTER_SIZE: Spatial size of gaussian filter Output: A gauss smoothed 'Tensor' of same size as 'mask' ''' SIGMA = 0.3 * ( (FILTER_SIZE - 1) * 0.5 - 1) + 0.8 #0.3*(FILTER_SIZE-1) + 0.8 smoother = Smoother({'data': mask}, FILTER_SIZE, SIGMA) new_mask = smoother.get_output() return new_mask
def smooth(): input_image = tf.placeholder(tf.float32, shape=[1, None, None, 3]) smoother = Smoother({'data': input_image}, FILTER_SIZE, SIGMA) smoothed_image = smoother.get_output() init = tf.global_variables_initializer() with tf.Session() as sess: sess.run(init) image = Image.open(FLAGS.image_path) image = np.array(image, dtype=np.float32) image = image.reshape((1, image.shape[0], image.shape[1], 1)) smoothed = sess.run(smoothed_image, feed_dict={image_input: image}) smoothed = smoothed / np.max(smoothed) out_image = np.squeeze(smoothed) out_image = Image.fromarray(np.squeeze(np.uint8(out_image * 255)))
def __init__( self, id, bins=[0, .25, .5, .75, 1], prob=[.25, .25, .25, .25], editable_cols=['bin-start', 'bin-end', 'pdf', 'cdf'], datatable={}, row_addable=False, scalable=False, smoother=False, *args, **kwargs ): super().__init__(id, *args, **kwargs) self.bins = bins self.prob = prob self.editable_cols = editable_cols self.datatable = datatable self.row_addable = row_addable self.scalable = scalable self.smoother = smoother # underlying distribution if using smoother self._dist = Smoother()
def test_vectorize_origin(self): s = Smoother([[0, 1], [1, 0]]) s.smooth() self.assertEqual(s.vectorize(10, -10), [[(10, 3), (23, -10), (30, -10), (30, -3), (17, 10), (10, 10)]])
def test_vectorize(self): s = Smoother([[0, 1], [1, 0]]) s.smooth() self.assertEqual(s.vectorize(), [[(0, 13), (13, 0), (20, 0), (20, 7), (7, 20), (0, 20)]])
def test_draw_white(self): s = Smoother([[0]]) pb = PathBuilder() s._draw_white(pb, 20, 30, NW) pb.optimize() self.assertEqual(pb.generate_paths(), [[(20, 30), (27, 30), (20, 37)]])
def __init__(self, priority, limit_rate_model, proxy_model): OriginalLimiter.__init__(self, priority, limit_rate_model, proxy_model) self.smooth_released = Smoother(2) self.smooth_rate_limit = Smoother(2) self.rate_set = False
def get_smoothed_sent_dist(address): sent_dist = sent_distributions.find_one({'address': address}) smitty = Smoother(sent_dist['sent_distribution'], 'total') smitty.smooth() smoothed_dist = smitty.to_objects() return smoothed_dist
def vectorize(self, smooth=True): s = Smoother(self._bitmap()) if smooth: s.smooth() return s.vectorize(MARGIN, -self.font.bdf[b'FONT_DESCENT'] * SCALE)