python - scikit-learn 的 extract_patches 函数背后的理论/算法是什么?

标签 python image-processing multidimensional-array scikit-learn data-science

我正在使用 extract_patches_2dextract_patches 从 2d 图像中提取本地补丁,我希望获得解释补丁实现方法的理论和引用资料萃取。

最佳答案

我不确定你指的是什么理论,在幕后这些方法只是巧妙的数组操作(剧透:numpy数组操作)。

  • 第一个,extract_patches_2d ,是 extract_patches 的简单二维包装器,它调用

    extract_patches(image,
                    patch_shape=(p_h, p_w, n_colors),
                    extraction_step=1)
    

    并 reshape 结果 ( source code )。

  • 第二个 extract_patches 也是一个包装器,这次是 numpy.as_strided 。它只准备 2*n 形状和跨步以将工作委托(delegate)给

    as_strided(arr, shape=shape, strides=strides)
    

    这是它的source code .

  • 真正有趣的是numpy.as_strided 。从它的文档:

    as_strided creates a view into the array given the exact strides and shape. This means it manipulates the internal data structure of ndarray and, if done incorrectly, the array elements can point to invalid memory and can corrupt results or crash your program. It is advisable to always use the original x.strides when calculating new strides to avoid reliance on a contiguous memory layout.

    因此,基本上,结果是内存中同一数组的包装器( View ),它提供索引查找,并且每个索引都在查找 x 内的特定区域>。 numpy.ndarray.view是 numpy 的核心函数,它允许在不重新分配内存的情况下查看现有数组的内部。如果您想深入了解 numpy 如何执行数组操作和 View ,numpy internals是一个很好的起点。

关于python - scikit-learn 的 extract_patches 函数背后的理论/算法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46621786/

相关文章:

python - 您如何使用经过训练的神经网络来识别图像中的多个对象?

python - 将Python与opencv结合使用以实现图像拼接

python - 以编程方式将列名添加到 numpy ndarray

python - Python 中的函数声明

python - 自动填充子图

php - 以透明颜色旋转图像

java - 如何访问二维数组的第二部分

Python:如何生成随机电话号码?

python - 重试规则 X 次

php - 如何从 PHP 多维数组中删除重复项,不区分大小写但保留大小写?