Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
Middleware
提交
80001873
M
Middleware
项目概览
OpenDocCN
/
Middleware
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Middleware
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
80001873
编写于
2月 19, 2020
作者:
飞
飞龙
提交者:
GitHub
2月 19, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
四阶灰度扩散仿色
上级
f0e79241
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
76 addition
and
0 deletion
+76
-0
src/diffdither.py
src/diffdither.py
+76
-0
未找到文件。
src/diffdither.py
0 → 100644
浏览文件 @
80001873
# coding: utf-8
import
sys
import
cv2
import
numpy
as
np
import
re
# 四阶灰度扩散仿色
# python diffdither.py <file>
def
build_pattern
(
shape
,
a0
,
a1
,
a2
,
a3
):
arr
=
np
.
zeros
(
shape
)
arr
[::
2
,
::
2
]
=
a0
arr
[::
2
,
1
::
2
]
=
a1
arr
[
1
::
2
,
::
2
]
=
a2
arr
[
1
::
2
,
1
::
2
]
=
a3
return
arr
# 0 85 170 255
def
process_img
(
img
):
assert
img
.
ndim
==
2
h
,
w
=
img
.
shape
if
w
>
1000
:
rate
=
1000
/
w
nh
=
round
(
h
*
rate
)
img
=
cv2
.
resize
(
img
,
(
1000
,
nh
),
interpolation
=
cv2
.
INTER_CUBIC
)
b
,
l11
,
l12
,
g1
,
l21
,
l22
,
g2
,
l31
,
l32
,
w
=
np
.
linspace
(
0
,
255
,
10
).
astype
(
int
)
pt11
=
build_pattern
(
img
.
shape
,
b
,
b
,
b
,
g1
)
pt12
=
build_pattern
(
img
.
shape
,
b
,
g1
,
g1
,
b
)
pt13
=
build_pattern
(
img
.
shape
,
b
,
g1
,
g1
,
g1
)
pt21
=
build_pattern
(
img
.
shape
,
g1
,
g1
,
g1
,
g2
)
pt22
=
build_pattern
(
img
.
shape
,
g1
,
g2
,
g2
,
g1
)
pt23
=
build_pattern
(
img
.
shape
,
g1
,
g2
,
g2
,
g2
)
pt31
=
build_pattern
(
img
.
shape
,
g2
,
g2
,
g2
,
w
)
pt32
=
build_pattern
(
img
.
shape
,
g2
,
w
,
w
,
g2
)
pt33
=
build_pattern
(
img
.
shape
,
g2
,
w
,
w
,
w
)
cond11
=
lambda
x
:
(
x
>
b
)
&
(
x
<
l11
)
cond12
=
lambda
x
:
(
x
>=
l11
)
&
(
x
<
l12
)
cond13
=
lambda
x
:
(
x
>=
l12
)
&
(
x
<
g1
)
cond21
=
lambda
x
:
(
x
>
g1
)
&
(
x
<
l21
)
cond22
=
lambda
x
:
(
x
>=
l21
)
&
(
x
<
l22
)
cond23
=
lambda
x
:
(
x
>=
l22
)
&
(
x
<
g2
)
cond31
=
lambda
x
:
(
x
>
g2
)
&
(
x
<
l31
)
cond32
=
lambda
x
:
(
x
>=
l31
)
&
(
x
<
l32
)
cond33
=
lambda
x
:
(
x
>=
l32
)
&
(
x
<
w
)
pts
=
{
cond11
:
pt11
,
cond12
:
pt12
,
cond13
:
pt13
,
cond21
:
pt21
,
cond22
:
pt22
,
cond23
:
pt23
,
cond31
:
pt31
,
cond32
:
pt32
,
cond33
:
pt33
,
}
for
cond
,
pt
in
pts
.
items
():
idx
=
cond
(
img
).
astype
(
int
)
img
=
img
*
(
1
-
idx
)
+
pt
*
idx
return
img
def
main
():
fname
=
sys
.
argv
[
1
]
print
(
fname
)
img
=
cv2
.
imread
(
fname
,
cv2
.
IMREAD_GRAYSCALE
)
img
=
process_img
(
img
)
fname
=
re
.
sub
(
r
'\.\w+$'
,
''
,
fname
)
+
'.png'
cv2
.
imwrite
(
fname
,
img
,
[
cv2
.
IMWRITE_PNG_COMPRESSION
,
9
])
if
__name__
==
'__main__'
:
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录