【问题标题】:Create patches from 3d images for training从 3d 图像创建补丁以进行训练
【发布时间】:2021-06-03 11:53:41
【问题描述】:

我有 (320x1280x1280) 320 个图像切片。我想训练网络但数据有限,为此我需要从原始图像创建图像补丁,以便我可以有效地训练网络。我怎么能在python中做到这一点?以及解决此问题的其他最佳方法是什么。谢谢

【问题讨论】:

    标签: image 3d vision


    【解决方案1】:

    要很好地回答这个问题,我需要更多信息:图像是什么格式的?图像补丁到底是什么意思?通过修补图像,您的目标是什么?你已经尝试了什么?为什么它不起作用?

    也就是说,我要做一些假设。我假设“补丁”是指将图像分成更小的图块,并将每个子部分视为自己的图像。 IE。您想从 320 个 1280x1280 图像变为 81920 个 80x80 图像,其中每个图像都是原始图像的一小部分。另外,我假设图像是 numpy 数组,因为你说你在 python 中工作。

    在这种情况下,您可以使用np.split。不幸的是,np.split 似乎一次只能在一个维度上工作,所以你必须这样做:

    import numpy as np
    
    # imagine this is your image data
    images = np.zeros((320,1280,1280), dtype=np.uint8)
    
    
    # this is a helper function that wraps around np.split and makes sure
    # the data is returned in the same format it started in
    def split(array, n, axis):
        # split the array along the given axis, then re-combine
        # the splits into a np array
        array = np.array(np.split(array, n, axis=axis))
        # flatten the array back into the right number of dimensions
        return np.reshape(array, [-1] + list(array.shape[2:]))
        
    
    # divide each image into 16x16=256 smaller images
    # (this will only work if the images dimensions are divisible by num_splits
    num_splits = 16
    patches = split( split(images, num_splits, 1), num_splits, 2 )
    print(patches.shape)
    # > (81920, 80, 80)
    

    【讨论】:

    • 和你写的一样。我有 .bmp 文件,320 个图像切片制作了一个 3d 对象。但是如果我只有一个对象,那么我认为我需要创建补丁(如您所说,通过拆分原始图像来制作更多示例)。我想通过拥有更多对象来很好地训练网络。我已经尝试过,但我没有找到如何在 python 中执行此操作的方法。
    • 和你写的一样。我有 .bmp 文件,320 个图像切片制作了一个 3d 对象。但是如果我只有一个对象,那么我认为我需要创建补丁(如您所说,通过拆分原始图像来制作更多示例)。我想通过拥有更多对象来很好地训练网络。我已经尝试过,但我没有找到如何在 python @QuinnFreedman 中做到这一点
    猜你喜欢
    • 2017-07-26
    • 2021-03-27
    • 1970-01-01
    • 2017-12-07
    • 2012-11-05
    • 2017-07-09
    • 2017-07-15
    • 1970-01-01
    • 2017-08-26
    相关资源
    最近更新 更多