diff --git a/world_maker/data/heightmap.png b/world_maker/data/heightmap.png index 91a6780..a743f15 100644 Binary files a/world_maker/data/heightmap.png and b/world_maker/data/heightmap.png differ diff --git a/world_maker/data/highwaymap.png b/world_maker/data/highwaymap.png index d675fe6..887f225 100644 Binary files a/world_maker/data/highwaymap.png and b/world_maker/data/highwaymap.png differ diff --git a/world_maker/data/negative_sobel_water_map.png b/world_maker/data/negative_sobel_water_map.png index 923b6a2..893f381 100644 Binary files a/world_maker/data/negative_sobel_water_map.png and b/world_maker/data/negative_sobel_water_map.png differ diff --git a/world_maker/data/skeleton_highway.png b/world_maker/data/skeleton_highway.png index 47db64e..e6a99cc 100644 Binary files a/world_maker/data/skeleton_highway.png and b/world_maker/data/skeleton_highway.png differ diff --git a/world_maker/data/sobelmap.png b/world_maker/data/sobelmap.png index 0139d07..b61cb41 100644 Binary files a/world_maker/data/sobelmap.png and b/world_maker/data/sobelmap.png differ diff --git a/world_maker/data/treemap.png b/world_maker/data/treemap.png index 5d5e761..ab753da 100644 Binary files a/world_maker/data/treemap.png and b/world_maker/data/treemap.png differ diff --git a/world_maker/data/watermap.png b/world_maker/data/watermap.png index 2c3cdd5..0f1cdf9 100644 Binary files a/world_maker/data/watermap.png and b/world_maker/data/watermap.png differ diff --git a/world_maker/data_analysis.py b/world_maker/data_analysis.py index b9441e4..e1d9899 100644 --- a/world_maker/data_analysis.py +++ b/world_maker/data_analysis.py @@ -130,18 +130,17 @@ def filter_smooth(image: Union[str, Image], radius: int = 3): return Image.fromarray(bool_array) -def remove_water_from_map(image: Union[str, Image]) -> Image: +def subtract_map(image: Union[str, Image], substractImage: Union[str, Image]) -> Image: image = handle_import_image(image) - watermap = Image.open('./data/watermap.png').convert('L') + substractImage = handle_import_image(substractImage).convert('L') array_heightmap = np.array(image) - array_watermap = np.array(watermap) + array_substractImage = np.array(substractImage) - mask = array_watermap == 255 + mask = array_substractImage == 255 array_heightmap[mask] = 0 - result_image = Image.fromarray(array_heightmap) - return result_image + return Image.fromarray(array_heightmap) def group_map(image1: Union[str, Image], image2: Union[str, Image]) -> Image: @@ -164,21 +163,32 @@ def filter_smooth_array(array: np.ndarray, radius: int = 3) -> np.ndarray: return array +def filter_remove_details(image: Union[str, Image], n: int = 20) -> Image: + image = handle_import_image(image) + array = np.array(image) + for _ in range(n): + array = ndimage.binary_dilation(array, iterations=4) + array = ndimage.binary_erosion(array, iterations=5) + array = filter_smooth_array(array, 2) + array = ndimage.binary_erosion(array, iterations=3) + image = Image.fromarray(array) + return image + + def highway_map() -> Image: smooth_sobel = filter_smooth("./data/sobelmap.png", 1) - inverse_sobel = filter_negative(smooth_sobel) - sobel_no_water = remove_water_from_map(inverse_sobel) - sobel_no_water.save("./data/negative_sobel_water_map.png") - array = np.array(sobel_no_water) - array = ndimage.binary_erosion(array, iterations=10) - array = ndimage.binary_dilation(array, iterations=5) - array = filter_smooth_array(array, 5) - array = ndimage.binary_erosion(array, iterations=17) - array = filter_smooth_array(array, 6) - array = ndimage.binary_dilation(array, iterations=3) - image = Image.fromarray(array) - image.save('./data/highwaymap.png') - return image + negative_smooth_sobel = filter_negative(smooth_sobel) + negative_smooth_sobel_water = subtract_map(negative_smooth_sobel, './data/watermap.png') + array_sobel_water = np.array(negative_smooth_sobel_water) + array_sobel_water = ndimage.binary_erosion(array_sobel_water, iterations=12) + array_sobel_water = ndimage.binary_dilation(array_sobel_water, iterations=5) + array_sobel_water = filter_smooth_array(array_sobel_water, 5) + array_sobel_water = ndimage.binary_erosion(array_sobel_water, iterations=20) + array_sobel_water = filter_smooth_array(array_sobel_water, 6) + image = Image.fromarray(array_sobel_water) + image_no_details = filter_remove_details(image, 15) + image_no_details.save('./data/highwaymap.png') + return image_no_details def create_volume(surface: np.ndarray, heightmap: np.ndarray, make_it_flat: bool = False) -> np.ndarray: diff --git a/world_maker/world_maker.py b/world_maker/world_maker.py index 6561f65..c711b88 100644 --- a/world_maker/world_maker.py +++ b/world_maker/world_maker.py @@ -3,8 +3,7 @@ from PIL import Image from data_analysis import get_data, highway_map, filter_sobel, skeleton_highway_map if __name__ == '__main__': - #world = World.World() - #heightmap, watermap, treemap = get_data(world) + world = World.World() + heightmap, watermap, treemap = get_data(world) filter_sobel("./data/heightmap.png").save('./data/sobelmap.png') - highway_map() - skeleton_highway_map(Image.open('./data/highwaymap.png')) + skeleton_highway_map(highway_map())