def test_stress(self): London = range(1000, 2000) Stockholm = range(2000, 3000) IL = [] generate = lambda z:str(London[int(1000 * random.random())]) + " " + \ str(Stockholm[int(1000 * random.random())]) for i in range(2800): new = generate([]) while new in IL: new = generate([]) IL.append(new) bilateral.bilateral(IL)
def test_basic(): expected = np.array([[ 7, 7, 7, 8, 8], [ 9, 9, 9, 10, 10], [11, 11, 12, 12, 12], [13, 13, 14, 14, 14], [15, 15, 16, 16, 16]]) out = bilateral.bilateral(np.arange(25).reshape((5,5)), 4, 10) print out print expected assert_array_almost_equal(out, expected) return out, expected
def start(self): sigma = defaultSigma radius = defaultRadius try: sigma = int(self.lineEditSigma.text()) radius = int(self.lineEditRadius.text()) except ValueError: print("Invalid value") return image_bil = bilateral(self.image, sigma, radius) self.labelBilateral.setPixmap(QtGui.QPixmap.fromImage(image_bil)) self.labelBilateral.setScaledContents(True)
name, ext = os.path.splitext(filename) img = hist_eq(image) os.makedirs('CE/HE', exist_ok=True) cv2.imwrite('CE/HE/%s.png' % name, img) elif (sys.argv[1] == 'denoise'): if (sys.argv[2] == 'bilateral'): for image in sys.argv[3:]: filename = os.path.basename(image) name, ext = os.path.splitext(filename) img = bilateral(image) os.makedirs('denoise/bilateral', exist_ok=True) cv2.imwrite('denoise/bilateral/%s.png' % name, img) if (sys.argv[2] == 'gaussian'): for image in sys.argv[3:]: filename = os.path.basename(image) name, ext = os.path.splitext(filename) img = gaussian(image) os.makedirs('denoise/gaussian', exist_ok=True)
def checkAns(self, expectedAns, inputList): actualAns = bilateral.bilateral(inputList) self.assertEqual(len(expectedAns), len(actualAns)) self.assertTrue(all(map(lambda x: x in expectedAns, actualAns))) return actualAns
import sys from gradient import gradient from nonmax import nonmax from canny import canny from bilateral import bilateral if __name__ == '__main__': if len(sys.argv) < 5: print('Usage: python main.py (command) [parameters...] (input_image) (output_image) \n\ commands: \n\ canny (sigma) (thr_high) (thr_low) \n\ dir (sigma) \n\ nonmax (sigma) \n\ bilateral (sigma_d) (sigma_r)') sys.exit(0) input_image = np.float64(imread(sys.argv[-2])) / 255. output_image = sys.argv[-1] command = sys.argv[1] if command == 'dir': _, directions = gradient(input_image, float(sys.argv[2])) imsave(output_image, directions) elif command == 'nonmax': imsave(output_image, nonmax(input_image, float(sys.argv[2]))) elif command == 'canny': imsave(output_image, canny(input_image, float(sys.argv[2]), float(sys.argv[4]), float(sys.argv[3]))) elif command == 'bilateral': imsave(output_image, bilateral(input_image, np.float64(sys.argv[2]), np.float64(sys.argv[3]) / 255))