繁体   English   中英

有没有更有效的方法来找到这个 object 的轮廓并填充 python 中的空白?

[英]Is there a more efficient way to find the contour of this object and fill the blank spaces in python?

我正在尝试借助形态学操作来改善此图像。 我得到的结果很好,但得到结果图像需要将近 40 秒,我想知道是否有任何其他方法可以在不花费太长时间的情况下获得类似甚至更好的结果。

下面我附上了用于增强原始图像的图像和代码。 谢谢

原始脊椎图像最终脊椎图像

import matplotlib.pyplot as plt
from skimage.io import imread
from skimage.morphology import (square, rectangle, diamond, disk, erosion, dilation, opening, closing)

im = imread('/content/drive/MyDrive/Proc_imag/Spine.png')
imf = closing(im,disk(40))
imf = opening(imf,rectangle(75,1))
imf[975:,:] = 0

plt.imshow(im,cmap='gray')
plt.title('Original')
plt.show()

plt.imshow(imf,cmap='gray')
plt.title('Final')
plt.show() 

关闭 function 几乎占用了你所有的时间。 这主要是因为该函数的运行时与 kernel 大小和磁盘(40)可能是一个 80x80 kernel 引擎盖下的扩展非常可怕。 我们可以通过缩小图像并在较小的图像上运行等效大小的 kernel 来近似相同的事情。

import matplotlib.pyplot as plt
from skimage.io import imread
from skimage.morphology import (square, rectangle, diamond, disk, erosion, dilation, opening, closing)
from skimage.transform import rescale
import time
import numpy as np

# load image
start = time.time();
im = imread('spine.png')
imf = np.copy(im);
end = time.time();
print("Read Time: " + str(end - start));

# resize down
scale = 4.0;
start = time.time();
imf = rescale(imf, 1.0 / scale, order=0, anti_aliasing=False, multichannel=False);
end = time.time();
print("Scale Time: " + str(end - start));

# disk, fill in holes
start = time.time();
imf = closing(imf,disk(40 // scale))
end = time.time();
print("Disk Time: " + str(end - start));

# resize up
start = time.time();
imf = rescale(imf, scale, order=0, anti_aliasing=False, multichannel=False);
end = time.time();
print("Upscale Time: " + str(end - start));

# rect, remove thin horizontal lines
start = time.time();
imf = opening(imf,rectangle(75,1))
end = time.time();
print("Rect Time: " + str(end - start));

# ???
imf[975:,:] = 0

# show original image
plt.imshow(im,cmap='gray')
plt.title('Original')
plt.show()

# show processed image
plt.imshow(imf,cmap='gray')
plt.title('Final')
plt.show() 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM