Change filters

This commit is contained in:
2024-06-24 17:38:48 +02:00
parent 0872cb1901
commit 5576a8810c
16 changed files with 47 additions and 16 deletions

12
main.py
View File

@@ -26,13 +26,13 @@ def main():
abs(buildArea.begin.z - buildArea.end.z) / 2) abs(buildArea.begin.z - buildArea.end.z) / 2)
length_world = sqrt((center[0]*2) ** 2 + (center[1]*2) ** 2) length_world = sqrt((center[0]*2) ** 2 + (center[1]*2) ** 2)
# remove_trees('./world_maker/data/heightmap.png', './world_maker/data/treemap.png', remove_trees('./world_maker/data/heightmap.png', './world_maker/data/treemap.png',
# './world_maker/data/smooth_sobel_watermap.png') './world_maker/data/smooth_sobel_watermap.png')
# smooth_terrain('./world_maker/data/heightmap.png', smooth_terrain('./world_maker/data/heightmap.png',
# './world_maker/data/heightmap_smooth.png', './world_maker/data/smooth_sobel_watermap.png') './world_maker/data/heightmap_smooth.png', './world_maker/data/smooth_sobel_watermap.png')
# set_roads(skeleton_highway, origin) set_roads(skeleton_highway, origin)
# set_roads(skeleton_mountain, origin) set_roads(skeleton_mountain, origin)
# set_roads_grids(road_grid, origin) # set_roads_grids(road_grid, origin)
# roads.setRoads(skeleton_mountain) # roads.setRoads(skeleton_mountain)
# roads.setRoads(skeleton_highway) # roads.setRoads(skeleton_highway)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 717 B

After

Width:  |  Height:  |  Size: 963 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -229,19 +229,50 @@ def highway_map() -> Image.Image:
negative_smooth_sobel_water = subtract_map( negative_smooth_sobel_water = subtract_map(
negative_smooth_sobel, './world_maker/data/watermap.png') negative_smooth_sobel, './world_maker/data/watermap.png')
array_sobel_water = np.array(negative_smooth_sobel_water) array_sobel_water = np.array(negative_smooth_sobel_water)
# Remove details
array_sobel_water = ndimage.binary_erosion( array_sobel_water = ndimage.binary_erosion(
array_sobel_water, iterations=12) array_sobel_water, iterations=5)
# Smooth non buildable area
array_sobel_water = filter_negative(
filter_smooth_array(np.array(filter_negative(array_sobel_water)), 2))
array_sobel_water = np.array(array_sobel_water)
# Propagate buildable area
array_sobel_water = ndimage.binary_dilation( array_sobel_water = ndimage.binary_dilation(
array_sobel_water, iterations=5) array_sobel_water, iterations=5)
array_sobel_water = filter_smooth_array(array_sobel_water, 5)
# Smooth buildable area
array_sobel_water = filter_smooth_array(array_sobel_water, 2)
array_sobel_water = np.array(array_sobel_water)
# Smooth non buildable area
array_sobel_water = filter_negative(
filter_smooth_array(np.array(filter_negative(array_sobel_water)), 1))
array_sobel_water = np.array(array_sobel_water)
# Erode buildable area
array_sobel_water = ndimage.binary_erosion( array_sobel_water = ndimage.binary_erosion(
array_sobel_water, iterations=20) array_sobel_water, iterations=12)
array_sobel_water = filter_smooth_array(array_sobel_water, 6)
# Dilate buildable area
array_sobel_water = ndimage.binary_dilation(
array_sobel_water, iterations=7)
# Smooth buildable area
array_sobel_water = filter_smooth_array(array_sobel_water, 20)
array_sobel_water = np.array(array_sobel_water)
image = Image.fromarray(array_sobel_water) image = Image.fromarray(array_sobel_water)
image_no_details = filter_remove_details(image, 15) image.save('./world_maker/data/smooth_for_highway.png')
image_no_details.save('./world_maker/data/highwaymap.png')
# Remove details
# image_no_details = filter_remove_details(image, 10)
# image_no_details.save('./world_maker/data/highwaymap.png')
print("[Data Analysis] Highway map generated.") print("[Data Analysis] Highway map generated.")
return image_no_details return image
def create_volume(surface: np.ndarray, heightmap: np.ndarray, make_it_flat: bool = False) -> np.ndarray: def create_volume(surface: np.ndarray, heightmap: np.ndarray, make_it_flat: bool = False) -> np.ndarray:

View File

@@ -9,10 +9,10 @@ from world_maker.pack_rectangle import generate_building
def world_maker(): def world_maker():
# world = World() world = World()
# heightmap, watermap, treemap = get_data(world) heightmap, watermap, treemap = get_data(world)
heightmap, watermap, treemap = get_data_no_update() # heightmap, watermap, treemap = get_data_no_update()
filter_sobel( filter_sobel(
"./world_maker/data/heightmap.png").save('./world_maker/data/sobelmap.png') "./world_maker/data/heightmap.png").save('./world_maker/data/sobelmap.png')