围绕ndarray和opencv进行快速原型设计
coat的Python项目详细描述
外套
Coat是位于numpy的ndarray(子类)和opencv
Coat唯一的优点是用于快速成型
风格
Coat正在使用级联方法
从每个方法返回的是Coat的HigherCoating实例
唯一的例外是返回numpy instance\
安装
最好使用虚拟环境
pip install coat
演示
函数Coat是处理不同类型参数的代理函数。在
它处理str(url)、图像的列表/生成器和ndarray。在
^{pr2}$使用
Content
Core functionalities
Dominance
Array manipulation
Image downloading
Labeling
Color spaces
Helper functions
Montage
Contours
Color filtering
Motion difference
核心功能
让我们定义两个不同类型、大小和维度的数组
# Import Coat(proxy function) and MontagefromcoatimportCoat,Montageimportnumpyasnparray1=Coat(np.zeros(shape=[40,60,3],dtype=np.uint8))array2=Coat(np.zeros(shape=[8,8],dtype=np.float32))
自动分解器
对数组进行涂层可以让Coat在发生冲突时解决数组操作
res=array1+array2res.shape,res.dtype>>>(40,60,3)uint8
涂层阵列可以是显性的也可以是非显性的。 一般规则如下:
A(non-dominant) + B(non-dominant) -> A is prioritized A(non-dominant) + B(dominant) -> B is prioritized A(dominant) + B(non-dominant) -> A is prioritized A(dominant) + B(dominant) -> A is prioritized
优势设置
你可以设定哪一个是主导阵法 默认情况下,每个数组不占主导地位。在
res=array1*array2.host()res.shape,res.dtype>>>(8,8)float32
如果有不同大小和维度的数组(灰色和彩色),您可以简单地转换为通用标准,如下所示
list_of_images=[img1,img2,img3,..,..,imgN]# define common standardgrayscale_template=Coat(np.zeros(shape=[100,100],dtype=np.uint8))colored_template=Coat(np.zeros(shape=[100,100],dtype=np.uint8))grascaled=[grayscale_template.host()+imageforimageinlist_of_images]colored=[colored_template.host()+imageforimageinlist_of_images]
插值
可以设置插值算法(默认为线性-双线性)
res=array1-array2.host('CUBIC')
消除优势
res=array1*array2.host('CUBIC').guest()res.shape,res.dtype>>>(40,60,3)uint8
数组操作
将osize设置为目标大小
array1.shape,array2.shape>>>(40,60,3),(8,8)array1.osize(array2.shape).shape>>>(8,8,3)array2.osize(array1.shape).shape>>>(40,60)
r大小为相对大小
res=array2.rsize(fx=2,fy=0.5)res.shape>>>(16,4)
n阵列兼容性
res=array1+np.zeros(shape=array1.shape)np.uint8(array1)# -> returns back Coat instance with changed datatypearray1.classic()# -> returns back numpy instance
利用OpenCV
下载图片
将url传递给Coat并show
url="https://natgeo.imgix.net/subjects/headers/shutterstock_276228476.jpg?auto=compress,format&w=1920&h=960&fit=crop"image=Coat(url).show()image=image.rsize(fx=0.25,fy=0.25)
支持标记
# Use int for objective coordinatesimage.labelbox("Home",(0,136),(230,340),bcolor=[0,255,0]).show()# Use float for relative coordinatesimage.labelbox("Home",(0.0,0.3),(0.9,0.7),bcolor=[0,255,0]).show()
色彩空间变化
支持的颜色变换
BGR2GRAY
BGR2HLS
BGR2HSV
HSV2BGR
GRAY2RGB
GRAY2BGR
RGB2GRAY
RGB2HSV
RGB2HLS
image.color_to('BGR2GRAY')
注
OpenCV使用BGR作为默认配色方案
图像处理助手
阈值
image.thresh(125,255,'thresh_binary').show()
卷积滤波
image.blur_medianimage.filter_bilateralimage.blur_gaussimage.blur_average
卷积2D
img.conv(kernel)
蒙太奇
请参见处理图像旁边的原始信号
我们添加主机(打开第一个图像的优势),这样我们就得到了RGB颜色空间的结果,因为我们的原始图像是RGB
image.rsize(fx=0.3,fy=0.3).host().join(image.thresh(127,255)).show()
不同色彩空间的蒙太奇
如果未定义模板,则主图像是第一个图像
all_images=[img]+[img.to_color(cspace)forcspaceincolor_spaces]montage=Montage(all_images).grid(2,2).show()
基于模板调整蒙太奇大小
montage=Montage(all_images).template(np.zeros(shape=[50,50,3],dtype=np.uint8)).grid(2,2)
移除具有形态开口的星星
image.morphologyEx('open',3).show()
轮廓
# Draw quick countoursthr=image.thresh(200,255)# copy contoured=image.copy().contours(thr,min_size=5,max_size=9999999,thickness=2,color=[0,125,255]).show()
更换特定颜色
present=[0,125,255]future=[255,0,0]contoured.replace(present,future).show()
颜色过滤
# [36,0,0] --> green color interval in HSV <--[70,255,255]image.filterHsv([36,0,0],[70,255,255],passband=True).show()image.filterHsv([36,0,0],[70,255,255],passband=False).show()# Passband False: -------|++|----- # Passband True: ++++++|--|++++++
通带真
通带错误
运动差异
box1=Coat(np.zeros(shape=[400,400,3])).box((30,30),(250,250),color=[255,125,0])box2=Coat(np.zeros(shape=[400,400,3])).box((30,150),(250,350),color=[255,125,0])motion_diff=box1.motion_difference(box2,val=30).show()
- 项目
标签: