I was doing a course which taught data science; it had a portion on using NumPy arrays for image inversion. It's able to invert jpg, but isn't able to invert PNG, I tried other images with the same extension, it doesn't work on those which have "png" extension (it only shows a transparent image).
What can be the problem? Thank you!
from PIL import Image
from IPython.display import display
#displaying the image
img = Image.open(r"./download.png")
display(img)
#converting the image into an array
imgArray = np.array(img)
imgArrayShape = imgArray.shape
#inverting the image
fullArray = np.full(imgArrayShape, 255)
invertedImageArray = abs(fullArray - imgArray)
invertedImageArray = invertedImageArray.astype(np.uint8)
#displaying the inverted image
invertedImage = Image.fromarray(invertedImageArray)
display(invertedImage)