简体   繁体   中英

Create patches from 3d images for training

I have (320x1280x1280) 320 image slices. 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? 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. Also, I'll assume that the images are numpy arrays since you said you are working in python.

In that case, you could use np.split . Unfortunately, np.split seems to only work in one dimension at a time, so you would have to do something like this:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM