Add get_data_no_update to quick test
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 717 B |
|
Before Width: | Height: | Size: 1005 B After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.4 KiB |
@@ -18,6 +18,17 @@ def get_data(world: World):
|
||||
return heightmap, watermap, treemap
|
||||
|
||||
|
||||
def get_data_no_update():
|
||||
print("[Data Analysis] Generating data...")
|
||||
# heightmap, watermap, treemap = world.getData()
|
||||
heightmap, watermap, treemap = handle_import_image(
|
||||
'./world_maker/data/heightmap.png'), handle_import_image(
|
||||
'./world_maker/data/watermap.png'), handle_import_image(
|
||||
'./world_maker/data/treemap.png')
|
||||
print("[Data Analysis] Data generated.")
|
||||
return heightmap, watermap, treemap
|
||||
|
||||
|
||||
def handle_import_image(image: str | Image.Image) -> Image.Image:
|
||||
if isinstance(image, str):
|
||||
return Image.open(image)
|
||||
@@ -68,29 +79,29 @@ def filter_sobel(image: str | Image.Image) -> Image.Image:
|
||||
for i in range(1, h - 1):
|
||||
for j in range(1, w - 1):
|
||||
horizontalGrad = (
|
||||
(horizontal[0, 0] * gray_img[i - 1, j - 1])
|
||||
+ (horizontal[0, 1] * gray_img[i - 1, j])
|
||||
+ (horizontal[0, 2] * gray_img[i - 1, j + 1])
|
||||
+ (horizontal[1, 0] * gray_img[i, j - 1])
|
||||
+ (horizontal[1, 1] * gray_img[i, j])
|
||||
+ (horizontal[1, 2] * gray_img[i, j + 1])
|
||||
+ (horizontal[2, 0] * gray_img[i + 1, j - 1])
|
||||
+ (horizontal[2, 1] * gray_img[i + 1, j])
|
||||
+ (horizontal[2, 2] * gray_img[i + 1, j + 1])
|
||||
(horizontal[0, 0] * gray_img[i - 1, j - 1])
|
||||
+ (horizontal[0, 1] * gray_img[i - 1, j])
|
||||
+ (horizontal[0, 2] * gray_img[i - 1, j + 1])
|
||||
+ (horizontal[1, 0] * gray_img[i, j - 1])
|
||||
+ (horizontal[1, 1] * gray_img[i, j])
|
||||
+ (horizontal[1, 2] * gray_img[i, j + 1])
|
||||
+ (horizontal[2, 0] * gray_img[i + 1, j - 1])
|
||||
+ (horizontal[2, 1] * gray_img[i + 1, j])
|
||||
+ (horizontal[2, 2] * gray_img[i + 1, j + 1])
|
||||
)
|
||||
|
||||
newhorizontalImage[i - 1, j - 1] = abs(horizontalGrad)
|
||||
|
||||
verticalGrad = (
|
||||
(vertical[0, 0] * gray_img[i - 1, j - 1])
|
||||
+ (vertical[0, 1] * gray_img[i - 1, j])
|
||||
+ (vertical[0, 2] * gray_img[i - 1, j + 1])
|
||||
+ (vertical[1, 0] * gray_img[i, j - 1])
|
||||
+ (vertical[1, 1] * gray_img[i, j])
|
||||
+ (vertical[1, 2] * gray_img[i, j + 1])
|
||||
+ (vertical[2, 0] * gray_img[i + 1, j - 1])
|
||||
+ (vertical[2, 1] * gray_img[i + 1, j])
|
||||
+ (vertical[2, 2] * gray_img[i + 1, j + 1])
|
||||
(vertical[0, 0] * gray_img[i - 1, j - 1])
|
||||
+ (vertical[0, 1] * gray_img[i - 1, j])
|
||||
+ (vertical[0, 2] * gray_img[i - 1, j + 1])
|
||||
+ (vertical[1, 0] * gray_img[i, j - 1])
|
||||
+ (vertical[1, 1] * gray_img[i, j])
|
||||
+ (vertical[1, 2] * gray_img[i, j + 1])
|
||||
+ (vertical[2, 0] * gray_img[i + 1, j - 1])
|
||||
+ (vertical[2, 1] * gray_img[i + 1, j])
|
||||
+ (vertical[2, 2] * gray_img[i + 1, j + 1])
|
||||
)
|
||||
|
||||
newverticalImage[i - 1, j - 1] = abs(verticalGrad)
|
||||
@@ -318,6 +329,7 @@ def get_index_of_biggest_area_mountain(area_mountain: list[int], exception: list
|
||||
index = i
|
||||
return index
|
||||
|
||||
|
||||
def get_random_point_in_area_mountain(mountain_map: list[list[int]], index: int) -> Position | None:
|
||||
points = []
|
||||
for y in range(len(mountain_map)):
|
||||
@@ -328,6 +340,7 @@ def get_random_point_in_area_mountain(mountain_map: list[list[int]], index: int)
|
||||
return None
|
||||
return choice(points)
|
||||
|
||||
|
||||
def get_center_of_area_mountain(mountain_map: list[list[int]], index: int) -> Position:
|
||||
sum_x = 0
|
||||
sum_y = 0
|
||||
@@ -353,7 +366,8 @@ def detect_mountain(number_of_mountain: int = 2, height_threshold: int = 10,
|
||||
for y in range(image_heightmap.size[1]):
|
||||
for x in range(image_heightmap.size[0]):
|
||||
avg_height += image_heightmap.getpixel((x, y))
|
||||
avg_height = int(avg_height / (image_heightmap.size[0] * image_heightmap.size[1]))
|
||||
avg_height = int(
|
||||
avg_height / (image_heightmap.size[0] * image_heightmap.size[1]))
|
||||
print("[Data Analysis] Average height:", avg_height)
|
||||
|
||||
mountain_map = [[-1 if image_heightmap.getpixel((x, y)) < (avg_height + height_threshold) else 0 for x in
|
||||
@@ -375,13 +389,15 @@ def detect_mountain(number_of_mountain: int = 2, height_threshold: int = 10,
|
||||
if number_of_mountain < len(area_mountain):
|
||||
index_mountain = []
|
||||
for n in range(number_of_mountain):
|
||||
index_mountain.append(get_index_of_biggest_area_mountain(area_mountain, index_mountain))
|
||||
index_mountain.append(get_index_of_biggest_area_mountain(
|
||||
area_mountain, index_mountain))
|
||||
else:
|
||||
index_mountain = [i for i in range(len(area_mountain))]
|
||||
|
||||
position_mountain = []
|
||||
for i in range(len(index_mountain)):
|
||||
position_mountain.append(get_center_of_area_mountain(mountain_map, index_mountain[i]))
|
||||
position_mountain.append(get_center_of_area_mountain(
|
||||
mountain_map, index_mountain[i]))
|
||||
|
||||
return position_mountain
|
||||
|
||||
@@ -408,7 +424,7 @@ def rectangle_2D_to_3D(rectangle: list[tuple[tuple[int, int], tuple[int, int]]],
|
||||
|
||||
|
||||
def transpose_form_heightmap(heightmap: str | Image.Image, coordinates, origin: tuple[int, int]) -> tuple[
|
||||
int, int, int]:
|
||||
int, int, int]:
|
||||
heightmap = handle_import_image(heightmap).convert('L')
|
||||
|
||||
xMin, zMin = origin
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from world_maker.World import World
|
||||
from PIL import Image
|
||||
from world_maker.data_analysis import (get_data, filter_negative, rectangle_2D_to_3D, skeleton_mountain_map, highway_map, filter_sobel, skeleton_highway_map,
|
||||
from world_maker.data_analysis import (get_data, get_data_no_update, filter_negative, rectangle_2D_to_3D, skeleton_mountain_map, highway_map, filter_sobel, skeleton_highway_map,
|
||||
smooth_sobel_water, subtract_map, detect_mountain, filter_smooth, overide_map)
|
||||
from world_maker.City import City
|
||||
from world_maker.Position import Position
|
||||
@@ -9,8 +9,10 @@ from world_maker.pack_rectangle import generate_building
|
||||
|
||||
|
||||
def world_maker():
|
||||
world = World()
|
||||
heightmap, watermap, treemap = get_data(world)
|
||||
# world = World()
|
||||
# heightmap, watermap, treemap = get_data(world)
|
||||
|
||||
heightmap, watermap, treemap = get_data_no_update()
|
||||
|
||||
filter_sobel(
|
||||
"./world_maker/data/heightmap.png").save('./world_maker/data/sobelmap.png')
|
||||
|
||||