我正在尝试读取 4 波段(红色、绿色、蓝色、近红外)geotiff(示例数据)并使用Python 中的模块执行快速移动分割。scikit-image
我创建了以下脚本(基于scikit 示例):
from __future__ import print_function
from osgeo import gdal
import matplotlib.pyplot as plt
import numpy as np
from skimage.segmentation import felzenszwalb, slic, quickshift
from skimage.segmentation import mark_boundaries
from skimage.util import img_as_float
image = r'C:\path\to\my\geotiff.tif'
img = io.imread(image, as_grey=False, plugin="gdal")
segments_quick = quickshift(img, kernel_size=3, max_dist=6, ratio=0.5)
我收到以下错误:
ValueError: the input array must be have a shape == (.., ..,[ ..,] 3)), got (4, 436, 553)
我很确定 numpy 数组需要以某种方式重塑。如何正确地将多波段 geotiff 读入 numpy 数组并执行图像分割?