예제 #1
0
# Lib to import our accidents data
import db_helper

# Find the current working directory
path = os.getcwd()

# Grab path to figures folder
if os.path.isdir(os.path.join(path, 'Figures')) == False:
    raise Exception('Figures directory does not exist, run retrieve script')
figures_dir_path = os.path.join(path, 'Figures')

# Path to our imagery
src_path = os.path.join(figures_dir_path, 'kandahar-compressed.tif')

# load
satdat = imagery_helper.load(src_path)

################################################################################
#                                                                              #
#                  Loading a sample the processed incidents                    #
#                                                                              #
################################################################################

# set crs
crs = '4326'

# Load the data
df = db_helper.get_incidents(OFFSET=0, LIMIT=10000, CRS=crs, CONTAINED=True)

# Keep certain columns
df = df.loc[:, ['geometry', 'bbox']]
예제 #2
0
path = os.getcwd()

# Grab path to figures folder
if os.path.isdir(os.path.join(path, 'Figures')) == False:
    raise Exception('Figures directory does not exist, run retrieve script')
figures_dir_path = os.path.join(path, 'Figures')

# Path to our imagery
src_path = os.path.join(figures_dir_path, 'kandahar-compressed.tif')
process_path = os.path.join(figures_dir_path,
                            'kandahar-compressed-with-incidents.tif')
out_path = os.path.join(figures_dir_path,
                        'kandahar-compressed-with-incidents.png')

# load
satdat = imagery_helper.load(src_path)

# read all bands from source dataset into a single ndarray
bands = satdat.read()


def scale(band):
    if (np.max(band) > 255):
        band = np.round((band / 10000.0) * 255.0)  # scale to 0 - 255
        band[band > 255] = 255  # if above set to max
    return band


# scale each band
for i, band in enumerate(bands):
    bands[i] = scale(band).astype(np.uint8)
예제 #3
0
################################################################################

# list of imagey
imagery_paths = [os.path.join(figures_dir_path, 'kandahar-compressed.tif')]

# init imagery dict
imagery_dict = []

# go through
for imagery_path in imagery_paths:

    # grab filename
    filename = os.path.basename(imagery_path)

    # load using rasterio
    satdat = imagery_helper.load(imagery_path)

    # parse crs
    crs = str(satdat.read_crs()).split(':')[-1]

    # grab meta data
    metadata = dict(**satdat.profile)

    # convert to json
    metadata.update(crs=crs, transform=list(metadata["transform"]))
    info = json.dumps(metadata)

    # Get bounds, in map units
    bound_left = satdat.bounds.left
    bound_right = satdat.bounds.right
    bound_top = satdat.bounds.top
out_path = os.path.join(figures_dir_path, 'opencv-processed.tif')

# load image with opencv
img = cv.imread(src_path)

# Grab dimensions of image
height, width, _ = img.shape

# convert to grayscale
img_gray = cv.cvtColor(img, cv.COLOR_RGB2GRAY)

# process
img_hist = cv.equalizeHist(img_gray)
edges = cv.Canny(cv.GaussianBlur(img_hist, ksize=(5,5), sigmaX=1, sigmaY=1), 0.1*1024, 0.25*1024)

# resize
resize_ratio = 10.0
resized_img = opencv_helper.resize(edges, int(width/resize_ratio), int(height/resize_ratio))

# show
opencv_helper.show(resized_img)

# write
cv.imwrite(out_path, resized_img)

# check vals
imagery_helper.info(imagery_helper.load(out_path))

# print
print(f'Processing done, file can be found {out_path}')