Ejemplo n.º 1
0
def batch_compute(landsat_images):

    print len(landsat_images)

    filters = singularity_index.SingularityIndexFilters(minScale=1.2, nrScales=14)

    for landsat_image in landsat_images:

        temp_dir = os.path.join(save_dir, 'temp')
        if not os.path.exists(temp_dir):
            os.makedirs(temp_dir)

        with zipfile.ZipFile(landsat_image) as zf:
            for zippedname in zf.namelist():
                if zippedname.endswith('.tif'):
                    zf.extract(zippedname, path = temp_dir)
                    temp_im_dir = os.path.join(temp_dir, zippedname)

        I1 = cv2.imread(temp_im_dir, cv2.IMREAD_UNCHANGED)
        gm = georef.loadGeoMetadata(temp_im_dir)

        #delete the temp file
        os.remove(temp_im_dir)

        psi, widthMap, orient = singularity_index.applyMMSI(I1, filters)

        nms = delineate.extractCenterlines(orient, psi)
        centerlines = delineate.thresholdCenterlines(nms, tLow=0.012, tHigh=0.11)

        # remove the overlapping response
        numRow, numCol = centerlines.shape
        padRow = numRow/10
        padCol = numCol/10
        centerlines[0:padRow, :] = 0
        centerlines[:, 0:padCol] = 0
        centerlines[-padRow:, :] = 0
        centerlines[:, -padCol:] = 0

        #save results
        wrsname = ntpath.basename(landsat_image)
        georef.exportCSVfile(orient, psi, centerlines, widthMap, gm, os.path.join(save_dir, wrsname[:-4] + '.csv'))
Ejemplo n.º 2
0
centerlines = delineate.thresholdCenterlines(nms)

# Generate a raster map of the extracted channels
raster = visualization.generateRasterMap(centerlines, orient, widthMap)

# Generate a vector map of the extracted channels
visualization.generateVectorMap(centerlines,
                                orient,
                                widthMap,
                                saveDest="vector.pdf")

# Generate a quiver plot
visualization.quiverPlot(psi, orient, saveDest="quiver.pdf")

# Save the images that are created at the intermediate steps
cv2.imwrite("mndwi.TIF", cv2.normalize(I1, None, 0, 255, cv2.NORM_MINMAX))
cv2.imwrite("psi.TIF", cv2.normalize(psi, None, 0, 255, cv2.NORM_MINMAX))
cv2.imwrite("nms.TIF", cv2.normalize(nms, None, 0, 255, cv2.NORM_MINMAX))
cv2.imwrite("centerlines.TIF", centerlines.astype(int) * 255)
cv2.imwrite("rasterMap.TIF",
            cv2.normalize(raster, None, 0, 255, cv2.NORM_MINMAX))

# An example of exporting a geotiff file
gm = georef.loadGeoMetadata("LC81380452015067LGN00_B3.TIF")
psi = preprocess.contrastStretch(psi)
psi = preprocess.double2im(psi, 'uint16')
georef.saveAsGeoTiff(gm, psi, "psi_geotagged.TIF")

# Export the (coordinate, width) pairs to a comma separated text file
georef.exportCSVfile(centerlines, widthMap, gm, "results.csv")
Ejemplo n.º 3
0
# channel response change
for i in range(0, len(B3s)):
    print(i)
    filters = singularity_index.SingularityIndexFilters()
    B3 = cv2.imread(B3s[i], cv2.IMREAD_UNCHANGED)
    B6 = cv2.imread(B6s[i], cv2.IMREAD_UNCHANGED)
    I1 = preprocess.mndwi(B3, B6)
    psi, widthMap, orient = singularity_index.applyMMSI(I1,
                                                        filters,
                                                        togglePolarity=False)
    nms = delineate.extractCenterlines(orient, psi)
    centerlines = delineate.thresholdCenterlines(nms)

    print("creating files")
    gm = georef.loadGeoMetadata(B3s[i])
    base = os.path.basename(B3s[i])
    georef.exportCSVfile(centerlines, widthMap, gm,
                         str(base) + "_geo_points.csv")

    psi = preprocess.contrastStretch(psi)
    psi = preprocess.double2im(psi, 'uint16')
    georef.saveAsGeoTiff(gm, psi, str(base) + "_geo_psi.TIF")

    mndwi = preprocess.contrastStretch(I1)
    mndwi = preprocess.double2im(mndwi, 'uint16')
    georef.saveAsGeoTiff(gm, mndwi, str(base) + "_geo_mndwi.TIF")
    #optional other file format
    #cv2.imwrite("MNDWI.TIF", cv2.normalize(I1, None, 0, 255, cv2.NORM_MINMAX))

    centerlines = preprocess.contrastStretch(centerlines)
Ejemplo n.º 4
0
psi, widthMap, orient = singularity_index.applyMMSI(I1, filters)

# Extract channel centerlines
nms = delineate.extractCenterlines(orient, psi)
centerlines = delineate.thresholdCenterlines(nms)

# Generate a raster map of the extracted channels
raster = visualization.generateRasterMap(centerlines, orient, widthMap)

# Generate a vector map of the extracted channels
visualization.generateVectorMap(centerlines, orient, widthMap, saveDest = "vector.pdf")

# Generate a quiver plot
visualization.quiverPlot(psi, orient, saveDest = "quiver.pdf")

# Save the images that are created at the intermediate steps
cv2.imwrite("mndwi.TIF", cv2.normalize(I1, None, 0, 255, cv2.NORM_MINMAX))
cv2.imwrite("psi.TIF", cv2.normalize(psi, None, 0, 255, cv2.NORM_MINMAX))
cv2.imwrite("nms.TIF", cv2.normalize(nms, None, 0, 255, cv2.NORM_MINMAX))
cv2.imwrite("centerlines.TIF", centerlines.astype(int)*255)
cv2.imwrite("rasterMap.TIF", cv2.normalize(raster, None, 0, 255, cv2.NORM_MINMAX))

# An example of exporting a geotiff file
gm = georef.loadGeoMetadata("LC81380452015067LGN00_B3.TIF")
psi = preprocess.contrastStretch(psi)
psi = preprocess.double2im(psi, 'uint16')
georef.saveAsGeoTiff(gm, psi, "psi_geotagged.TIF")

# Export the (coordinate, width) pairs to a comma separated text file
georef.exportCSVfile(centerlines, widthMap, gm, "results.csv")