[VP] 图像开运算 Opening

图像开运算代码

开运算其实就是先做侵蚀运算,再做扩张运算,闭运算顺序相反

import numpy as np
import matplotlib.pyplot as plt
import scipy

image = np.array([[0, 1, 1, 1, 0], 
                  [0, 0, 1, 0, 0], 
                  [0, 0, 1, 0, 0], 
                  [0, 0, 1, 0, 0], 
                  [0, 1, 1, 1, 0]])

opening1 = scipy.ndimage.grey_erosion(image, size=(1,1))
opening1 = scipy.ndimage.grey_dilation(opening1, footprint=np.ones((1,1)))
opening1 = Image.fromarray(opening1)

opening2 = scipy.ndimage.grey_erosion(image, size=(2,2))
opening2 = scipy.ndimage.grey_dilation(opening2, footprint=np.ones((2,2)))
opening2 = Image.fromarray(opening2)

opening3 = scipy.ndimage.grey_erosion(image, size=(3,3))
opening3 = scipy.ndimage.grey_dilation(opening3, footprint=np.ones((3,3)))
opening3 = Image.fromarray(opening3)


plt.subplot(1, 3, 1)
plt.imshow(opening1)
plt.subplot(1, 3, 2)
plt.imshow(opening2)
plt.subplot(1, 3, 3)
plt.imshow(opening3)

imageArray1 = np.array(opening1)
print("Opening Image1: \n", imageArray1)
imageArray2 = np.array(opening2)
print("Opening Image2: \n", imageArray2)
imageArray3 = np.array(opening3)
print("Opening Image3: \n", imageArray3)

这图像,imshow了个寂寞哈哈。。。
在这里插入图片描述

Opening Image1: 
 [[0 1 1 1 0]
 [0 0 1 0 0]
 [0 0 1 0 0]
 [0 0 1 0 0]
 [0 1 1 1 0]]
Opening Image2: 
 [[0 1 1 1 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]]
Opening Image3: 
 [[0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]]

从结果看,开运算的size越大,效果越强。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是土豆大叔啊!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值