【问题标题】:Is there any way to reshape more than one image together in python for NMF?有没有办法在 python 中为 NMF 重塑多个图像?
【发布时间】:2020-04-28 11:45:34
【问题描述】:

我是 Nmf 的新手,使用 python 。我正在尝试创建图像列表以获取组件。代码如下:

from skimage import color
from skimage import io
import matplotlib.pyplot as plt

f=color.rgb2gray(io.imread('f.jpg'))
e=color.rgb2gray(io.imread('e.jpg'))


images2= (e,f)

from sklearn.decomposition import NMF
model=NMF(n_components=2)
features=model.fit_transform(images2)

然后出现下一个错误:

Found array with dim 3. Estimator expected <= 2.

【问题讨论】:

  • 您需要将每个图像展平为一个矢量(1d)。

标签: scikit-learn scikit-image nmf


【解决方案1】:

根据文档。设计矩阵(NMF.fit 的参数)的大小必须为 (n_samples,n_features)。这意味着您需要将图像展平。

试试:

from skimage import color
from skimage import io
import matplotlib.pyplot as plt

f=color.rgb2gray(io.imread('f.jpg'))
e=color.rgb2gray(io.imread('e.jpg'))


images2= (e,f)

#flattening
images2 = np.array(images2).reshape(2,-1)

from sklearn.decomposition import NMF
model=NMF(n_components=2)
features=model.fit_transform(images2)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 2019-06-28
    • 2020-09-01
    • 2013-05-15
    • 2021-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多