mahotas绘图函数

1.函数
mahotas.polygon.line((y0, x0), (y1, x1), canvas, color=1)# 画一条线
参数:
p0 : 一对整数-第一点
p1 : 一对整数第二点
canvas : ndarray在要显示的图像上绘制
color : integer, optional绘图颜色
===============================================================================
mahotas.polygon.fill_polygon([(y0, x0), (y1, x1), ..., ]canvas, color=1)# 在画布上绘制一个填充的多边形
参数:
polygon : list of pairs-a list of (y,x) points
canvas : ndarray在要显示的图像上绘制
color : integer, optional绘图颜色
===============================================================================
mahotas.polygon.convexhull(bwimg)# 将凸包计算为多边形
参数:
bwimg : ndarray输入图像(解释为布尔值)仅支持2D阵列
返回值:	
hull : ndarray凸包外轮廓点(y,x)坐标集
===============================================================================
mahotas.polygon.fill_convexhull(bwimg)# 计算凸包并将其作为二进制掩码返回
参数:
bwimage : 输入图像(解释为布尔值)必须为int or bool类型
返回值:将凸包作为二进制图像返回
hull : 与bwimg具有相同大小和dtype的图像,并填充了船体
2.实例:

import mahotas as mh,numpy as np
from matplotlib import pyplot as plt
import cv2

girl=r'C:\Users\Administrator\Desktop\Fastener\Resources\Pictures\tubao.jpg'
image=mh.imread(girl,1)
image=255-image
img=np.zeros(image.shape,np.uint8)

x0,y0,x1,y1=100,100,200,200
mh.polygon.line((y0, x0), (y1, x1), image, color=125)# 画一条线

x0,y0=400,100
x1,y1=400,300
x2,y2=500,100
x3,y3=500,300
# mh.polygon.fill_polygon([(y0, x0), (y1, x1),(y2, x2), (y3, x3) ],canvas, color=125)#画填充多边形

binary1=mh.polygon.convexhull(image)#获取凸包外轮廓点
binary2=mh.polygon.fill_convexhull(image.astype('uint8'))##获取凸包外轮廓图像 -有些不正常,上面的是白色的?
mh.polygon.fill_polygon(binary1,img, color=125)#画填充多边形

cv2.imshow('s1',image)
cv2.imshow('s2',img)
cv2.imshow('s3',binary2.astype('uint8'))
cv2.waitKey()

print(binary1)
"""
[[ 56 142]
 [ 66 200]
[ 72 223]
[ 96 301]
[ 97 303]
[112 319]
[258 359]
[294 359]
[319 335]
[423 206]
[447 175]
[447 161]
[423  48]
[415  46]
[199  32]
[ 81  32]
[ 72  40]
[ 64  64]
[ 56 121]]
"""
print(binary2)
"""
[[255 255 255 ... 255 255 255]
 [255 255 255 ... 255 255 255]
[255 255 255 ... 255 255 255]
...
[  0   0   0 ...   0   0   0]
[  0   0   0 ...   0   0   0]
[  0   0   0 ...   0   0   0]]
"""

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值