Esempio n. 1
0
def get_centerline(B3, B6, size):
    """
    Using RivaMap library finds the largest centerline from
    Bands 3 and 6 lansat 8 imagery
    """
    I1 = preprocess.mndwi(B3, B6)
    filters = singularity_index.SingularityIndexFilters()
    psi, widthMap, orient = singularity_index.applyMMSI(I1, filters)
    nms = delineate.extractCenterlines(orient, psi)

    return delineate.getBiggestCenterline(nms, size)
Esempio n. 2
0
def test_applyMMSI_scales():
    '''
    Testing with more than just 1 scale size
    '''
    t_input = np.array([[20,20,50,20,20],[20,20,55,20,20],[20,20,50,20,20]], dtype='uint8')
    filts = singularity_index.SingularityIndexFilters(nrScales=2)
    [psi, widthMap, orient] = singularity_index.applyMMSI(t_input,filts)
    # expect max response in the center
    psi_max = np.max(psi)
    psi_bool = psi==psi_max
    # make assertion
    assert psi_bool[1,2] == True
Esempio n. 3
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'))
Esempio n. 4
0
#You can download the example images from AWS:
#http://landsat-pds.s3.amazonaws.com/L8/138/045/LC81380452015067LGN00/LC81380452015067LGN00_B3.TIF
#http://landsat-pds.s3.amazonaws.com/L8/138/045/LC81380452015067LGN00/LC81380452015067LGN00_B6.TIF

# Read bands 3 and 6 of an example Landsat 8 image
B3 = cv2.imread("LC81380452015067LGN00_B3.TIF", cv2.IMREAD_UNCHANGED)
B6 = cv2.imread("LC81380452015067LGN00_B6.TIF", cv2.IMREAD_UNCHANGED)

# Compute the modified normalized difference water index of the input
I1 = preprocess.mndwi(B3, B6)

# Create the filters that are needed to compute the singularity index
filters = singularity_index.SingularityIndexFilters()

# Compute the modified multiscale singularity index
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
Esempio n. 5
0
#prints names of files being used
for infile in B3s:
    print infile
for infile in B6s:
    print infile

# 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)
Esempio n. 6
0
#You can download the example images from AWS:
#http://landsat-pds.s3.amazonaws.com/L8/138/045/LC81380452015067LGN00/LC81380452015067LGN00_B3.TIF
#http://landsat-pds.s3.amazonaws.com/L8/138/045/LC81380452015067LGN00/LC81380452015067LGN00_B6.TIF

# Read bands 3 and 6 of an example Landsat 8 image
B3 = cv2.imread("LC81380452015067LGN00_B3.TIF", cv2.IMREAD_UNCHANGED)
B6 = cv2.imread("LC81380452015067LGN00_B6.TIF", cv2.IMREAD_UNCHANGED)

# Compute the modified normalized difference water index of the input
I1 = preprocess.mndwi(B3, B6)

# Create the filters that are needed to compute the singularity index
filters = singularity_index.SingularityIndexFilters()

# Compute the modified multiscale singularity index
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