<jupyter_start><jupyter_text>img_to_array will take PIL Image instance and turn it into a numpy array, with dtype float32. If you start from a PNG image, the values inside the image will lie between 0 and 255. This is usually represented by an 8-bit unsigned integer; img_to_array however will cast to float.<jupyter_code># Keras provides the img_to_array() function for converting a loaded image in PIL format into a NumPy array 
# for use with deep learning models. The image is convertated into t [height, width, channels]

# # Arguments
#         img: PIL Image instance.
#         data_format: Image data format,
#             either "channels_first" or "channels_last".
#         dtype: Dtype to use for the returned array.
# Returns: A 3D Numpy array.

# The component values are often stored as integer numbers in the range 0 to 255, 
# the range that a single 8-bit byte can offer,


img_array = img_to_array(img)
print(img_array.dtype)
print(img_array.shape)

print(img_array)

# converting into 0 - 1, This is called as Normalization will help you to remove distortions 
# caused by lights and shadows in an image.
img_array /= 255
print('\n-----------------------------------------------------')
print(img_array)

# convert back to image
print('\n-----------------------------------------------------')
img_pil = array_to_img(img_array)
print(type(img_pil))<jupyter_output>float32
(50, 50, 3)
[[[209. 101. 135.]
  [206.  99. 142.]
  [194. 103. 142.]
  ...
  [207.  91. 127.]
  [211. 104. 141.]
  [205. 106. 144.]]

 [[213. 114. 144.]
  [210. 136. 170.]
  [209. 101. 140.]
  ...
  [219. 123. 157.]
  [216. 126. 163.]
  [206.  97. 136.]]

 [[209. 101. 136.]
  [212.  91. 122.]
  [206.  97. 127.]
  ...
  [221. 124. 160.]
  [218. 112. 147.]
  [206.  84. 121.]]

 ...

 [[147.  94. 137.]
  [149.  88. 135.]
  [114.  70. 121.]
  ...
  [186.  97. 140.]
  [187. 123. 157.]
  [172. 121. 158.]]

 [[120.  67. 120.]
  [138.  85. 134.]
  [103.  60. 107.]
  ...
  [202. 150. 173.]
  [177. 135. 170.]
  [169.  72. 111.]]

 [[150. 118. 146.]
  [188. 154. 190.]
  [224. 194. 213.]
  ...
  [166.  70. 114.]
  [193. 102. 137.]
  [215. 154. 181.]]]
[[[0.81960785 0.39607844 0.5294118 ]
  [0.80784315 0.3882353  0.5568628 ]
  [0.7607843  0.40392157 0.5568628 ]
  ...
  [0.8117647  0.35686275 0.49803922]
  [0.827451   0.40784314 0.5529412 ]
  [0.8039216  0.41568628 0.5647059 ]]

 [[0.8352941[...]
{'fraction_non_alphanumeric': 0.1907949790794979, 'fraction_numerical': 0.20627615062761506, 'mean_word_length': 2.093143596377749, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '636897', 'license': 'MIT', 'n_tokens_mistral': 1268, 'n_tokens_neox': 891, 'n_words': 301, 'path': 'Image_Conversion_Try1.ipynb', 'repo_name': 'hkyopreston/BreastCancer_MachineLearning', 'size': '2390'}