<jupyter_start><jupyter_text>Image Augmentation DemoThis shows a demo of image augmentation and the resulting images. It creates one without augmentation and one with augmentation to show the difference.<jupyter_code>from glob import glob
from hyperspectral_image_generator import hyperspectral_image_generator, hyperspectral_image_generator_jp2
import matplotlib.pyplot as plt
# variables
path_to_images = './images_for_notebook'
batch_size = 4
class_indices = {'AnnualCrop': 0, 'Forest': 1, 'HerbaceousVegetation': 2, 'Highway': 3}
no_augmentation_parameters = {'flip': False,
                            'zoom': 1.0,
                            'shift': 0.0,
                            'rotation': 0.0,
                            'sheer': 0.0,
                            'noising': None}
augmentation_parameters = {'flip': True,
                            'zoom': 1.2,
                            'shift': 0.1,
                            'rotation': 10.0,
                            'sheer': 0.01,
                            'noising': None}
image_files = glob(path_to_images + "/**/*.tif")
print(image_files)
noaug_image_generator = hyperspectral_image_generator(image_files, class_indices,
                                                batch_size=batch_size,
                                                image_mean='image_mean_std.txt',
                                                rotation_range=no_augmentation_parameters['rotation'],
                                                horizontal_flip=no_augmentation_parameters['flip'],
                                                vertical_flip=no_augmentation_parameters['flip'],
                                                speckle_noise=no_augmentation_parameters['noising'],
                                                shear_range=no_augmentation_parameters['sheer'],
                                                scale_range=no_augmentation_parameters['zoom'],
                                                transform_range=no_augmentation_parameters['shift']
                                                )
aug_image_generator = hyperspectral_image_generator(image_files, class_indices,
                                                batch_size=batch_size,
                                                image_mean='image_mean_std.txt',
                                                rotation_range=augmentation_parameters['rotation'],
                                                horizontal_flip=augmentation_parameters['flip'],
                                                vertical_flip=augmentation_parameters['flip'],
                                                speckle_noise=augmentation_parameters['noising'],
                                                shear_range=augmentation_parameters['sheer'],
                                                scale_range=augmentation_parameters['zoom'],
                                                transform_range=augmentation_parameters['shift']
                                                )
# No augmentation case
data = next(noaug_image_generator)
images = data[0]
print(images.shape)
fig, axs = plt.subplots(1, 4, figsize=(10, 3))
for idx, ax in enumerate(axs):
    ax.imshow(images[idx, :, :, 1], cmap='gray')
    ax.axis('off')
plt.show()
images[idx, :, :, 1]
# Augmentation case
data = next(aug_image_generator)
images = data[0]
print(images.shape)
fig, axs = plt.subplots(1, 4, figsize=(10, 3))
for idx, ax in enumerate(axs):
    ax.imshow(images[idx, :, :, 1], cmap='gray')
    ax.axis('off')
plt.show()<jupyter_output>(4, 64, 64, 13)<jupyter_text>Extraction from tilesThe JP2 generator avoids the problems with the above generator by sampling directly from the Satellite tiled images. It takes an input with the folder containing the JP2 images and a shape file that contains centroids of the data points. The image shows an example from fields surrounding Orange river, South Africa. Source from https://zindi.africa<jupyter_code>class_indices_column = 'Crop_Id_Ne'
shape_file = "./shape_file/train_reprojected_centroid.shp"
path_to_images = './data_jp2'
image_files = glob(path_to_images + "/*.jp2")
batch_size = 4
augmentation_parameters = {'flip': True,
                            'zoom': 1.2,
                            'shift': 0.1,
                            'rotation': 10.0,
                            'sheer': 0.01,
                            'noising': 0.001}
print(image_files)

jp2_image_generator = hyperspectral_image_generator_jp2(image_files, shape_file, class_indices_column,
                                                batch_size=batch_size,
                                                image_mean='jp2_image_mean_std.txt',
                                                rotation_range=augmentation_parameters['rotation'],
                                                horizontal_flip=augmentation_parameters['flip'],
                                                vertical_flip=augmentation_parameters['flip'],
                                                speckle_noise=augmentation_parameters['noising'],
                                                shear_range=augmentation_parameters['sheer'],
                                                scale_range=augmentation_parameters['zoom'],
                                                transform_range=augmentation_parameters['shift'],
                                                crop_size=[96,96]
                                                )
# JP2 case
data = next(jp2_image_generator)
images = data[0]
print(images.shape)
fig, axs = plt.subplots(1, 4, figsize=(10, 3))
for idx, ax in enumerate(axs):
    ax.imshow(images[idx, :, :, 1], cmap='gray')
    ax.axis('off')
plt.show()<jupyter_output>c:\users\laptomon\anaconda3\envs\tensorflow\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
{'fraction_non_alphanumeric': 0.08737546954107464, 'fraction_numerical': 0.014208721215090642, 'mean_word_length': 1.599320882852292, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 62, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '117504', 'license': 'MIT', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1422, 'n_words': 307, 'path': 'image_augmentation_demo.ipynb', 'repo_name': 'mabdelhack/hyperspectral_image_generator', 'size': '6123'}