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
1 Answers
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. I.e. 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)

- 2,242
- 2
- 25
- 42
-
Its in same way as you wrote. I have .bmp files, 320 image slice makes a 3d object. but if i have only one object then i think i need to create patches(as you said, make more example from original image by splitting it). I want to train a network well by having more objects. I have tried but i didn't find a way how to do this in python. – Ali Mar 06 '21 at 12:00
-
Its in same way as you wrote. I have .bmp files, 320 image slice makes a 3d object. but if i have only one object then i think i need to create patches(as you said, make more example from original image by splitting it). I want to train a network well by having more objects. I have tried but i didn't find a way how to do this in python @QuinnFreedman – Ali Mar 11 '21 at 08:46