xxxxxxxxxx
# Extracting color channels
red_array = img_array[:, :, 0]
blue_array = img_array[:, :, 1]
green_array = img_array[:, :, 2]
# Flipping image array in all dimensions
flipped_img = np.flip(img_array)
# Flip specified dimensions
# axis 0 is row, axis 1 is column, axis 2 is channel or color
flipped_img2 = np.flip(img_array, axis=(0, 1)) # Flip only column and row
# Transpose image dimensions
# Transposing will swap dimensions
transposed_img = np.transpose(img_array, axes=(1, 0, 2)) # Swapping first and second dimension
# Split image channels
splitting_parts = 3
dimension_index_to_split = 2
red_array, green_array, blue_array = np.split(img_array, splitting_parts, axis=dimension_index_to_split)
red_array = red_array.reshape((3, 3))
# Stacking color channels to create rgb image
new_dimension_index = 2
stacked_rgb = np.stack([red_array, green_array, blue_array], axis=2)
# Show image
plt.imshow(img_array)
plt.show()
xxxxxxxxxx
def normalize_images(images):
# initial zero ndarray
normalized_images = np.zeros_like(images.astype(float))
# The first images index is number of images where the other indices indicates
# hieight, width and depth of the image
num_images = images.shape[0]
# Computing the minimum and maximum value of the input image to do the normalization based on them
maximum_value, minimum_value = images.max(), images.min()
# Normalize all the pixel values of the images to be from 0 to 1
for img in range(num_images):
normalized_images[img, ] = (images[img, ] - float(minimum_value)) / float(maximum_value - minimum_value)
return normalized_images
# encoding the input images. Each image will be represented by a vector of zeros except for the class index of the image
# that this vector represents. The length of this vector depends on number of classes that we have
# the dataset which is 10 in CIFAR-10