【发布时间】:2019-10-23 20:53:01
【问题描述】:
我有一张灰度噪声图像。我想应用PCA降噪,应用后看看输出。
这是我尝试做的:
[输入]:
from sklearn.datasets import load_sample_image
from sklearn.feature_extraction import image
from sklearn.decomposition import PCA
# Create patches of size 25 by 25 and create a matrix from all patches
patches = image.extract_patches_2d(grayscale_image, (25, 25), random_state = 42)
print(patches.shape)
# reshape patches because I got an error when applying fit_transform(ValueError: FoundValueError: Found array with dim 3. Estimator expected <= 2.)
patches_reshaped = patches.reshape(2,-1)
#apply PCA
pca = PCA()
projected = pca.fit_transform(patches_reshaped.data)
denoised_image = pca.inverse_transform(projected)
imshow(denoised_image)
[出]:
(来源:imggmi.com)
结果我得到了一个数组。如何查看去噪图像?
【问题讨论】:
标签: python pca noise-reduction