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)
def test_extractCenterlines(): ''' Unit test for extractCenterlines function ''' psi = np.zeros((5,5)) orient = np.zeros((5,5)) # put some values in dummy psi psi[:,2] = 1 # expect max values in interior to be held nms = delineate.extractCenterlines(orient,psi) # make assertion assert np.all(nms[1:4,2]) == np.all(psi[1:4,2])
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'))
# 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
# 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 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))