mehdi-antoine / normalmapgenerator Goto Github PK
View Code? Open in Web Editor NEWNormal Map Generator using python
License: MIT License
Normal Map Generator using python
License: MIT License
This is a great little tool.
Sorry I haven't done this as a propper pull request (i'm doing this quite adhoc) but here's a little modification I have made to this, which saves a kind of AO in the alpha channel of the output files. I have a couple of other extra enhancements in mind for my workflow. this would want to be a commandline option I guess, and would need a couple of control parameters (the size of the shadow gaussian, the bias, and whether to combine it or not)
from PIL import Image
import math
def normalized(a):
factor = 1.0/math.sqrt( np.sum(a*a)) # normalize
return a*factor
def my_gauss(im):
im_smooth = im.astype(float)
kernel = np.array([0.5,1.0,0.5]).astype(float);
kernel=normalized(kernel)
im_smooth = scipy.ndimage.convolve(im_smooth, kernel[np.newaxis])
im_smooth = scipy.ndimage.convolve(im_smooth, kernel[np.newaxis].T)
return im_smooth
#calculate a local internal shadowing/AO aproximation using 'difference of gaussians'
def shadow(im):
im1 = im.astype(float)
im0 = im1.copy()
im00 = im1.copy()
im000 = im1.copy()
for i in range(0,2):
im00 = my_gauss(im00)
for i in range(0,64):
im0 = my_gauss(im0)
for i in range(0,128):
im1 = my_gauss(im1)
im000=normalized(im000)
im00=normalized(im00)
im0=normalized(im0)
im1=normalized(im1)
im00=normalized(im00)
shadow=im00*2.0+im000-im1*2.0-im0 # np.clip(im1, 0.0, 1000000.0)
shadow=normalized(shadow)
mean = np.mean(shadow)
rmse = rms_error(shadow)
shadow = np.clip(shadow, mean-rmse*2.0,mean+rmse*0.5)
return shadow
# ....
# added to the end of main()
# save the pure normal map and AO/shadow images as seperatejpgs
scipy.misc.imsave("normal.jpg", normal_map)
im_shadow = shadow(im)
scipy.misc.imsave("shadow.jpg", im_shadow)
# read these images back in, and combine them to make an image with RGB=normal, Alpha=AO
# really I did this because i couldn't get it working from numpy arrays directly.
imgsh=Image.open("shadow.jpg")
#imgsh.show()
imgnorm=Image.open("normal.jpg")
#imgnorm.show()
imgnormao = np.zeros( (img.size[0],img.size[1],4), np.float)
imgnormao[ :, :, 0:3] = np.asarray(imgnorm)[:,:,0:3] #RGB = normal
imgnormao[ :, :, 3] = np.asarray(imgsh)[:,:] #Alpha = AO
scipy.misc.imsave(output_file, imgnormao)
imgnormao=Image.open(output_file) # save the RGBA image containing Normal,AO
Thanks for making this! What's the licence? Could you please add a LICENCE.md file? GitHub has a simple process for it.
Selfishly, may I suggest the MIT licence? But it's up to you, of course :-)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.