上下文

I'm trying to recreate an effect used on photoshop called satin effect, which creates stainy texture by creating a satin texture (or structure) and applying a blur-like effect.

Example :

Example

I think this effect is achieved by using a double shift of the input pattern from which they apply a XOR operation to get the satin pattern (See Image above - Satin Size 0), then I think they apply a gaussian blur while handling the intersection of the XOR operation.

到目前为止我所做的

I created the first part which consist of shifting the pattern of the satin.
Here's the code :
Image Used : apple.png

apple = cv2.imread('apple.png')
apple = cv2.cvtColor(apple, cv2.COLOR_BGR2GRAY)

# User Inputs (Similar to Photoshop)
angle = 41        # angle of the shift
distance = 100    # distance of the shift

angle = np.deg2rad(180-angle)
tx, ty = (distance*np.cos(angle),distance*np.sin(angle))

# Shifting
shift_matrix1 = np.array([[1,0,tx],[0,1,ty]], dtype=np.float32)
shift_matrix2 = np.array([[1,0,-tx],[0,1,-ty]], dtype=np.float32)

shift1 = cv2.warpAffine(apple, shift_matrix1, apple.shape)
shift2 = cv2.warpAffine(apple,shift_matrix2, apple.shape)

# XOR Operation
xor_result = cv2.bitwise_not(cv2.bitwise_and(cv2.bitwise_xor(shift1, shift2), apple))

output = cv2.bitwise_and(xor_result, apple)

这为我们提供了预期结果(similar to what we achieve with photoshop):

result1

Problem :
But the problem emerge when I try to apply the gaussian blur before the XOR operation (Which can be achieved by adding those two lines of code before the XOR operation :

...

shift1 = cv2.GaussianBlur(shift1, (101,101),0)
shift2 = cv2.GaussianBlur(shift2, (101,101),0)

# XOR Operation
xor_result = ...


And her's what I get :

example2


Vs What I get using Photoshop :

example photoshop


问题

So I think that I'm missing an operation to handle the intersection of those 2 shapes (where we got those weird pixels)
So my question is : What operation do you think we should add in order to handle the intersection of the XOR of these two shapes ?

推荐答案

布尔or算子的模糊逻辑版本是max算子,而and算子的模糊逻辑版本是min.

对于异或,逻辑上最等价的是max(x-y, y-x),更有效地写为abs(x-y).This paper描述了另外两个选项,但绝对差异似乎很好地再现了Photoshop效果.

因此,我将实现您的代码:

xor_result = cv2.absdiff(shift1, shift2)
output = np.minimum(255 - xor_result, apple)

Python相关问答推荐

通过交换 node 对链接列表进行 Select 排序

当密钥是复合且唯一时,Pandas合并抱怨标签不唯一

将numpy数组存储在原始二进制文件中

连接两个具有不同标题的收件箱

如何在类和classy-fastapi -fastapi- followup中使用FastAPI创建路由

SQLAlchemy Like ALL ORM analog

Tkinter菜单自发添加额外项目

在Python中使用if else或使用regex将二进制数据如111转换为001""

ModuleNotFoundError:没有模块名为x时try 运行我的代码''

从源代码显示不同的输出(机器学习)(Python)

语法错误:文档. evaluate:表达式不是合法表达式

计算机找不到已安装的库'

如何反转一个框架中列的值?

数据框,如果值在范围内,则获取范围和

如何将相同组的值添加到嵌套的Pandas Maprame的倒数第二个索引级别

删除Dataframe中的第一个空白行并重新索引列

为什么Visual Studio Code说我的代码在使用Pandas concat函数后无法访问?

对数据帧进行分组,并按组间等概率抽样n行

Pandas 删除只有一种类型的值的行,重复或不重复

Groupby并在组内比较单独行上的两个时间戳