Optimize remove_trees
|
Before Width: | Height: | Size: 370 B After Width: | Height: | Size: 368 B |
|
Before Width: | Height: | Size: 379 B After Width: | Height: | Size: 421 B |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 962 B After Width: | Height: | Size: 910 B |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 962 B After Width: | Height: | Size: 912 B |
|
Before Width: | Height: | Size: 899 B After Width: | Height: | Size: 136 B |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 102 B After Width: | Height: | Size: 86 B |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 8.5 KiB |
@@ -31,11 +31,8 @@ def remove_trees(heightmap: Union[str, Image], treesmap: Union[str, Image], mask
|
||||
if mask.getpixel((x, z)) != 0 and treesmap.getpixel((x, z)) > 0:
|
||||
|
||||
tree_area = morphology.flood(treesmap, (z, x), tolerance=1)
|
||||
blend = img.blend(img.fromarray(tree_area).convert(
|
||||
'L'), removed_treesmap.convert('L'), 0.5)
|
||||
array = np.array(blend.convert('L'))
|
||||
bool_array = array > 1
|
||||
removed_treesmap = img.fromarray(bool_array)
|
||||
removed_treesmap = img.fromarray(
|
||||
np.where(tree_area, treesmap, 0).astype(np.uint8))
|
||||
|
||||
y = heightmap.getpixel((x, z))
|
||||
y_top = removed_treesmap.getpixel((x, z))
|
||||
|
||||