System:
python: 3.6.8 |Anaconda custom (64-bit)| (default, Dec 29 2018, 19:04:46) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]
executable: /Users/steve/miniconda3/envs/retinanet/bin/python
machine: Darwin-18.2.0-x86_64-i386-64bit
BLAS:
macros: SCIPY_MKL_H=None, HAVE_CBLAS=None
lib_dirs: /Users/steve/miniconda3/envs/retinanet/lib
cblas_libs: mkl_rt, pthread
Python deps:
pip: 19.0.3
setuptools: 40.8.0
sklearn: 0.20.3
numpy: 1.16.2
scipy: 1.2.1
Cython: 0.29.6
pandas: 0.24.2
我正在尝试将图像转换为补丁,然后将其转换回图像并保存。似乎有两个功能可以做到这一点。
使用以下代码,重建补丁似乎只是使图像“变黑”并减小大小(原始图像大小为31MB,新大小为33KB)。没有颜色,什么都没有。垃圾。
import numpy as np
from PIL import Image
from sklearn.feature_extraction import image as skl
image = Image.open('./myimage.tif')
image = np.array(image)[..., :3]
patches = skl.extract_patches_2d(image, (300, 300), max_patches = 250)
reconstruct = skl.reconstruct_from_patches_2d(patches, image.shape)
# i need this as uint8, as i'm saving it back into an image
# i tried using skimage.img_as_ubyte, but i recieve an error
reconstruct = reconstruct.astype(np.uint8)
Image.fromarray(reconstruct, 'RGB').save('./myimage.out.tif')
我在做错什么吗?从extract_patches_2d返回的补丁都具有颜色并且看起来不错。因此,我希望重建的行为相同。