Skip to content

Commit

Permalink
初始化项目
Browse files Browse the repository at this point in the history
Signed-off-by: A.Star <astar@snowland.ltd>
  • Loading branch information
ASTARCHEN committed Jul 26, 2018
1 parent 0af39f3 commit 130f1bf
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 37 deletions.
37 changes: 0 additions & 37 deletions README.md

This file was deleted.

3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
======
scikit-snowland
======
5 changes: 5 additions & 0 deletions requirements
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
opencv-python==3.4.1.15
numpy>=1.0.0
scikit-image>=0.13
matplotlib>=2.1.2
wand>=0.4.4
47 changes: 47 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 河北雪域网络科技有限公司 A.Star
# @contact: astar@snowland.ltd
# @site:
# @file: setup.py
# @time: 2018/7/11 15:13
# @Software: PyCharm


from setuptools import setup, find_packages
from snowland import __version__
setup(
name='scikit-snowland',
version=__version__,
description=(
'scikit tool for image '
),
long_description=open('README.rst').read(),
author='A.Star',
author_email='astar@snowland.ltd',
maintainer='A.Star',
maintainer_email='astar@snowland.ltd',
license='BSD License',
packages=find_packages(),
platforms=["all"],
url='https://gitee.com/hoops/snowland-img2cartoon',
classifiers=[
'Development Status :: 4 - Beta',
'Operating System :: OS Independent',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python',
'Programming Language :: Python :: Implementation',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Software Development :: Libraries'
],
install_requires=[
'opencv-python>=3.4.1.15',
'numpy>=1.0.0',
'scikit-image>=0.13',
'matplotlib>=2.1.2'
]
)
14 changes: 14 additions & 0 deletions snowland/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 河北雪域网络科技有限公司 A.Star
# @contact: astar@snowland.ltd
# @site:
# @file: __init__.py.py
# @time: 2018/7/26 10:30
# @Software: PyCharm

__version__ = '0.1.0'


if __name__ == '__main__':
pass
13 changes: 13 additions & 0 deletions snowland/image/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 河北雪域网络科技有限公司 A.Star
# @contact: astar@snowland.ltd
# @site:
# @file: __init__.py.py
# @time: 2018/7/26 10:31
# @Software: PyCharm


from .color import *
from .api import *
from .thirdparty import *
11 changes: 11 additions & 0 deletions snowland/image/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 河北雪域网络科技有限公司 A.Star
# @contact: astar@snowland.ltd
# @site:
# @file: __init__.py.py
# @time: 2018/7/26 10:32
# @Software: PyCharm


from .img_to_cartoon import cartoonise
52 changes: 52 additions & 0 deletions snowland/image/api/img_to_cartoon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 河北雪域网络科技有限公司 A.Star
# @contact: astar@snowland.ltd
# @site:
# @file: main.py
# @time: 2018/7/11 14:34
# @Software: PyCharm

import cv2


def cartoonise(img_rgb, num_down=2, num_bilateral=7):
"""
:param img_rgb: 输入图像
:param num_down: 缩减像素采样的数目
:param num_bilateral: 定义双边滤波的数目
:return:
"""
# 用高斯金字塔降低取样
img_color = img_rgb
for _ in range(num_down):
img_color = cv2.pyrDown(img_color)
# 重复使用小的双边滤波代替一个大的滤波
for _ in range(num_bilateral):
img_color = cv2.bilateralFilter(img_color, d=9, sigmaColor=9, sigmaSpace=7)
# 升采样图片到原始大小
for _ in range(num_down):
img_color = cv2.pyrUp(img_color)
# 转换为灰度并且使其产生中等的模糊
img_gray = cv2.cvtColor(img_color, cv2.COLOR_RGB2GRAY)
img_blur = cv2.medianBlur(img_gray, 7)
# 检测到边缘并且增强其效果
img_edge = cv2.adaptiveThreshold(img_blur, 255,
cv2.ADAPTIVE_THRESH_MEAN_C,
cv2.THRESH_BINARY,
blockSize=9,
C=2)
# 转换回彩色图像
img_edge = cv2.cvtColor(img_edge, cv2.COLOR_GRAY2RGB)
img_cartoon = cv2.bitwise_and(img_color, img_edge)
return img_cartoon


if __name__ == '__main__':
from skimage.io import imread, imshow
from skimage.data import chelsea
from matplotlib import pylab as plt
img = chelsea()
out = cartoonise(img)
plt.imshow(out)
plt.show()
11 changes: 11 additions & 0 deletions snowland/image/color/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 河北雪域网络科技有限公司 A.Star
# @contact: astar@snowland.ltd
# @site:
# @file: __init__.py.py
# @time: 2018/7/26 10:31
# @Software: PyCharm


from .color import ycbcr2rgb, rgb2ycbcr
68 changes: 68 additions & 0 deletions snowland/image/color/color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 河北雪域网络科技有限公司 A.Star
# @contact: astar@snowland.ltd
# @site:
# @file: color.py
# @time: 2018/7/26 0:24
# @Software: PyCharm

import numpy as np
npa = np.array

def rgb2ycbcr(img):
origT = npa([[65.481, 128.553, 24.966], [-37.797, -74.203, 112], [112, -93.786, -18.214]])
oriOffset = npa([[16], [128], [128]])

if img.dtype.name == 'uint8':
t = 1
offset = 1.0 / 255
elif img.dtype.name == 'float64':
t = 1.0 / 255
offset = 1.0 / 255
elif img.dtype.name == 'uint16':
t = 257.0 / 65535
offset = 257

T = origT * t
Offset = oriOffset * offset

ycbcr = np.zeros(img.shape, dtype=img.dtype)
for p in range(3):
ycbcr[:, :, p] = T[p, 0] * img[:, :, 0] + T[p, 1] * img[:, :, 1] + T[p, 2] * img[:, :, 2] + Offset[p]

return ycbcr


def ycbcr2rgb(img):
origT = npa([[65.481, 128.553, 24.966], [-37.797, -74.203, 112], [112, -93.786, -18.214]])
oriOffset = npa([[16], [128], [128]])
tinv = np.linalg.inv(origT)
if img.dtype.name == 'uint8':
t = 255
offset = 255
elif img.dtype.name == 'float64':
t = 255
offset = 1
elif img.dtype.name == 'uint16':
t = 65535 / 257.0
offset = 65535

T = tinv * t
Offset = offset * tinv.dot(oriOffset)

rgb = np.zeros(img.shape, dtype=img.dtype)

for p in range(3):
rgb[:, :, p] = T[p, 0] * img[:, :, 0] + T[p, 1] * img[:, :, 1] + T[p, 2] * img[:, :, 2] - Offset[p]

if img.dtype.name == 'float64':
rgb[rgb > 1] = 1
rgb[rgb < 0] = 0
return rgb

if __name__ == '__main__':
from skimage.io import imread
img = imread('1.jpg')
img2 = rgb2ycbcr(img)
img1 = ycbcr2rgb(img2)
19 changes: 19 additions & 0 deletions snowland/test/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 河北雪域网络科技有限公司 A.Star
# @contact: astar@snowland.ltd
# @site:
# @file: test.py
# @time: 2018/7/26 10:38
# @Software: PyCharm


if __name__ == '__main__':
from snowland.image.api import cartoonise
from skimage.io import imread, imshow
from skimage.data import chelsea
from matplotlib import pylab as plt
img = chelsea()
out = cartoonise(img)
plt.imshow(out)
plt.show()

0 comments on commit 130f1bf

Please sign in to comment.