예제 #1
0
파일: mspec.py 프로젝트: zhangxl2000/pycmac
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)
예제 #2
0
파일: mspec.py 프로젝트: zhangxl2000/pycmac
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
예제 #3
0
    def save_capture_as_reflectance_stack(self,
                                          outfilename,
                                          irradiance_list=None,
                                          warp_matrices=None,
                                          normalize=False):
        from osgeo.gdal import GetDriverByName, GDT_UInt16
        self.compute_reflectance(irradiance_list)
        if warp_matrices is None:
            warp_matrices = self.get_warp_matrices()
        cropped_dimensions, edges = imageutils.find_crop_bounds(
            self, warp_matrices)
        im_aligned = imageutils.aligned_capture(self,
                                                warp_matrices,
                                                cv2.MOTION_HOMOGRAPHY,
                                                cropped_dimensions,
                                                None,
                                                img_type="reflectance")

        rows, cols, bands = im_aligned.shape
        driver = GetDriverByName('GTiff')
        outRaster = driver.Create(outfilename, cols, rows, bands, GDT_UInt16)
        if outRaster is None:
            raise IOError("could not load gdal GeoTiff driver")
        for i in range(0, 5):
            outband = outRaster.GetRasterBand(i + 1)
            outdata = im_aligned[:, :, i]
            outdata[outdata < 0] = 0
            outdata[outdata > 1] = 1
            outband.WriteArray(outdata * 32768)
            outband.FlushCache()

        if bands == 6:
            outband = outRaster.GetRasterBand(6)
            outdata = (
                im_aligned[:, :, 5] + 273.15
            ) * 100  # scale data from float degC to back to centi-Kelvin to fit into uint16
            outdata[outdata < 0] = 0
            outdata[outdata > 65535] = 65535
            outband.WriteArray(outdata)
            outband.FlushCache()
        outRaster = None
예제 #4
0
파일: mspec.py 프로젝트: Ciaran1981/pycmac
def _proc_stack(i, warp_matrices, bndFolders, panel_irradiance, reflFolder,
                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,
                                                            warp_mode=warp_md)

    im_aligned = imageutils.aligned_capture(i,
                                            warp_matrices,
                                            cropped_dimensions,
                                            warp_md,
                                            match_index=rf,
                                            img_type="reflectance")

    im_display = np.zeros((im_aligned.shape[0], im_aligned.shape[1], 5),
                          dtype=np.float32)

    rows, cols, bands = im_display.shape
    #    driver = gdal.GetDriverByName('GTiff')

    im = i.images[1].path
    hd, nm = os.path.split(im[:-6])

    filename = os.path.join(reflFolder,
                            nm + '.tif')  #blue,green,red,nir,redEdge
    #

    #    outRaster = driver.Create(filename, cols, rows, 5, gdal.GDT_Byte)
    #    normalize = False

    # Output a 'stack' in the same band order as RedEdge/Alutm
    # Blue,Green,Red,NIR,RedEdge[,Thermal]

    # NOTE: NIR and RedEdge are not in wavelength order!

    i.compute_reflectance(panel_irradiance + [0])

    i.save_capture_as_reflectance_stack(filename, normalize=True)

    #    for i in range(0,5):
    #        outband = outRaster.GetRasterBand(i+1)
    #        if normalize:
    #            outband.WriteArray(imageutils.normalize(im_aligned[:,:,i])*65535)
    #        else:
    #            outdata = im_aligned[:,:,i]
    #            outdata[outdata<0] = 0
    #            outdata[outdata>1] = 1
    #
    #            outband.WriteArray(outdata*65535)
    #        outband.FlushCache()
    #
    #    if im_aligned.shape[2] == 6:
    #        outband = outRaster.GetRasterBand(6)
    #        outdata = im_aligned[:,:,5] * 100 # scale to centi-C to fit into uint16
    #        outdata[outdata<0] = 0
    #        outdata[outdata>65535] = 65535
    #        outband.WriteArray(outdata)
    #        outband.FlushCache()
    #    outRaster = None

    cmd = [
        "exiftool", "-tagsFromFile", im, "-file:all", "-iptc:all", "-exif:all",
        "-xmp", "-Composite:all", filename, "-overwrite_original"
    ]
    call(cmd)
예제 #5
0
파일: mspec.py 프로젝트: Ciaran1981/pycmac
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  #,