admin管理员组文章数量:1406926
Photoshop has a lot of cool artistic filters, and I'd love to understand the underlying algorithms.
One algorithm that's particularly interesting is Crosshatch filter.
Is there any source for technical descriptions of the Photoshop filters? Alternatively, do you have any thoughts about how this particular filter might be implemented?
Photoshop has a lot of cool artistic filters, and I'd love to understand the underlying algorithms.
One algorithm that's particularly interesting is Crosshatch filter.
Is there any source for technical descriptions of the Photoshop filters? Alternatively, do you have any thoughts about how this particular filter might be implemented?
1 Answer
Reset to default 3You can do something like a Photoshop crosshatch with a 2D convolution with OpenCV in Python:
#!/usr/bin/env python3
import cv2 as cv
import numpy as np
# Load image
im = cv.imread('bird.png')
# Define +/- 45 degree kernel, change length to taste
len=11
kern = np.eye(len, dtype=np.float32)
kern = np.maximum(kern, kern[:,::-1]) / ( 2 * len)
print(kern)
# Apply 2D convolution to image
res = cv.filter2D(im, -1, kern)
# Save result
cv.imwrite('result.png', res)
If I change the length of the convolution kernel to 6, you can see its shape and content better. It is basically the sum of two diagonal matrices:
[[0.08333334 0. 0. 0. 0. 0.08333334]
[0. 0.08333334 0. 0. 0.08333334 0. ]
[0. 0. 0.08333334 0.08333334 0. 0. ]
[0. 0. 0.08333334 0.08333334 0. 0. ]
[0. 0.08333334 0. 0. 0.08333334 0. ]
[0.08333334 0. 0. 0. 0. 0.08333334]]
If, instead of opening your image, I just create a 400x400 black image and place a single white dot at the centre, then do the convolution, you will see what it does:
#!/usr/bin/env python3
import cv2 as cv
import numpy as np
# Create square black image with a single white pixel in the middle
im = np.zeros((400,400), dtype=np.uint8)
im[200,200] = 255
# Define +/- 45 degree kernel, change length to taste
len=24
kern = np.eye(len, dtype=np.float32)
kern = np.maximum(kern, kern[:,::-1]) / ( 2 * len)
print(kern)
# Apply 2D convolution to image
res = cv.filter2D(im, -1, kern)
# Save result
cv.imwrite('result.png', res)
本文标签: algorithmHow is the photoshop Crosshatch filter implementedStack Overflow
版权声明:本文标题:algorithm - How is the photoshop Crosshatch filter implemented? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745056308a2639956.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
bash
script fmwconcepts/imagemagick/crosshatch/index.php You could amend the script to preserve the intermediate images in order to understand how it works. Note that you would likely need to pay a licence fee for commercial use. – Mark Setchell Commented Mar 4 at 10:12./crosshatch -l 5 -s 3 -g 1 -p 5 -e normal bird.png result.png
– Mark Setchell Commented Mar 4 at 11:43