I wrote a pure python TIFF G4 decompress for use with tifffile.py. I know there are ways to add libtiff to a custom PIL, but I never could get that working very well in a mixed virtualenv. I want to manipulate the image in PIL. I am looking for pointers in hooking my decompressor to stock PIL for TiffImagePlugin.py.
Any ideas?
It appears that TiffImagePlugin does not easily allow me to hook in additional decompressors. Replacing TiffImageFile._decoder with a dictionary of decoders might work, but you would have to examine and test each release of PIL to ensure it hasn't broken. This level of maintenance is just as bad as a custom PIL. I appreciate the design of tifffile.py for using a dictionary of decoders. It made it very easy.
Final solution? I couldn't hook my code into PIL. I had to use PIL.Image.fromarray() to using my decompressed images.
Related
I try to find way for compressing images(PNG as an example) with any S3TC/DXT algorithm using python libraries.
As I can see in Pillow(PIL) library DDS format in Read-only formats section. Therefore Pillow can't be used for this purpose.
Searching in google didn't give positive results.
Question:
Is it possible to do with python?
Could someone please provide link to libraries with such functional?(which is checked on practice)
DDS format is not mandatory for my case. I need only compressed file.
PS:
It's required for creating textures for future use.
Library should support different algorithms of compression.
You could use Python Wand. Here I create a pseudo image with a magenta-yellow gradient and save as DDS:
from wand.image import Image
with Image(width=200, height=80, pseudo='gradient:magenta-yellow') as img:
img.save(filename='result.dds')
Or, if you want to load a PNG file and save as DDS:
with Image(filename='input.png') as img:
img.save(filename='result.dds')
I'm trying to write a Python script that loads a jpeg file, rotates the image by 90 degrees, and then saves the result at about the same level of compression as the original. I've looked at the documentation at https://pillow.readthedocs.org/en/latest/reference/ImageFile.html, but don't see any way to control the size/quality of the output file.
Do you know the incoming quality? Which functions are you using? I just jumped over to the docs and the save function takes a named parameter "quality".
http://pillow.readthedocs.org/en/latest/handbook/image-file-formats.html
If you are looking for lossless rotation, you should not use Pillow. There is jpegtran program. It is part of libjpeg and libjpeg-progs package in Ubuntu.
We got 50TB of 16bit uncompressed TIF images from a industrial sensor in our server, and we want to compress them all with lossless zip compression using python. Using python because it's easier to use Python to communicate our database.
However after hours of search and documentation reading, I found that there's not even a matured python library that can convert 16bit TIF into zip compressed tif. The latest PIL cannot write compressed tif, OpenCV hardcoded output file into LZW tif not zip(deflate). And there is no sufficient documentation in smc.freeimage, PythonImageMagick so I don't know if they can do it. I also found this tifffile.py, there seems something about compression in its source code, but there is no example code that let me understand how to config compression option for output.
Of course I can use an external executable, but I just don't want to use python as scripting language here.
So that I really appreciate if anyone give me an efficient example here, thanks.
Update:
cgohlke's code works, here I provide another light weight solution.
Checkout the patched pythontifflib code from here https://github.com/delmic/pylibtiff.
The original PythonTiffLib from google code doesn't handle RGB information well and it didn't work on my data, this patched version works, however because the code is very old, it implies PythonTiffLib may be not maintained very well.
Use the code like this:
from libtiff import TIFF
tif = TIFF.open('Image.tiff', mode='r')
image = tif.read_image()
tifw = TIFF.open('testpylibtiff.tiff', mode='w')
tifw.write_image(image, compression='deflate', write_rgb=True)
PythonMagick works for me on Windows:
from PythonMagick import Image, CompressionType
im = Image('tiger-rgb-strip-contig-16.tif')
im.compressType(CompressionType.ZipCompression)
im.write("tiger-rgb-strip-contig-16-zip.tif")
Scikit-image includes a wrapper for the FreeImage library:
import skimage.io._plugins.freeimage_plugin as fi
im = fi.read('tiger-rgb-strip-contig-16.tif')
fi.write(im, 'tiger-rgb-strip-contig-16-zip.tif',
fi.IO_FLAGS.TIFF_ADOBE_DEFLATE)
Or via tifffile.py, 2013.11.03 or later:
from tifffile import imread, imsave
im = imread('tiger-rgb-strip-contig-16.tif')
imsave("tiger-rgb-strip-contig-16-zip.tif", im, compress=6)
These might not preserve all other TIFF tags or properties but that wasn't specified in the question.
What is the most efficient way in terms of speed to access the pixel data of a PIL image from a C extension? I only need read-only access to it, if that makes a difference.
C-level bindings for PIL are available, but there is very little documentation for them. You will need to consult the source for usage information.
Besides C extension, you can try numpy. It takes a bit to learn though. To get started, check Convert RGBA PNG to RGB with PIL , and http://effbot.org/zone/pil-numpy.htm .
In my experience, numpy performance is great if the code is properly written. Processing image data can still be slow using C extension. But numpy uses SIMD instructions such as SSE2, which dramatically improves operation such as histogram elevating or alpha blending.
I'm trying to convert a batch of .ICO images over to .PNG images in Python. I have quite a few images to go through so I'd like to find a programmatic solution. I've tried using PIL but I can't seem to get the images and transparency to come out correctly.
I'd prefer to use Python but if it can't be done another language or library would also help.
See http://code.google.com/p/casadebender/wiki/Win32IconImagePlugin
It's a PIL plugin that makes it handle Windows icons properly.
If it's just a batch job, why not just use imagemagick?