-
Notifications
You must be signed in to change notification settings - Fork 0
/
solaris_visualization.py
65 lines (51 loc) · 2.02 KB
/
solaris_visualization.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 27 19:14:42 2022
@author: hubert
"""
import os
import cv2
import skimage
import rasterio
import solaris as sol
import matplotlib.pyplot as plt
from utils.config import PROJECT_ROOT
from solaris.vector import mask
from rasterio.plot import show
# Get the project root directory
project_path = PROJECT_ROOT
RCNN_ROOT = os.path.abspath(project_path + "Mask_RCNN")
os.chdir(RCNN_ROOT)
print("Printing the current project root dir".format(os.getcwd()))
# input_raster = PROJECT_ROOT + "results/Data/inputs/tile_8.tif"
# predicted_raster = PROJECT_ROOT + "results/Data/predicted/tile_8b.tif"
# geo_raster = PROJECT_ROOT + "results/Data/georeferenced/tile_1.tif"
input_raster = PROJECT_ROOT + "results/Test/inputs/debi_tiguet_image.tif"
predicted_raster = PROJECT_ROOT + "results/Test/predicted/tile_4096_4096.jpg"
geo_raster = PROJECT_ROOT + "results/Test/georeferenced/debi_tiguet_image.tif"
# ref_image = skimage.io.imread(input_raster)
# geo_raster = skimage.io.imread(geo_raster)
mask_image = skimage.io.imread(geo_raster)
geoms = mask.mask_to_poly_geojson(mask_image, channel_scaling=[1, -1, -1])
# # f, ax = plt.subplots(figsize=(10, 8))
# # plt.imshow(mask_image)
# # plt.show()
# fig, (axr, axg, axl) = plt.subplots(1, 3, figsize=(25, 9))
# ref_image = ref_image.swapaxes(2, 0)
# ref_image = ref_image.swapaxes(2, 1)
# show(ref_image, ax=axr, title="Testing Image")
# show(geo_raster, ax=axg, title="Pred. without Smooth Blending")
# mask_image = mask_image.swapaxes(2, 0)
# mask_image = mask_image.swapaxes(2, 1)
# show(mask_image, ax=axl, title="Pred. with Smooth Blending")
# plt.show()
# Revert the mask to the original crs and affine tranformation for matching.
# result_polys = sol.vector.polygon.georegister_px_df(
# geoms, affine_obj=ref_image.transform, crs=ref_image.crs
# )
# unary_union(result_polys['geometry'])
geoms = sol.vector.mask.mask_to_poly_geojson(mask_image, channel_scaling=[1, -1, -1])
f, ax = plt.subplots(figsize=(10, 8))
plt.imshow(mask_image)
plt.show()