Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python skimage.segmentation.slic()到底代表什么?_Python_Image Processing_Image Segmentation_Scikit Image_Interpretation - Fatal编程技术网

Python skimage.segmentation.slic()到底代表什么?

Python skimage.segmentation.slic()到底代表什么?,python,image-processing,image-segmentation,scikit-image,interpretation,Python,Image Processing,Image Segmentation,Scikit Image,Interpretation,我正在研究复制-移动伪造检测,并被其中一个算法卡住了。 我有一个532x800像素的RGB图像 运行以下代码时: import matplotlib.pyplot as plt from skimage.segmentation import slic, mark_boundaries from skimage.util import img_as_float from skimage import io img_rgb = img_as_float(io.imread(PATH)) segm

我正在研究复制-移动伪造检测,并被其中一个算法卡住了。 我有一个532x800像素的RGB图像

运行以下代码时:

import matplotlib.pyplot as plt
from skimage.segmentation import slic, mark_boundaries
from skimage.util import img_as_float
from skimage import io

img_rgb = img_as_float(io.imread(PATH))
segments = slic(image=img_rgb, n_segments=1000)
print(img_rgb.shape)
print(segments.shape)
img_rgb = mark_boundaries(image=img_rgb, label_img=segments)
plt.imshow(img_rgb)
plt.show()
它返回:

(532, 800, 3)
(532, 800)
这张图片:

由于输入图像和变量“段”的尺寸相同(第三通道尺寸除外)

  • 为什么它们的尺寸相同
  • “img_rgb”3D矩阵中的不同值表示颜色强度。变量“段”中的值代表什么?如何对它们进行类似的解释
  • 谢谢你的意见


    编辑:我知道它返回一个numpy数组。我很想知道它代表什么。

    找到了我要找的东西

    这是我写的代码

    import matplotlib.pyplot as plt
    from skimage.segmentation import slic, mark_boundaries
    from skimage.util import img_as_float
    from skimage import io
    from skimage.transform import resize
    import numpy as np
    
    img_rgb = img_as_float(io.imread("apple_32x32.png"))
    img_rgb = resize(image=img_rgb, output_shape=(32, 32, 3))
    
    segments = slic(image=img_rgb, n_segments=10)
    print(img_rgb.shape)
    print(segments.shape)
    img_rgb = mark_boundaries(image=img_rgb, label_img=segments)
    plt.imshow(img_rgb)
    plt.show()
    
    np.savetxt("segments.txt", segments, fmt='%i')
    
    它输出此图像:

    并将其发送到控制台:

    (32, 32, 3)
    (32, 32)
    
    并将变量“segments”写入文件“segments.txt”。文件内容如下所示:

    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1
    0 0 0 0 0 0 0 0 0 0 0 0 2 2 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1
    0 0 0 0 0 0 0 0 0 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1
    0 0 0 0 0 0 0 0 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1
    0 0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5 5 5 5 5 5
    4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5
    4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5
    4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5
    4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5
    
    如您所见,变量“segments”的大小与输入图像的大小相同。 但是段[i,j]的每个值表示图像的像素[i,j]属于哪个簇。

    您读过吗?哪一部分还不清楚?