Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 17071

Custom cropping function in ImageDatagenerator

$
0
0

I need to Crop a square shape around a Centre point (x,y) and I try to create my custom function below.

from PIL import Imagedef Crop_Image(image):    cropsize = 224    croplength = cropsize/2    x = Xcentre    y = Ycentre    image_crop = image.crop((x-croplength, y-croplength, x+croplength, y+croplength))    return image_crop

Then passing Crop_Image function in to the Imagedatagenerator.

datagen = ImageDataGenerator(rescale=1./255,                             validation_split=0.2,                             rotation_range=0.2,                             width_shift_range=0.2,                             height_shift_range=0.2,                             shear_range=0.2,                             zoom_range=0.2,                             horizontal_flip=True,                             fill_mode='nearest',                             preprocessing_function=Crop_Image)

but in the training process, I have got some error.

AttributeError: 'numpy.ndarray' object has no attribute 'crop'

How can I solve this error?


Viewing all articles
Browse latest Browse all 17071

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>