Corrections to patch generation code for some features
This commit is contained in:
parent
70e895692c
commit
5cc9819dba
37
layergen.py
37
layergen.py
@ -159,8 +159,7 @@ class mstr_layergen:
|
|||||||
for line in file:
|
for line in file:
|
||||||
linedata = line.split(" ")
|
linedata = line.split(" ")
|
||||||
if linedata[0] == self._tag and linedata[1] == self._value:
|
if linedata[0] == self._tag and linedata[1] == self._value:
|
||||||
src = linedata[2].split(",")
|
contrast = int(linedata[4])
|
||||||
contrast = src[4]
|
|
||||||
|
|
||||||
return contrast
|
return contrast
|
||||||
|
|
||||||
@ -295,6 +294,8 @@ class mstr_layergen:
|
|||||||
|
|
||||||
# Find this layer's predetermined contrast
|
# Find this layer's predetermined contrast
|
||||||
lyr_contrast = self.findLayerContrast()
|
lyr_contrast = self.findLayerContrast()
|
||||||
|
if lyr_contrast != 0:
|
||||||
|
mstr_msg("layergen", "Applying contrast value: " + str(lyr_contrast))
|
||||||
|
|
||||||
# Should this not exist yet, we need to create it
|
# Should this not exist yet, we need to create it
|
||||||
#if os.path.isfile(gensrc_ptc) == False:
|
#if os.path.isfile(gensrc_ptc) == False:
|
||||||
@ -376,18 +377,18 @@ class mstr_layergen:
|
|||||||
self._tag == "landuse" and self._value == "residential"):
|
self._tag == "landuse" and self._value == "residential"):
|
||||||
amt = randrange(2, 9)
|
amt = randrange(2, 9)
|
||||||
masks = glob.glob(mstr_datafolder + "textures/tile/completion/*.png")
|
masks = glob.glob(mstr_datafolder + "textures/tile/completion/*.png")
|
||||||
for i in range(1, amt + 1):
|
|
||||||
pick = randrange(0, len(masks))
|
|
||||||
patchmask = Image.open(masks[pick])
|
|
||||||
patchpix = patchmask.load()
|
|
||||||
# Pick from possible tags and values for the patches
|
|
||||||
patchtags = [
|
patchtags = [
|
||||||
["landuse", "meadow"],
|
["landuse", "meadow"],
|
||||||
["landuse", "grass"],
|
["landuse", "grass"],
|
||||||
["natural", "heath"],
|
["natural", "heath"],
|
||||||
["natural", "scrub"]
|
["natural", "scrub"]
|
||||||
]
|
]
|
||||||
|
for i in range(1, amt + 1):
|
||||||
|
pick = randrange(0, len(masks))
|
||||||
|
patchmask = Image.open(masks[pick])
|
||||||
|
patchmask = patchmask.rotate(randrange(0, 360), expand=True)
|
||||||
|
patchpix = patchmask.load()
|
||||||
|
# Pick from possible tags and values for the patches
|
||||||
numbers = list(range(1, 16))
|
numbers = list(range(1, 16))
|
||||||
src = random.sample(numbers, 5)
|
src = random.sample(numbers, 5)
|
||||||
|
|
||||||
@ -411,7 +412,7 @@ class mstr_layergen:
|
|||||||
nc = ( oc[0], oc[1], oc[2], ptc_msk[3] )
|
nc = ( oc[0], oc[1], oc[2], ptc_msk[3] )
|
||||||
lp_pix[x,y] = nc
|
lp_pix[x,y] = nc
|
||||||
|
|
||||||
layerpatch = layerpatch.rotate(randrange(0, 360), expand=True)
|
#layerpatch = layerpatch.rotate(randrange(0, 360), expand=True)
|
||||||
|
|
||||||
lx = randrange(self._imgsize - layerpatch.width)
|
lx = randrange(self._imgsize - layerpatch.width)
|
||||||
ly = randrange(self._imgsize - layerpatch.height)
|
ly = randrange(self._imgsize - layerpatch.height)
|
||||||
@ -546,17 +547,17 @@ class mstr_layergen:
|
|||||||
d = randrange(41, 61)
|
d = randrange(41, 61)
|
||||||
layer_comp_pix[x, y] = ( d,d,d,a[3] )
|
layer_comp_pix[x, y] = ( d,d,d,a[3] )
|
||||||
if self._tag == "highway" and self._value != "motorway":
|
if self._tag == "highway" and self._value != "motorway":
|
||||||
d = randrange(0, 36)
|
d = randrange(0, 6)
|
||||||
dr = 90+d
|
dr = 80+d
|
||||||
dg = 90+d
|
dg = 80+d
|
||||||
db = 95+d
|
db = 85+d
|
||||||
da = a[3]
|
da = a[3]
|
||||||
layer_comp_pix[x, y] = ( dr,dg,db,da )
|
layer_comp_pix[x, y] = ( dr,dg,db,da )
|
||||||
if self._tag == "highway" and self._value == "motorway":
|
if self._tag == "highway" and self._value == "motorway":
|
||||||
d = randrange(0, 36)
|
d = randrange(0, 46)
|
||||||
dr = 57+d
|
dr = 47+d
|
||||||
dg = 68+d
|
dg = 58+d
|
||||||
db = 70+d
|
db = 60+d
|
||||||
layer_comp_pix[x, y] = ( dr,dg,db,a[3] )
|
layer_comp_pix[x, y] = ( dr,dg,db,a[3] )
|
||||||
if self._tag == "highway" and (self._value == "footway" or self._value == "track" or self._value == "path"):
|
if self._tag == "highway" and (self._value == "footway" or self._value == "track" or self._value == "path"):
|
||||||
dr = randrange(158, 183)
|
dr = randrange(158, 183)
|
||||||
@ -690,7 +691,7 @@ class mstr_layergen:
|
|||||||
ptc_src = []
|
ptc_src = []
|
||||||
|
|
||||||
# Find this layer's predetermined contrast
|
# Find this layer's predetermined contrast
|
||||||
lyr_contrast = self.findLayerContrast()
|
lyr_contrast = randrange(1, 4)
|
||||||
|
|
||||||
rg = mstr_resourcegen(self._tag, self._value, src)
|
rg = mstr_resourcegen(self._tag, self._value, src)
|
||||||
rg.setLayerContrast(int(lyr_contrast))
|
rg.setLayerContrast(int(lyr_contrast))
|
||||||
|
53
photogen.py
53
photogen.py
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
from PIL import Image, ImageFilter, ImageEnhance, ImageFile
|
from PIL import Image, ImageFilter, ImageEnhance, ImageFile
|
||||||
|
|
||||||
from defines import *
|
from defines import *
|
||||||
from layergen import *
|
from layergen import *
|
||||||
from log import *
|
from log import *
|
||||||
@ -92,33 +93,28 @@ class mstr_photogen:
|
|||||||
if c < len(cpl)-1:
|
if c < len(cpl)-1:
|
||||||
cplstr = cplstr + "_"
|
cplstr = cplstr + "_"
|
||||||
|
|
||||||
# Should this not exist yet, we need to create it
|
# Find the right color catalogue
|
||||||
rg = mstr_resourcegen("landuse", "meadow", cpl)
|
cpl_catalog = 0
|
||||||
rg.setLayerContrast(randrange(1,4))
|
for c in range(len(mstr_completion_colors)):
|
||||||
ptcimg = rg.gensource()
|
if mstr_completion_colors[c][0] == edn:
|
||||||
|
cpl_catalog = c
|
||||||
|
|
||||||
ptc_src = [ptcimg[0]]
|
# Put in some pixels
|
||||||
samples = 250 # <- We need this in a moment
|
cmpl_bg = Image.new("RGBA", (self._tile.width, self._tile.height))
|
||||||
for i in range(samples):
|
cmpl_pix = cmpl_bg.load()
|
||||||
imgid = 0
|
for y in range(0, self._tile.height):
|
||||||
if len(ptc_src) == 1: imgid = 0
|
for x in range(0, self._tile.width):
|
||||||
l = 0 - int(ptc_src[imgid].width / 2)
|
idx = randrange(0, len(mstr_completion_colors[cpl_catalog][1]))
|
||||||
r = cmpl.width - int(ptc_src[imgid].width / 2)
|
clr = mstr_completion_colors[cpl_catalog][1][idx]
|
||||||
t = 0 - int(ptc_src[imgid].height / 2)
|
cmpl_pix[x,y] = clr
|
||||||
b = cmpl.height - int(ptc_src[imgid].height / 2)
|
cmpl_bg = ImageEnhance.Contrast(cmpl_bg).enhance(0.8)
|
||||||
cmpl.alpha_composite(ptc_src[imgid], (randrange(l, r), randrange(t, b)))
|
cmpl_bg = cmpl_bg.filter(ImageFilter.GaussianBlur(radius=1))
|
||||||
|
cmpl_bg.alpha_composite(self._tile)
|
||||||
brd_img = ptcimg[1]
|
self._tile = cmpl_bg
|
||||||
cmpl.alpha_composite(brd_img)
|
|
||||||
|
|
||||||
# Patches to add from other sources. If they don't exist, we also need to make them
|
# Patches to add from other sources. If they don't exist, we also need to make them
|
||||||
masks = glob.glob(mstr_datafolder + "textures/tile/completion/*.png")
|
masks = glob.glob(mstr_datafolder + "textures/tile/completion/*.png")
|
||||||
amt = randrange(5, 16)
|
amt = randrange(5, 16)
|
||||||
for i in range(1, amt + 1):
|
|
||||||
pick = randrange(0, len(masks))
|
|
||||||
patchmask = Image.open(masks[pick])
|
|
||||||
patchpix = patchmask.load()
|
|
||||||
# Pick from possible tags and values for the patches
|
|
||||||
patchtags = [
|
patchtags = [
|
||||||
["landuse", "meadow"],
|
["landuse", "meadow"],
|
||||||
["landuse", "grass"],
|
["landuse", "grass"],
|
||||||
@ -126,6 +122,13 @@ class mstr_photogen:
|
|||||||
["natural", "scrub"]
|
["natural", "scrub"]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
for i in range(1, amt + 1):
|
||||||
|
pick = randrange(0, len(masks))
|
||||||
|
patchmask = Image.open(masks[pick])
|
||||||
|
patchmask = patchmask.rotate(randrange(0, 360), expand=True)
|
||||||
|
patchpix = patchmask.load()
|
||||||
|
|
||||||
|
# Pick from possible tags and values for the patches
|
||||||
numbers = list(range(1, 16))
|
numbers = list(range(1, 16))
|
||||||
src = random.sample(numbers, 5)
|
src = random.sample(numbers, 5)
|
||||||
|
|
||||||
@ -149,10 +152,10 @@ class mstr_photogen:
|
|||||||
nc = (oc[0], oc[1], oc[2], ptc_msk[3])
|
nc = (oc[0], oc[1], oc[2], ptc_msk[3])
|
||||||
lp_pix[x, y] = nc
|
lp_pix[x, y] = nc
|
||||||
|
|
||||||
layerpatch = layerpatch.rotate(randrange(0, 360), expand=True)
|
#layerpatch = layerpatch.rotate(randrange(0, 360), expand=True)
|
||||||
|
|
||||||
lx = randrange(self._imgsize - layerpatch.width)
|
lx = randrange(0, self._imgsize - layerpatch.width)
|
||||||
ly = randrange(self._imgsize - layerpatch.height)
|
ly = randrange(0, self._imgsize - layerpatch.height)
|
||||||
cmpl.alpha_composite(layerpatch, (lx, ly))
|
cmpl.alpha_composite(layerpatch, (lx, ly))
|
||||||
|
|
||||||
# Merge the images
|
# Merge the images
|
||||||
|
Loading…
x
Reference in New Issue
Block a user