def _proc_imgs(i, warp_matrices, bndFolders, panel_irradiance, warp_md, normalize=None): # for i in imgset.captures: i.compute_reflectance(irradiance_list=panel_irradiance) #i.plot_undistorted_reflectance(panel_irradiance) cropped_dimensions, edges = imageutils.find_crop_bounds(i, warp_matrices, warp_mode=warp_md) im_aligned = imageutils.aligned_capture(i, warp_matrices, warp_md, cropped_dimensions, None, img_type="reflectance") im_display = np.zeros((im_aligned.shape[0],im_aligned.shape[1],5), dtype=np.float32 ) for iM in range(0,im_aligned.shape[2]): im_display[:,:,iM] = imageutils.normalize(im_aligned[:,:,iM])*65535 for k in range(0,im_display.shape[2]): im = i.images[k] hd, nm = os.path.split(im.path) outdata = im_aligned[:,:,i] outdata[outdata<0] = 0 outdata[outdata>1] = 1 outfile = os.path.join(bndFolders[k], nm) imageio.imwrite(outfile, outdata) cmd = ["exiftool", "-tagsFromFile", im.path, "-file:all", "-iptc:all", "-exif:all", "-xmp", "-Composite:all", outfile, "-overwrite_original"] call(cmd)
def align_template(imAl, mx, reflFolder, rf, plots, warp_md): warp_matrices, alignment_pairs = imageutils.align_capture(imAl, ref_index=rf, warp_mode=warp_md, max_iterations=mx) for x,mat in enumerate(warp_matrices): print("Band {}:\n{}".format(x,mat)) # cropped_dimensions is of the form: # (first column with overlapping pixels present in all images, # first row with overlapping pixels present in all images, # number of columns with overlapping pixels in all images, # number of rows with overlapping pixels in all images ) dist_coeffs = [] cam_mats = [] # create lists of the distortion coefficients and camera matricies for i,img in enumerate(imAl.images): dist_coeffs.append(img.cv2_distortion_coeff()) cam_mats.append(img.cv2_camera_matrix()) #warp_mode = cv2.MOTION_HOMOGRAPHY #alignment_pairs[0]['warp_mode'] match_index = rf#alignment_pairs[0]['ref_index'] cropped_dimensions, edges = imageutils.find_crop_bounds(imAl, warp_matrices, warp_mode=warp_md) # capture, warp_matrices, cv2.MOTION_HOMOGRAPHY, cropped_dimensions, None, img_type="reflectance", im_aligned = imageutils.aligned_capture(imAl, warp_matrices, warp_md, cropped_dimensions, match_index, img_type="reflectance") im_display = np.zeros((im_aligned.shape[0],im_aligned.shape[1],5), dtype=np.float32 ) for iM in range(0,im_aligned.shape[2]): im_display[:,:,iM] = imageutils.normalize(im_aligned[:,:,iM]) rgb = im_display[:,:,[2,1,0]] cir = im_display[:,:,[3,2,1]] grRE = im_display[:,:,[4,2,1]] prevList = [rgb, cir, grRE] nmList = ['rgb.jpg', 'cir.jpg', 'grRE.jpg'] ootF, _ = os.path.split(reflFolder) names = [os.path.join(ootF, pv) for pv in nmList] for ind, p in enumerate(prevList): #img8 = bytescale(p) imgre = exposure.rescale_intensity(p) with warnings.catch_warnings(): warnings.simplefilter("ignore") img8 = util.img_as_ubyte(imgre) imageio.imwrite(names[ind], img8) return warp_matrices, alignment_pairs, rgb, cir, grRE#, dist_coeffs, cam_mats, cropped_dimensions
def _proc_imgs_comp(i, warp_matrices, bndFolders, panel_irradiance, warp_md, rf): i.compute_reflectance(irradiance_list=panel_irradiance) #i.plot_undistorted_reflectance(panel_irradiance) cropped_dimensions, edges = imageutils.find_crop_bounds(i, warp_matrices) im_aligned = imageutils.aligned_capture(i, warp_matrices, warp_md, cropped_dimensions, match_index=rf, img_type="reflectance") im_display = np.zeros((im_aligned.shape[0], im_aligned.shape[1], 5), dtype=np.float32) for iM in range(0, im_aligned.shape[2]): im_display[:, :, iM] = imageutils.normalize(im_aligned[:, :, iM]) * 32768 rgb = im_display[:, :, [2, 1, 0]] #cir = im_display[:,:,[3,2,1]] RRENir = im_display[:, :, [4, 3, 2]] # cir = im_display[:,:,[3,2,1]] # # grRE = im_display[:,:,[4,2,1]] # # imoot = [rgb, RRENir] del im_display imtags = ["RGB.tif", "RRENir.tif"] #, "GRNir.tif", "GRRE.tif"] im = i.images[1] hd, nm = os.path.split(im.path[:-6]) #cmdList = [] def _writeim(image, folder, nametag, im): #for ind, k in enumerate(bndFolders): #img8 = bytescale(imoot[ind]) #imgre = exposure.rescale_intensity(image, out_range='uint16') #with warnings.catch_warnings(): #warnings.simplefilter("ignore") img16 = np.uint16(np.round(image, decimals=0)) del image outFile = os.path.join(folder, nm + '.tif') #imageio.imwrite(outfile, img8) #imOut = Image.fromarray(img16) #imOut.save(outFile) imageio.imwrite(outFile, img16) del img16 cmd = [ "exiftool", "-tagsFromFile", im.path, "-file:all", "-iptc:all", "-exif:all", "-xmp", "-Composite:all", outFile, "-overwrite_original" ] call(cmd) _writeim(rgb, bndFolders[0], imtags[0], im) del rgb _writeim(RRENir, bndFolders[1], imtags[1], im) del RRENir #,