Python 数字图像的形态侵蚀 - 错误
Morphological erosion on digital images with Python - error
我尝试使用 Python 对数字图像实施形态侵蚀。我上传了一个二进制图像并定义了一个结构元素 - ones(3,3)。但是当我运行代码时,出现如下错误:
运行时错误:序列参数的长度必须等于输入等级
请多多指教。以下是我的代码:
import numpy as np
import cv2
from matplotlib import pyplot as plt
from skimage import data, io, color
bi_im1 = plt.imread("binary1.jpg")
plt.imshow(bi_im1)
print("Original binary image1")
def plot_comparison(original, filtered, filter_name):
fig, (ax1, ax2) = plt.subplots( ncols=2, figsize=(512, 256), sharex=True,
sharey=True)
ax1.imshow(original, cmap=plt.cm.gray)
#ax1.set_title('original')
ax1.axis('off')
ax2.imshow(filtered, cmap=plt.cm.gray)
ax2.set_title(filter_name)
ax2.axis('off')
from skimage.morphology import (erosion, dilation, opening, closing)
from skimage.morphology import disk
selem = np.array([[1,1,1],
[1,1,1],
[1,1,1]])
plt.imshow(selem, cmap='gray', vmax=1, vmin=0);
eroded1 = erosion(bi_im1, selem)
plot_comparison(bi_im1, eroded1, 'erosion')
我的二进制图像'binary1.jpg'上传如下:
binaryimage1
将我提到的内容发布为 - 您正在尝试对 RGB 图像执行侵蚀操作。需要先将RGB图像转成二值图像,再用结构元素进行腐蚀。
我尝试使用 Python 对数字图像实施形态侵蚀。我上传了一个二进制图像并定义了一个结构元素 - ones(3,3)。但是当我运行代码时,出现如下错误:
运行时错误:序列参数的长度必须等于输入等级
请多多指教。以下是我的代码:
import numpy as np
import cv2
from matplotlib import pyplot as plt
from skimage import data, io, color
bi_im1 = plt.imread("binary1.jpg")
plt.imshow(bi_im1)
print("Original binary image1")
def plot_comparison(original, filtered, filter_name):
fig, (ax1, ax2) = plt.subplots( ncols=2, figsize=(512, 256), sharex=True,
sharey=True)
ax1.imshow(original, cmap=plt.cm.gray)
#ax1.set_title('original')
ax1.axis('off')
ax2.imshow(filtered, cmap=plt.cm.gray)
ax2.set_title(filter_name)
ax2.axis('off')
from skimage.morphology import (erosion, dilation, opening, closing)
from skimage.morphology import disk
selem = np.array([[1,1,1],
[1,1,1],
[1,1,1]])
plt.imshow(selem, cmap='gray', vmax=1, vmin=0);
eroded1 = erosion(bi_im1, selem)
plot_comparison(bi_im1, eroded1, 'erosion')
我的二进制图像'binary1.jpg'上传如下:
binaryimage1
将我提到的内容发布为