<jupyter_start><jupyter_text>Interactive Break: Arrays  Learning Outcomes- Numpy Arrays: Bracket Operator [ ]- Matplotlibs figure/imshow/title/colorbar- itk.imread, itk.GetArrayFromImage- RGB images  Bracket Operator [ ]You can use the bracket operator [ ] to access certain parts of the image:* numpy_array[5,5,5] accesses the array at the point z=5, y=5, x=5.* numpy_array[5,5,:] accesses the array at z=5, y=5, x= xmin to xmax (everything in x)* numpy_array[:] accesses the whole array* numpy_array[10:13, 5, 5] accesses the array at z=10 to 13 (i.e. 10,11,12 – 13 is exclusive!), y=5, x=5<jupyter_code>import matplotlib.pyplot as plt 
%matplotlib notebook
import numpy as np

# initialize a empty 200 x 200 arrays with zeros
initials_array = np.zeros((200,200))

# assign (arbitrary) values to certain subregions. note, the first index affects y, the second does x!
# initial_arrays[from_y:to_y, from_x:tox]
initials_array[20:40, 60:140] = 1
initials_array[20:160, 140:160] = 2
initials_array[160:180, 60:160] = 3
initials_array[120:180, 60:80] = 4

# plot 2D image
plt.figure()
plt.imshow(initials_array)
plt.title('Funny-colored J')
plt.colorbar()
plt.show()<jupyter_output><empty_output><jupyter_text>--- TASK: Create a image showing the initial letter of your name using the bracket-operator [ ]. Use 'blocky' letters, do not try to make diagonal entries. If you end up with one of the letters M, N, V, W, or Z, please use another letter.---<jupyter_code># initialize a empty 200 x 200 arrays with zeros
initials_array = np.zeros((200,200))

# assign values to certain subregions
initials_array[...] = 1  #TODO
initials_array[...] = 2 #TODO


# plot 2D image
plt.figure()
plt.imshow(initials_array)
plt.colorbar()<jupyter_output><empty_output><jupyter_text>Reading ImagesImage of various formats can be read with itk.imread and converted to a ITKImage to a numpy array with itk.GetArrayFromImage. --- TASK: Please read in the picture with the path 'iekm_picture.jpg' using the function itk.imread---<jupyter_code>import itk
# read in image as itkImageObject and convert it to a numpy array
itk_image = #TODO: read image
numpy_iekm_image = itk.GetArrayFromImage(itk_image)

print('numpy_iekm_image has the shape: %d (y) %d (x) %d (color)' % numpy_iekm_image.shape)

plt.figure()
plt.imshow(numpy_iekm_image)
plt.title('IEKM')<jupyter_output><empty_output><jupyter_text>ThresholdingShort repetition: Images are made out of numbers which we interpret in a certain way. Thresholding is the method of asking 'Which pixel in the image are greater/smaller than a (threshold) value?'. The output of the threshold is a binary mask, i.e., a image where each pixel indicate if the "threshold question" is true/false.  TASK:Create a binary mask which indicates values greater than 0.5 in the array initials_array. You can write comparisons e.g. with image  .<jupyter_code>binary_initial_mask = ... #TODO: threshold initials_array > 0.5

plt.figure()
plt.subplot(121)
plt.imshow(initials_array)
plt.title('Funny-colored J')

plt.subplot(122)
plt.imshow(binary_initial_mask.astype(np.uint8))
plt.title('Binary Mask of Funny-colored J')<jupyter_output><empty_output><jupyter_text>The created mask can now be used to manipulate other images. TASK:Try to manipulate colors in the  numpy_iekm_image  with the binary mask you created, so that the letter is clearly visible, see examples below. Use arithmic operations (+ - / *) to manipulate the color values directly.![manipulation_example.png](attachment:manipulation_example.png)Hint: you can use the mask directly in the bracket operator. Your image has 3 dimensions [y,x,c], with c being the color (c=0,1,2 being red, green, blue, respectively. If you have a 2 dimensional mask [y,x], you can use your mask to index the first two dimensions and an additional index to access the data you want. So, for example, if you'd like to increase the red channel in your image using the two-dimensional mask, you can use:image[mask, 0] = image[mask, 0] * 1.1<jupyter_code># reload the image
numpy_iekm_image = itk.GetArrayFromImage(itk.imread('iekm_picture.jpg'))


numpy_iekm_image[...] = ... #TODO: use the binary_initial_mask to manipulate red, green, and blue of the image
# numpy_iekm_image[...] = ...
# numpy_iekm_image[...] = ...

# clip/limit values between 0 and 255
numpy_iekm_image = np.clip(numpy_iekm_image, a_min=0, a_max=255)

plt.figure()
plt.imshow(numpy_iekm_image)
plt.title('Letter + IEKM')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10281627179257935, 'fraction_numerical': 0.029280286097451945, 'mean_word_length': 5.26750700280112, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '419297', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1462, 'n_words': 523, 'path': 'InteractiveBreak_Arrays/InteractiveBreak_Arrays.ipynb', 'repo_name': 'JoeGreiner/MorphologicalOperatorsDemo', 'size': '4474'}