简体   繁体   English

从 3d 图像创建补丁以进行训练

[英]Create patches from 3d images for training

I have (320x1280x1280) 320 image slices.我有 (320x1280x1280) 320 个图像切片。 I want to train network but have limited data, For this i need to create image patches from original images so that i can effectively train the network.我想训练网络但数据有限,为此我需要从原始图像创建图像补丁,以便我可以有效地训练网络。 How i can do it in python?我如何在 python 中做到这一点? and what could be any other best way to solve this issue.以及解决此问题的其他最佳方法是什么。 Thank you谢谢

To answer this question well, I would need a lot more information: what format are the images in?为了很好地回答这个问题,我需要更多信息:图像是什么格式的? What exactly do you mean by image patches?图像补丁到底是什么意思? What is your goal by patching the images?通过修补图像,您的目标是什么? What have you already tried?你已经尝试了什么? Why isn't it working?为什么它不起作用?

That said, I'm going to make some assumptions.也就是说,我要做一些假设。 I'm assuming that by "patches" you mean dividing the image up into smaller tiles and treating each sub-section as it's own image.我假设“补丁”是指将图像分成更小的图块,并将每个子部分视为自己的图像。 Ie you want to go from 320 1280x1280 images to, say, 81920 80x80 images where each image is a small section of one of the original images.即,您希望将 go 从 320 个 1280x1280 图像转换为 81920 个 80x80 图像,其中每个图像都是原始图像之一的一小部分。 Also, I'll assume that the images are numpy arrays since you said you are working in python.另外,我假设图像是 numpy arrays,因为你说你在 python 工作。

In that case, you could use np.split .在这种情况下,您可以使用np.split Unfortunately, np.split seems to only work in one dimension at a time, so you would have to do something like this:不幸的是, 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