Commit aa290799 authored by Kishore Bandi's avatar Kishore Bandi

Upload New File

parent fbb85170
{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# # example of zoom image augmentation\n",
"# from numpy import expand_dims\n",
"# from keras.preprocessing.image import load_img\n",
"# from keras.preprocessing.image import img_to_array\n",
"# from keras.preprocessing.image import ImageDataGenerator\n",
"# from matplotlib import pyplot"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# # load the image\n",
"# img = load_img('./1.png')\n",
"# # convert to numpy array\n",
"# data = img_to_array(img)\n",
"# # expand dimension to one sample\n",
"# samples = expand_dims(data, 0)\n",
"# # create image data augmentation generator\n",
"# datagen = ImageDataGenerator(zoom_range=[0.5,1.0])\n",
"# # prepare iterator\n",
"# it = datagen.flow(samples, batch_size=1)\n",
"# # generate samples and plot\n",
"# for i in range(9):\n",
"# \t# define subplot\n",
"# \tpyplot.subplot(330 + 1 + i)\n",
"# \t# generate batch of images\n",
"# \tbatch = it.next()\n",
"# \t# convert to unsigned integers for viewing\n",
"# \timage = batch[0].astype('uint8')\n",
"# \t# plot raw pixel data\n",
"# \tpyplot.imshow(image)\n",
"# # show the figure\n",
"# pyplot.show()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"from keras.preprocessing.image import ImageDataGenerator\n",
"\n",
"datagen = ImageDataGenerator(\n",
" rotation_range=40,\n",
" width_shift_range=0.2,\n",
" height_shift_range=0.2,\n",
" rescale=1./255,\n",
" shear_range=0.2,\n",
" zoom_range=0.2,\n",
" horizontal_flip=True,\n",
" fill_mode='nearest')"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img\n",
"\n",
"datagen = ImageDataGenerator(\n",
" rotation_range=40,\n",
" width_shift_range=0.2,\n",
" height_shift_range=0.2,\n",
" shear_range=0.2,\n",
" zoom_range=0.2,\n",
" horizontal_flip=True,\n",
" fill_mode='nearest')\n",
"\n",
"img = load_img('./1.png') # this is a PIL image\n",
"x = img_to_array(img) # this is a Numpy array with shape (3, 150, 150)\n",
"x = x.reshape((1,) + x.shape) # this is a Numpy array with shape (1, 3, 150, 150)\n",
"\n",
"# the .flow() command below generates batches of randomly transformed images\n",
"# and saves the results to the `preview/` directory\n",
"i = 0\n",
"for batch in datagen.flow(x, batch_size=1,\n",
" save_to_dir='./', save_prefix='cervix', save_format='png'):\n",
" i += 1\n",
" if i > 20:\n",
" break # otherwise the generator would loop indefinitely"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment