Created
November 7, 2015 01:13
-
-
Save melihme/a04f1d0c02542a9f8ebe to your computer and use it in GitHub Desktop.
Photoshop soft light blend with Numpy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
#https://en.wikipedia.org/wiki/Blend_modes#Soft_Light | |
def soft_light_blend(im1, im2): | |
nrm_im1 = im1/255. | |
nrm_im2 = im2/255. | |
res = np.zeros_like(nrm_im1) | |
xif = nrm_im2 < .5 | |
xel = nrm_im2 >= .5 | |
a = nrm_im1[xif] | |
b = nrm_im2[xif] | |
res[xif] = (2 * a * b + (a ** 2) * (1 - 2 * b)) | |
a = nrm_im1[xel] | |
b = nrm_im2[xel] | |
res[xel] = (2 * a * (1 - b) + np.sqrt(a) * (2 * b - 1)) | |
res=res * (255 / res.max()) | |
return res.astype('uint8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment