I am trying to use python pillow package to enlarge picture and here is my try
from PIL import Image
image = Image.open('Sample.jpg')
new_image = image.resize((1080, 1080))
new_image.save('Output.jpg')
The code is working but the output image loses completely the ratio. How can I enlarge the image without losing the quality?
What you're talking about is image upscaling, which is a more complex problem just than enlarging the image. I recommend looking into image upscaling packages. A lot of them use CNNs for this.
Related
I have an image that I need to enlarge and enhance its quality for better reading
I tried the following using Pillow to resize the image but I still can't read it well
from PIL import Image
img = Image.open('Sample.jpg')
resized_img = img.resize((2450, 3283))
resized_img.save('Output.png')
Here's a sample of the image
I have an image of 300*300 pixels size and want to convert it into 1500*1500 pixels size using python. I need this because i have to georeferenced this image with 1500*1500 pixel raster image. Any python library function or basic fundamental how to do this are welcome.
You should try using Pillow (fork of PIL = Python Image Library)
Simple like this:
from PIL import Image
img = Image.open("my_image.png")
img.resize((1500, 1500, ))
img.save("new_image.png")
I have an image in JPEG which contains a solid black circle on top of a solid black inverted equilateral triangle.
Upon application of Python PIL Image class, function thumbnail, resizing from 500*500 to 100*100 the shape of the image components change from (circle+triangle) to (rectangle+rectangle), almost looks like the android icon now.
Any ideas why this is happening? I'm guessing this is an algorithm issue.
Here's the code:
im = Image.open('E:/asdsa/aret/sdfssdf/media/edasdaas1d0-1.jpeg')
im.thumbnail((100,100), Image.ANTIALIAS)
im.save('E:/asdsa/aret/sdfssdf/media/11.jpeg')
Try
im.save('E:/asdsa/aret/sdfssdf/media/11.jpeg', quality=90)
Anyway, it's better to use Pillow.
Also, for solid colors jpeg format might not be the best choice. PNG is a better solution.
I am using the following code to resize an image using PIL
img = Image.open("in.png")
resized = ImageOps.fit(img, (200, 200), method=Image.ANTIALIAS)
resized.save("out.png")
But the output image colors look very different. Here they are for comparison, the big one is the original:
What's even stranger is that when I open them using the image viewer in ubuntu, they look the same. But not in Windows or MacOS.
The larger image is using the Adobe RGB color profile. It is omitted from the smaller image, which means the color correction system will use some default (probably sRGB), which likely has a smaller gamut. This will cause the colors to appear duller.
Solution 1: Create the original image using sRGB instead of Adobe RGB.
Solution 2: Copy the color profile from the larger image to the smaller image.
Most Linux systems do not support color correction, at least not on the same scope that OS X or Windows do. So the fact that they appear the same in Ubuntu's image viewer is really a limitation of the image viewer program, which is unable to understand color profiles.
I am trying to increase the height of an image using PIL but I don't want the image to be resized; I actually want a strip of blank pixels at the bottom of the image. Any way of doing this with PIL?
I guess one way would be to make a new image of the required size and copy the old image into it but I can't seem to find the right function to do this.
Oops, just realized you can do image.crop() and it will resize the image for you.