tiff alpha/transparency channel - utility to scan files for its presence?

Don't know where to start, or stuck on a certain problem? Drop by and tell us about it. Feel like helping others? Start here.

Moderator: peterZ

Post Reply
b0bcat
Posts: 49
Joined: 30 Nov 2012, 21:37
Number of books owned: 0
Country: UK

tiff alpha/transparency channel - utility to scan files for its presence?

Post by b0bcat »

Is there a free tool for MS Windows (preferred) or maybe Linux, Debian 10 Stable that can act in batch mode to find those tiff files in a folder whose headers/metadata indicate the presence of an alpha (transparency) channel (by which I mean the channel that can be removed manually by e.g. in GIMP opening menu item Layer, then Transparency, and selecting Remove Alpha Channel)? My objective is to avoid manually opening and checking very many files to see if there is an alpha channel present (and to be removed) which may be the root cause of the problem indicated below.

Background:
I've encountered a problem using djvu small v.0.4.4 to encode as DjVu a large number of greyscale tif files output by ScanTailor Advanced v.1.0.14 and in a large minority of cases later edited with GIMP v.2.8.18.
Basically djvu small when commanded to encode the selected tiffs pauses a moment and then states nothing encoded (or words to that effect).
As I can't find any logs in its install folder or the usual admin type places (Windows 7) and the Windows Event Viewer logs are silent I thought I would try encoding the same files using DjVuSolo 3.1 (happy twentieth birthday year!) - as I suspected the issue might be presence of alpha channel in the files I had edited in GIMP. After doing its thing for some seconds it announced: "Error: SamplesPerPixel==2. Only values of 1,3, and 4 are supported." Without researching it I don't know what that means but some time ago when I encountered that error I found removing the alpha channel (where present) fixed it so I assume the same thing applies this time (and also possibly to djvu small).

PS: if anyone has found any troubleshooting info on djvu small regarding this or more generally it would be helpful to see it posted/linked; on my last deep dive I couldn't immediately find anything.
cday
Posts: 445
Joined: 19 Mar 2013, 14:55
Number of books owned: 0
Country: UK

Re: tiff alpha/transparency channel - util to scan files for its presence?

Post by cday »

I have very little experience with transparency but a quick online search has produced these two linked command line methods of detecting, and if required possibly removing, an alpha channel in an image:

Detect Alpha Channel with ImageMagick

Imagemagick: remove alpha component (replace all intermediate alpha pixel with solid pixel)

ImageMagick as you may know is a very powerful and widely used command line tool for image processing, and undoubtedly has its own support forum.

I'm more familiar with XnView.com's NConvert command line utility, but checking the help file quickly I don't see the existing alpha operations providing a means of detecting or removing alpha. However, if you are not in too much of a hurry, Pierre the developer is quite responsive, so if you make a request on the forum he might add those to the existing supported alpha operations.

Or maybe someone else can help with your request?

Edit:

As I said I'm not very familiar with transparency, but it has occurred to me that XnView.com's excellent cross-platform batch processing GUI software XnConvert might be able to batch process a folder of files to remove alpha where present using the 'Change color depth' action, you could easily test that...
dpc
Posts: 379
Joined: 01 Apr 2011, 18:05
Number of books owned: 0
Location: Issaquah, WA

Re: tiff alpha/transparency channel - utility to scan files for its presence?

Post by dpc »

What might work is just batch all of the TIFF files through an image converter to an image format that doesn't contain an alpha channel, then convert them back from that intermediate format to TIFF. I don't have any recommendations for a command line image converter (I just use Photoshop for everything), but converting to 24-bpp Windows BMP would certainly drop the alpha channel.

This brute-force method would of course also unnecessarily process the TIFF files that didn't have an alpha channel, but I wouldn't think that you'd lose anything in the round-trip conversion process if you used an intermediary 24-bpp format?
cday
Posts: 445
Joined: 19 Mar 2013, 14:55
Number of books owned: 0
Country: UK

Re: tiff alpha/transparency channel - utility to scan files for its presence?

Post by cday »

There is more to this than is initially apparent as the TIFF format itself doesn't support alpha, neither the word 'alpha' nor 'transparency' appear in Wikipedia's comprehensive description of the official format:

Wikipedia - TIFF

However, this link does refer to a multlayer version of the TIFF format that was introduced in Adobe Photoshop:

"A tiff does not officially support transparency (Photoshop introduced a multi-layered tiff format at some point), but does support alpha channels. This alpha channel is present in the channel palette, and can be used to generate a layer mask, for example."

No doubt there is further information available online, if required.

Your aim ideally would be to not only identify troublesome files, but also presumably to convert them into a standard TIFF so that all source files could then be processed using the same procedure?

In that case, any workflow in which you could load all source TIFFs, without needing to identify whether they have alpha, that converts them to standard TIFF files would meet your overall need? The only consideration might be if the source TIFFs used JPEG rather than a lossless compression method and were then recompressed with a possible theoretical loss of quality, in practice probably only a second or third order consideration.

While any of the above conversion suggestions might work, the only way to be sure would be to test each; I can imagine, for example, that in practice some at least of the tools mentioned above might decline to open a non-standard TIFF variant. If GIMP supports batch processing, maybe opening them and then resaving them as a standard TIFF (or if necessary an intermediate format such as PNG) would provide a good solution.
b0bcat
Posts: 49
Joined: 30 Nov 2012, 21:37
Number of books owned: 0
Country: UK

Re: tiff alpha/transparency channel - utility to scan files for its presence?

Post by b0bcat »

Thanks for replies.

Success!

I installed
https://imagemagick.org/download/binari ... 64-dll.exe

-without selecting extra install options or adding program to path.

Multiple web searches then ensued, including:

https://www.imagemagick.org/script/escape.php
%A :: image transparency channel enabled (true/false)

Having reviewed them and after numerous attempts at using variants of Windows batch files, I then located myself in the program directory and ran:

magick identify -format "%A\n" D:\Scan\*.tif >>D:\Scan\doc\logfile.txt

(without the \n you get a text file full of the word Undefined, without carriage returns or paragraph breaks, so unless you know what you are looking for as an exception you can hardly see one).

This produces a list of outputs which are nearly all described in the logfile as
Undefined
but it found three files with
Blend
which when opened in GIMP show a transparency layer - I removed it.

Seeing also
https://www.imagemagick.org/script/escape.php
-format %[opaque] :: CALCULATED: is image fully-opaque?

I then ran:

magick identify -format %[opaque]\n D:\Scan\*.tif >> D:\Scan\doc\logfile2.txt
which confirmed all without transparency.

Having edited out the alpha channel layer from the affected files in GIMP I then submitted the tiffs to DjVuSmall and this time it worked. I also tried the same files in DjVuSolo and it worked also.

The real time sink was searching for a means of batch processing with IM in Windows 7 - as you'll have noted from the above examples, in the event it turned out to be needless, because a simple wildcard worked in this version of IM. The problem is that when you search for this material you get endless forum discussions about problems affecting an array of different versions and platforms going back over one or two decades and none of the Windows batch files I found worked. (I think it was this issue which - perhaps unjustly - turned me off IM when I first encountered it around 2005). See e.g.
https://superuser.com/questions/1126551 ... subfolders

Incidentally, while I was searching before my initial post, I also came across this program :
"ImBatch – The Best in Batch Image Processing"

https://www.highmotionsoftware.com/help ... ilter_task
"Get_HasAlphaChannel_B - Returns 1, if current image has an alpha channel and 0 - if hasn't. "

I didn't install the program but it looks promising; I emailed the developers asking if they could confirm if this means specifically the alpha (transparency) channel being the one which can be removed in GIMP as I noted in my opening post. If I hear back and if it adds anything, I'll update.
cday
Posts: 445
Joined: 19 Mar 2013, 14:55
Number of books owned: 0
Country: UK

Re: tiff alpha/transparency channel - utility to scan files for its presence?

Post by cday »

Glad you have found a solution that suits you, but I wonder if there mightn't have been a more direct overall solution avoiding the need to test whether or not a given file had an alpha channel.

I started computing with Windows 3.11, and with a couple of very trivial exceptions never used DOS, and certainly never expected to use the command line regularly.

When I started working with images in a history archive project I saw the potential of creating batch files and started using NConvert, a very steep learning curve with initially a lot of trial and error usually required to get a batch file to work as the command line is very unforgiving. I later had a quick look at ImageMagick which certainly supports a very wide range of operations, but coming from NConvert found it limiting and harder to use.
Post Reply