How is transparent background removed from a TIFF file in Python - python-3.x

I have a situation where I need to convert TIFF files to JPEG files in Python. I am using the PIL library to do this and it works fine unless the TIFF has a transparent background on it and then PIL can't open the file and says it is not recognized. Are there other solutions to this in Python?

TIFF format files usually consist of multiple images of different resolutions. Try reading with openslide
Eg:
patch = openslide.OpenSlide(img_path)
patch = patch.read_region((17800,19500), 0, (256, 256))
For more info visit openslide documentation

Related

Extract small regions from a PIL image python

enter image description here
I have a PIL image in python as shown and I want to extract each of the small red regions separately into a jpeg format. So from this file, I'm expecting file1.jpg, file2.jpg, etc.
How can I obtain each sub-regions in each different file?
PIL doesn't really excel at that. I would consider using:
OpenCV findContours(), or
scikit-image regionprops(), or
ImageMagick Connected Components, or
Python wand bindings to ImageMagick as above

How to convert multi-page tiff to jpeg, using python

I am trying to batch process images, in which I need to convert some multi-page tiff files to individual jpeg images, I tried with PIL library of Python but sadly PIL only supports conversion of a single page, in this case the first page in TIFF files.

Python / PIL - Raw RGB565 data to PNG?

I have raw RGB565 data as a bytes-like object and I want to save it as a PNG.
Although it is possible with libraries such as PyQt5, as you can here:
QtGui.QImage(data, width, height, QtGui.QImage.Format_RGB16)
I would like to use only PIL, but I cannot find a way to do this with only PIL.
More generally, a method that does not involve Qt would be fine.
Thanks.
It so happens that the pypng repository has a tool to convert from Kobo's 15-bit to PNG.
It's here: https://github.com/drj11/pypng/blob/master/code/kobo565topng
One word of warning however, it outputs an 8-bit RGB PNG.
You don't save any space by saving it as an R5G6B5 PNG, so that might not matter much.

flatten images with transparency in PDF

How to flatten images in PDF files with transparency?
convert PDF to PS (postscript)
pdftops input.pdf output.pdf.ps
If a PDF file contains eg. PNG files with alpha channel (transparency) the PDF is rendered/rasterized to an image and that is not a solution because then you lose the plain text in the file
Is there a tool (linux command line) to flatten images in PDF files with transparency?
Its not clear why you want to do this. If you want PostScript then Ghostscript can produce PostScript for you from a PDF file (use the ps2write device). Obviously transparency will have to be rendered to an image, in which case the resolution is important. The default is 720 dpi which is probably higher than you might need.
Note that a PDF file can't contain a PNG, that's not a possible image type in PDF. A PNG would have to be stored as an image with a separate alpha.

Imagemagick auto create duplicate file

I downloaded the icon file from http://www.freeiconsweb.com/favicon.ico. I try to convert ico file to png as below : -
im.convert(['favicon.ico', '-format', '16x16+0+0', 'favicon.png'], function (err, stdout, stderr) {
});
Result :
It's create two png file for me. favicon-0.png and favicon-1.png.
Correct result:
It should be create one file only that is favicon.png.
Anyone know about the why imagemagick create two file ?
An ico file can contain multiple images, a png cannot, so ImageMagick makes a png for each image in the ico file.
From the Wikipedia page (emphasis mine):
The ICO file format is an image file format for computer icons in Microsoft Windows. ICO files contain one or more small images at multiple sizes and color depths, such that they may be scaled appropriately.
To get only a single image, you'd have to specify which one you want. For help with that, see the (command line) documentation on reading particular frames of an image.

Resources