撇取运行非常缓慢,输出意外的结果

2024-04-25 02:21:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我第一次使用scikit图片是为了在这个周末的一个hackathon中使用。在做一些测试时,我发现api运行非常慢,尽管在the page的底部说它们的脚本运行时是4.780秒。我每次跑步都要花20分钟。你知道吗

他们的示例代码对我不起作用,因为我无法让matplotlib工作。我已经尝试适应它,并一直在使用PIL保存我的图像

import numpy as np
from PIL import Image
from skimage import data, img_as_float, img_as_ubyte
from skimage.segmentation import (morphological_chan_vese, 
morphological_geodesic_active_contour, inverse_gaussian_gradient, 
checkerboard_level_set)

def store_evolution_in(lst):
    """Returns a callback function to store the evolution of the 
level sets in
    the given list.
    """

    def _store(x):
        lst.append(np.copy(x))

    return _store

imarray = np.asarray(Image.open("./images/bottle.jpg"))
# Morphological ACWE
image = img_as_float(imarray)
# Initial level set
init_ls = checkerboard_level_set(image.shape, 6)
# List with intermediate results for plotting the evolution
evolution = []
callback = store_evolution_in(evolution)

gimage = inverse_gaussian_gradient(image)
ls = morphological_geodesic_active_contour(gimage, 100, init_ls,
                                       smoothing=1, balloon=-1,
                                       threshold=0.69,
                                       iter_callback=callback)
intls = img_as_ubyte(ls)
Image.fromarray(intls).save('./results/ls.jpg', 'JPEG')

我希望能得到一个像他们在结果中那样的分割图像(最终目标是只剩下瓶子里的黑色液体)。但运行时不仅比他们的长得多,而且只返回一个黑色图像。也许我做错了什么?你知道吗

我的活动监视器显示Python消耗了100%的CPU能量,但是底部的CPU负载显示用户消耗了9%,所以我只能假设我的内核没有全部被使用。你知道吗


Tags: thestorefrom图像imageimportimgas