Issue
I have made a couple of images which I need for a CNN using matplotlib. But I would like to read only the base of the image (without the axis and the whitespace), because I found out that my CNN which uses keras and tensordlow reads the whole image (meaning that the numbers on the axis have a big impact on the prediction). Any ideas on how can I do that?
Note that I already have an image with the axis and the whitespace. I am just wondering how can I edit them out.
This is the full image:
And this is what I need to use:
Solution
You have to crop the images, because they already have the axis and whitespace on them.
Firtstly resize them to same dimensions:
from PIL import Image
image = Image.open('sunset.jpg')
print(f"Original size : {image.size}") # 5464x3640
sunset_resized = image.resize((400, 400))
sunset_resized.save('sunset_400.jpeg')
Than crop them (link to code explanation-https://www.geeksforgeeks.org/python-pil-image-crop-method/):
from PIL import Image
# Opens a image in RGB mode
im = Image.open(r"C:\Users\Admin\Pictures\network.png")
# Setting the points for cropped image
left = 155
top = 65
right = 360
bottom = 270
# Cropped image of above dimension
# (It will not change original image)
im1 = im.crop((left, top, right, bottom))
# Shows the image in image viewer
im1.show()
Answered By - gasper_thebeast101
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.