<jupyter_start><jupyter_text>Image Reading - Generally Used for Gray Image<jupyter_code>import numpy as np
from PIL import Image 
img = Image.open('./Image/lena.png') 
img_array=np.array(img,dtype=np.uint8)
print(img_array)
print(img_array.shape)
# Output Images 
img.show() 
img_array = img_array.astype(np.uint8)
img=Image.fromarray(img_array)

img.save("Image/lenaDup.png")<jupyter_output>[[162 162 162 ... 170 155 128]
 [162 162 162 ... 170 155 128]
 [162 162 162 ... 170 155 128]
 ...
 [ 43  43  50 ... 104 100  98]
 [ 44  44  55 ... 104 105 108]
 [ 44  44  55 ... 104 105 108]]
(512, 512)<jupyter_text>Image Reading - Used for Realtime Images<jupyter_code>import numpy as np
import cv2 
img = cv2.imread('./Image/lena.png') 
img_array=np.array(img,dtype=np.float32)
print(img_array)
print(img_array.shape)

# Output img with window name as 'image' 
cv2.imshow('image', img)  
  
# Maintain output window utill 
# user presses a key 
cv2.waitKey(0)         
  
# Destroying present windows on screen 
cv2.destroyAllWindows()<jupyter_output>[[[162. 162. 162.]
  [162. 162. 162.]
  [162. 162. 162.]
  ...
  [170. 170. 170.]
  [155. 155. 155.]
  [128. 128. 128.]]

 [[162. 162. 162.]
  [162. 162. 162.]
  [162. 162. 162.]
  ...
  [170. 170. 170.]
  [155. 155. 155.]
  [128. 128. 128.]]

 [[162. 162. 162.]
  [162. 162. 162.]
  [162. 162. 162.]
  ...
  [170. 170. 170.]
  [155. 155. 155.]
  [128. 128. 128.]]

 ...

 [[ 43.  43.  43.]
  [ 43.  43.  43.]
  [ 50.  50.  50.]
  ...
  [104. 104. 104.]
  [100. 100. 100.]
  [ 98.  98.  98.]]

 [[ 44.  44.  44.]
  [ 44.  44.  44.]
  [ 55.  55.  55.]
  ...
  [104. 104. 104.]
  [105. 105. 105.]
  [108. 108. 108.]]

 [[ 44.  44.  44.]
  [ 44.  44.  44.]
  [ 55.  55.  55.]
  ...
  [104. 104. 104.]
  [105. 105. 105.]
  [108. 108. 108.]]]
(512, 512, 3)<jupyter_text>Image Reading - Used for showing using Matplotlib<jupyter_code>import numpy as np
import matplotlib.image as Image
import matplotlib.pyplot as plt 
img = Image.imread('./Image/image.png') 
img_array=np.array(img,dtype=np.float32)
#print(img_array)
#print(img_array.shape)
# Output Images 
plt.imshow(img)<jupyter_output><empty_output><jupyter_text>Image Reading - Used for ML and NN<jupyter_code>import numpy as np
from keras.preprocessing import image
import matplotlib.pyplot as plt 
img = image.load_img('./Image/image.png', target_size=(64, 64))
img_array=np.array(img,dtype=np.float32)
#print(img_array)
#print(img_array.shape)
# Output Images 
plt.imshow(img)<jupyter_output>Using TensorFlow backend.<jupyter_text>Negation of the Image- Subtracting pixel values from maximum pixel value<jupyter_code>import numpy as np
from PIL import Image

img = Image.open("./Image/boat.png")

img_array=np.array(img,dtype=np.float32)

img_array[:,:] =255-img_array[:,:]

img_array = img_array.astype(np.uint8)

img=Image.fromarray(img_array)

img.save("./Image/boatNegative.png")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16929945054945056, 'fraction_numerical': 0.14732142857142858, 'mean_word_length': 3.0798319327731094, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '326375', 'license': 'MIT', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1176, 'n_words': 292, 'path': 'Python/3. Image Processing/Image.ipynb', 'repo_name': 'shoaibrayeen/Data-Science', 'size': '2912'}