Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageDataGenerator for 3D images #2939

Closed
josejimenezluna opened this issue Jun 9, 2016 · 4 comments
Closed

ImageDataGenerator for 3D images #2939

josejimenezluna opened this issue Jun 9, 2016 · 4 comments

Comments

@josejimenezluna
Copy link

Hi,

Does the ImageDataGenerator work on 3d images (5 dimensional array (n_samples, channels, x, y, z)) as well? I looked at the source code and I'm not sure if this is the case.

def random_rotation(x, rg, row_index=1, col_index=2, channel_index=0,
                    fill_mode='nearest', cval=0.):
    theta = np.pi / 180 * np.random.uniform(-rg, rg)
    rotation_matrix = np.array([[np.cos(theta), -np.sin(theta), 0],
                                [np.sin(theta), np.cos(theta), 0],
                                [0, 0, 1]])

    h, w = x.shape[row_index], x.shape[col_index]
    transform_matrix = transform_matrix_offset_center(rotation_matrix, h, w)
    x = apply_transform(x, transform_matrix, channel_index, fill_mode, cval)
    return x
@joelthchao
Copy link
Contributor

ImageDataGenerator doesn't work on 3d images. It only takes 4d array as input.

@fchollet
Copy link
Member

But it would be reasonably easy to reimplement for 3D data a subset of the operations done by ImageDataGenerator.

@dhuy228
Copy link

dhuy228 commented Sep 27, 2019

@Hawk31 hey mate, I just customised the Keras' ImageDataGenerator for medical image analysis applications, i.e. 3D Dicom slices (10,32,32,32,1). It might help with your problem.

https://github.com/dhuy228/augmented-volumetric-image-generator/blob/master/generator.py

@Mcitrin
Copy link

Mcitrin commented Oct 17, 2019

@dhuy228

could you give an example how how your calling your custom ImageDataGenerator

im trying to do a similar thing using .nii files generated from a number of dicom slices

the shape of the array of patches in (1000,32,32,32) (num patches, x, y, z) and i re shaped it to be (1000, 32, 32, 32, 1) the script seems augmenting my image array properly but it dosn't augment the labels accordingly

im nt sure what i need to do to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants