簡體   English   中英

從 3d 圖像創建補丁以進行訓練

[英]Create patches from 3d images for training

我有 (320x1280x1280) 320 個圖像切片。 我想訓練網絡但數據有限,為此我需要從原始圖像創建圖像補丁,以便我可以有效地訓練網絡。 我如何在 python 中做到這一點? 以及解決此問題的其他最佳方法是什么。 謝謝

為了很好地回答這個問題,我需要更多信息:圖像是什么格式的? 圖像補丁到底是什么意思? 通過修補圖像,您的目標是什么? 你已經嘗試了什么? 為什么它不起作用?

也就是說,我要做一些假設。 我假設“補丁”是指將圖像分成更小的圖塊,並將每個子部分視為自己的圖像。 即,您希望將 go 從 320 個 1280x1280 圖像轉換為 81920 個 80x80 圖像,其中每個圖像都是原始圖像之一的一小部分。 另外,我假設圖像是 numpy arrays,因為你說你在 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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM