def main(image_files, output_folder, exposure_times, resize=False): """ Generate an HDR from the images in the source folder """ image_files = sorted(image_files) # Print the information associated with each image -- use this # to verify that the correct exposure time is associated with each # image, or else you will get very poor results print "{:^30} {:>15}".format("Filename", "Exposure Time") print "\n".join([ "{:>30} {:^15.4f}".format(*v) for v in zip(image_files, exposure_times) ]) img_stack = [ cv2.imread(name) for name in image_files if path.splitext(name)[-1][1:].lower() in EXTENSIONS ] if not all(img_stack): raise RuntimeError("One or more input files failed to load.") # Subsampling the images can reduce runtime for large files if resize: img_stack = [img[::4, ::4] for img in img_stack] log_exposure_times = np.log(exposure_times) hdr_image = a9.computeHDR(img_stack, log_exposure_times) cv2.imwrite(path.join(output_folder, "output.png"), hdr_image) print "Done!"
print "getYXLocations testing passed." return True if __name__ == "__main__": print "Performing unit test." if not test_normalizeImage(): print "normalizeImage function failed. Halting testing." sys.exit() if not test_linearWeight(): print "linearWeight function failed. Halting testing." sys.exit() if not test_getYXLocations(): print "getYXLocations function failed. Halting testing." sys.exit() print "Unit tests passed." print "We do not run a unit test for computeResponseCurve so make sure " + \ "you look at the HDR output (or see why the function isn't " + \ "running) to assess your progress." image_dir = "input" output_dir = "output" exposure_times = np.float64( [1 / 160.0, 1 / 125.0, 1 / 80.0, 1 / 60.0, 1 / 40.0, 1 / 15.0]) log_exposure_times = np.log(exposure_times) np.random.seed() hdr = assignment9.computeHDR(image_dir, log_exposure_times) cv2.imwrite(output_dir + "/hdr.jpg", hdr)
if not test_linearWeight(): print "linearWeight function failed. Halting testing." sys.exit() if not test_sampleIntensities(): print "sampleIntensities function. Halting testing." sys.exit() if not test_computeResponseCurve(): print "computeResponseCurve function failed. Halting testing." sys.exit() if not test_computeRadianceMap(): print "ccomputeRadianceMap function failed. Halting testing." sys.exit() print "Unit tests passed." print "Generating HDR from sample images. (This may take a while.)" image_dir = "input" output_dir = "output" exposure_times = np.float64( [1 / 160.0, 1 / 125.0, 1 / 80.0, 1 / 60.0, 1 / 40.0, 1 / 15.0]) log_exposure_times = np.log(exposure_times) np.random.seed() small_images = assignment9.readImages(image_dir) hdr = assignment9.computeHDR(small_images, log_exposure_times) print u"Expected avg pixel value for the test images is 125\u00B1" + u"1.", print "Your value was {}.".format(int(np.average(hdr))) if not (124 <= int(np.average(hdr)) <= 126): print "Please check your code for errors and inspect your output." cv2.imwrite(output_dir + "/hdr.jpg", hdr)
print "We do not run a unit test for computeResponseCurve so make sure " + \ "you look at the HDR output (or see why the function isn't " + \ "running) to assess your progress." parser = argparse.ArgumentParser(description='Create an HDR image from an input directory of images.') parser.add_argument('--input', help='directory where the input images are stored', action='store', dest="input") parser.add_argument('--output', help='path to the output file', action='store', dest="output") args = parser.parse_args() #exposure_times = np.float64(exposures(args.input)) exposure_times = np.float64([1/2.0, 2.0, 8.0]) log_exposure_times = np.log(exposure_times) np.random.seed() hdr = assignment9.computeHDR(args.input, log_exposure_times) cv2.imwrite(args.output, hdr) #hdr = cv2.cvtColor(hdr, cv2.COLOR_BGR2RGB) #h, w = hdr.shape[:2] #app = wx.App() #frame = MyFrame(title="HDR Image") #panel = wx.Panel(frame) #image = wx.ImageFromBuffer(w, h, hdr) #bitmap = wx.StaticBitmap(panel, -1, wx.BitmapFromImage(image)) #frame.SetClientSize(bitmap.GetSize()) #frame.Show() #app.MainLoop()
np.testing.assert_array_equal(y_locs, y_ans) np.testing.assert_array_equal(x_locs, x_ans) print "getYXLocations testing passed." return True if __name__ == "__main__": print "Performing unit test." if not test_normalizeImage(): print "normalizeImage function failed. Halting testing." sys.exit() if not test_linearWeight(): print "linearWeight function failed. Halting testing." sys.exit() if not test_getYXLocations(): print "getYXLocations function failed. Halting testing." sys.exit() print "Unit tests passed." print "We do not run a unit test for computeResponseCurve so make sure " + "you look at the HDR output (or see why the function isn't " + "running) to assess your progress." image_dir = "input" output_dir = "output" exposure_times = np.float64([1 / 160.0, 1 / 125.0, 1 / 80.0, 1 / 60.0, 1 / 40.0, 1 / 15.0]) log_exposure_times = np.log(exposure_times) np.random.seed() hdr = assignment9.computeHDR(image_dir, log_exposure_times) cv2.imwrite(output_dir + "/hdr.jpg", hdr)