用Scipy进行图像侵蚀和扩张 [英] Image erosion and dilation with Scipy

查看:717
本文介绍了用Scipy进行图像侵蚀和扩张的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用scipy来执行数组。我使用 flatten = true 将原始图像转换为灰度,如下所示:

  im = scipy.misc.imread('flower.png',flatten = True).astype(np.uint8)

然后调用:

  im1 = ndimage.grey_erosion(im,size =(15,15))

虽然它是灰度的,却得到了很好的侵蚀图片。


I am trying to use scipy to do erosion and dilation of an image. It seems pretty straightforward using scipy -> binary_erosion / dialation. However, the output is not at all what is expected.

Here is my basic code:

import scipy
from scipy import ndimage
import matplotlib.pyplot as plt
import numpy as np
import Image

#im = Image.open('flower.png')
im = ndimage.imread('flower.png')
im = ndimage.binary_erosion(im).astype(np.float32)
scipy.misc.imsave('erosion.png', im)


im2 = Image.open('flower.png')
im2 = ndimage.binary_dilation(im2)
scipy.misc.imsave('dilation.png', im2)

This is the output:

The output for dilation is just a completely white image for the original "flower.png"

I believe that I must specify a better kernel or mask but am not really sure why I am getting a green output for erosion and completely white output for dilation.

解决方案

I was using the binary erosion instead of the grey erosion array. I converted the original image to greyscale by using flatten=true like so:

im = scipy.misc.imread('flower.png', flatten=True).astype(np.uint8)

then called:

im1 = ndimage.grey_erosion(im, size=(15,15))

And got a nicely eroded picture, although it is greyscale.

这篇关于用Scipy进行图像侵蚀和扩张的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆