I have one image, and I have another image that I would like to resize to the size of the first image in python. I've attempted this in many different ways, all resulting in failure. How can I do this?
Some failed methods:
.thumbnail(), only works for a PIL image, which means it can't interact with SimpleCV images later on in the program
.resize(), when I used the arguments, it resulted in the error.
Alternate Solution:
Setting camera resolution, though I have no idea how to do this.
As the camera was the only object with an unknown size, I was able to set it like the following:
cam = camera(prop_set ={'width':width, height:'height'})
Related
I am trying to detect leaves diseases in an image using image processing.But becasue of my loading images are too big and it's not fit in to screen. So I resized my images. Then when I am trying to detect green colour objects in an each and every image, I always getting 0 as a value. Is it possible to affect the resizing an image to this issue? Thanks in advance
If you run this once:
cv2.namedWindow("your_win_name",cv2.WINDOW_NORMAL)
cv2.resizeWindow("your_win_name",your_win_width,your_win_height)
Whenever you call cv2.imshow with that window name, it will show the whole image in that window. So you don't need to resize it.
cv2.imshow("your_win_name",image)
If it doesn't detect on full image either, then problem is something else.
I use python pillow to do a easy gif image reverse,but I found that the image has become more size(10m) than before(1m). Anyone know how to make it?
And here is my code:
from PIL import Image, ImageSequence
from PIL import ImagePalette
with Image.open('sd.gif') as im:
if im.is_animated:
frames = [f.copy() for f in ImageSequence.Iterator(im)]
frames.reverse()
frames[0].save('out.gif', save_all=True, append_images = frames[1:])
I can't tell for sure without examining the actual images, but I can guess what likely happened:
Some gifs are optimized with a method that finds pixels in each frame where nothing is changing (or changing only very slightly) from frame to frame, and make them transparent instead of storing the color for each pixel, to reduce the amount of data. For some gifs with large static areas in many consecutive frames this can be very efficient way to reduce file size.
When you are reversing the GIF, the frames must be unoptimized first, otherwise there would be transparent areas without any data. This can increase file size quite a bit. The difference may vary from one image to another.
You probably can solve this by running some gif optimization algorithm after the new image is created.
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 want to change size of GIF animation image using python and PIL or PythonMagick. I can't find solution. PIL and thumbnail method works for jpg and png but not for gif. ImageMagick has command mogrify/convert -resize '1280x1024>' but i can't find documentation and i don't know how to do it with pythonmagick.
Anyone knows solution?
In the worst case i use os/subprocess and convert ;-S
Thanks.
You can use PIL and images2gif, a short PIL based module linked to on this blog page, and available here. Code used to process this rose.gif is below. I set the images2gif.readGif 'read as numpy array' property to false in order to get a list of PIL images so as I could use the PIL thumbnail function.
Orignial: Processed:
import Image
import images2gif
frames = images2gif.readGif("rose.gif",False)
for frame in frames:
frame.thumbnail((100,100), Image.ANTIALIAS)
images2gif.writeGif('rose99.gif', frames)
I'm not sure how to preserve transparency, my attempts to do so have failed (so far).
Some amazing person made an updated version of images2gif.py that accounts for transparency:
https://bitbucket.org/bench/images2gif.py/overview
There are still some artifacts, but it's way better than the original!
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.