Sorry for my english but it's not my first language.
I would like to create a program that:
- Transform a jpeg or png image into an array (very important: I would like an array composed only of the values that the pixels of the image have and not metadata or other information. Where I can select each specific pixel of the image).
- Save this array in a txt file.
- Transform this array composed of only the pixel values of the image back into jpg or png image and save it in a file.
Requests:
- Is the array I created with the program I wrote composed only of the pixel values of the image? is there also metadata or other information?
- Is this a valid way to remove metadata from an image?
- Is this a valid way to create the array representing that image pixel by pixel?
- Is this a valid way to convert png images to jpeg or jpeg to png?
Thank you!
This is the program I created, any opinion?
import numpy as np
from PIL import Image
import sys
img_data = Image.open("imagea.jpeg")
img_arr = np.array(img_data)
np.set_printoptions(threshold=sys.maxsize)
print(img_arr.shape)
new_img = Image.fromarray(img_arr)
new_img.save("imageb.jpeg")
print("Image saved!")
file = open("file1.txt", "w+")
content = str(img_arr)
file.write(content)
file.close()
print("Finished!")