import numpy as np
r = np.random.rand(500, 500)
from matplotlib import pyplot as plt, cm
plt.imshow(r, cmap=cm.gray, interpolation='nearest')

"""
Explanation: Introduction: images are numpy arrays
A grayscale image is just a 2D array:
End of explanation
"""


from skimage import data
coins = data.coins()
print(type(coins))
print(coins.dtype)
print(coins.shape)
plt.imshow(coins, cmap=cm.gray, interpolation='nearest')

"""
Explanation: Trying that with a real picture:
End of explanation
"""


lena = data.lena()
print(lena.shape)
plt.imshow(lena, interpolation='nearest')

"""
Explanation: A color image is a 3D array, where the last dimension has size 3 and represents the red, green, and blue channels:
End of explanation
"""


lena[100:200, 100:200, :] = [255, 0, 0] # [red, green, blue]
plt.imshow(lena)

"""
Explanation: These are just numpy arrays. Making a red square is easy using just array slicing and manipulation:
End of explanation
"""


def draw_h(image, coords, in_place=True):
    pass # code goes here

"""
Explanation: As we will see, this opens up many lines of analysis for free.
Exercise: draw an H
Define a function that takes as input an RGB image and a pair of coordinates (row, column), and returns the image (optionally a copy) with green letter H overlaid at those coordinates. The coordinates should point to the top-left corner of the H.
The arms and strut of the H should have a width of 3 pixels, and the H itself should have a height of 24 pixels and width of 20 pixels.
End of explanation
"""


lena_h = draw_h(lena, (50, -50), in_place=False)
plt.imshow(lena_h)

"""
Explanation: Test your function like so:
End of explanation
"""


def plot_intensity(image, row):
    pass # code goes here

"""
Explanation: Bonus points: RGB intensity plot
Plot the intensity of each channel of the image along some row.
End of explanation
"""


plot_intensity(coins, 50)
plot_intensity(lena, 250)

"""
Explanation: Test your function here:
End of explanation
"""


