Giter Club home page Giter Club logo

normalmapgenerator's People

Contributors

af-tw avatar mehdi-antoine avatar michal212345 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

normalmapgenerator's Issues

thanks, sharing an enhancement as i'm obliged to for open source

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





Showing inverse normal map for human face

I want to generate normal map for 2D human face.

Original image

Original Image

Generated Normal Map

Generated Normal Map

Expected Normal Map

Expected Normal map
I think the result is coming inverse for me. But inversing won't solve it.
Can you please tell me what value should I change or how to approach this problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.