TIFF copy alpha channel from one image to another

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Misko78
Posts: 10
Joined: 2016-02-13T15:05:36-07:00
Authentication code: 1151

TIFF copy alpha channel from one image to another

Post by Misko78 »

Hello everyone and sorry for asking maybe a stupid question.

I'm using a Vuescan program to scan my negatives, and negfix8 script to remove orange mask. Vuescan saves infrared scan of a negative for purposes of dust and scratch removal. It does that by saving IR scan as an alpha channel. RAW scan that Vuescan makes is in fact RGB 16bit TIFF image plus 16bit grayscale image as a alpha channel.

By using negfix8 script you lose alpha channel in new TIFF file. Is there any way to copy alpha channel from initial TIFF scan file to new TIFF.

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: TIFF copy alpha channel from one image to another

Post by fmw42 »

What version of Imagemagick are you using and what platform? Always provide that when asking questions, since syntax may differ

Can you post your input TIFF file that has the alpha channel or the RGB image and a separate alpha channel image to some place such as dropbox.com and put the URL here. I am not really sure I understand where you have the alpha channel that you want to put in another image.

If you have a tiff with RGB and alpha as input, then in unix syntax

Code: Select all

convert new.tif \( input.tif -channel a -separate +channel \) -alpha off -compose copy_opacity -composite new.tif
for windows

Code: Select all

convert new.tif ( input.tif -channel a -separate +channel ) -alpha off -compose copy_opacity -composite new.tif
Misko78
Posts: 10
Joined: 2016-02-13T15:05:36-07:00
Authentication code: 1151

Re: TIFF copy alpha channel from one image to another

Post by Misko78 »

Thank you for a superfast response :D

I use ImageMagick 6.9.2-3 Q16 x64

This is a link to my dropbox folder with two files (i've lowered resolution to 600dpi because originals are over 100MB):
https://www.dropbox.com/sh/v0u2w9pnmgvr ... HGg1a?dl=0

P_scan0006.tif - file created with negfix8 script (https://sites.google.com/site/negfix/) without alpha channel
scan0006.tif - RAW scan from Vuescan program.

I need to transfer alpha channel from scan0006.tif to P_scan0006.tif.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: TIFF copy alpha channel from one image to another

Post by fmw42 »

You have not answered my question. What platform are you on? Syntax differs.

The other image from the google site has many different sizes. But what relevance does it have to the other two files?

Did you try my commands above for your platform?

EDIT:

This works for me (unix syntax)

Code: Select all

convert -quiet P_scan0006.tif \( scan0006.tif -channel a -separate +channel \) -alpha off -compose copy_opacity -composite P_scan0006_alpha.tif
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: TIFF copy alpha channel from one image to another

Post by snibgo »

For dust and scratches, which are very small things, you might provide cropped versions of the large files rather than resized. The crops can be very small, provided they are representative.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: TIFF copy alpha channel from one image to another

Post by fmw42 »

see my EDIT above
Misko78
Posts: 10
Joined: 2016-02-13T15:05:36-07:00
Authentication code: 1151

Re: TIFF copy alpha channel from one image to another

Post by Misko78 »

ahh, I use Windows 7, was tired last night and misunderstood you. I posted google link as a reference to a script used, don't mind images there.

When i use command above i get this:

Image

and i need it like this:

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: TIFF copy alpha channel from one image to another

Post by fmw42 »

If you are on windows, then try

Code: Select all

convert -quiet P_scan0006.tif ( scan0006.tif -channel a -separate +channel ) -alpha off -compose copy_opacity -composite P_scan0006_alpha.tif
When I process your images, the result looks fine (no dither pattern).
http://www.fmwconcepts.com/misc_tests/a ... _alpha.tif

If this is not what you want, then it is something other than a simple transfer of alpha channels. So please explain further or provide and example of two input images and the resulting output image.

What is your version of Imagemagick and your version of libtiff
Misko78
Posts: 10
Joined: 2016-02-13T15:05:36-07:00
Authentication code: 1151

Re: TIFF copy alpha channel from one image to another

Post by Misko78 »

I've updated Imagemagick to 6.9.3-4 Q16 x64 and my libtiff is 3.8.2 (gnuwin32 http://gnuwin32.sourceforge.net/packages/tiff.htm)

When i open your file in Photoshop i don't see separate alpha channel only dithered image, when i open it in any pic viewer i see image normally.

Yes i need simple transfer of alpha channel from one image to another and to maintain it as a separate alpha channel.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: TIFF copy alpha channel from one image to another

Post by fmw42 »

You need to specify the type of alpha you want in your command line. Try this (windows syntax)

Code: Select all

convert -quiet P_scan0006.tif ( scan0006.tif -channel a -separate +channel ) -alpha off -compose copy_opacity -composite -define tiff:alpha=unassociated P_scan0006_alpha_u.tif
Misko78
Posts: 10
Joined: 2016-02-13T15:05:36-07:00
Authentication code: 1151

Re: TIFF copy alpha channel from one image to another

Post by Misko78 »

Still no luck, maybe it has something to do because when you do the command it makes layer 0 instead of background layer.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: TIFF copy alpha channel from one image to another

Post by fmw42 »

Can you send an example TIFF of the format you want it to have. We need to understand better what you want. The file I generated above had one layer and 4 channels (RGB and separate alpha). When I open it in PS (CS), it has one layer (background) and 4 channels red, green, blue, alpha 1. What is wrong with that?

If the above does not work, try

Code: Select all

convert -quiet P_scan0006.tif ( scan0006.tif -channel a -separate +channel ) -alpha off -compose copy_opacity -composite -define tiff:alpha=unspecified P_scan0006_alpha_us.tif
or

Code: Select all

convert -quiet P_scan0006.tif ( scan0006.tif -channel a -separate +channel ) -alpha off -compose copy_opacity -composite -define tiff:alpha=associated P_scan0006_alpha_a.tif
But I think those will produce the same result as before with the dither-like pattern.
Misko78
Posts: 10
Joined: 2016-02-13T15:05:36-07:00
Authentication code: 1151

Re: TIFF copy alpha channel from one image to another

Post by Misko78 »

fmw42 wrote:Can you send an example TIFF of the format you want it to have. We need to understand better what you want. The file I generated above had one layer and 4 channels (RGB and separate alpha). When I open it in PS (CS), it has one layer (background) and 4 channels red, green, blue, alpha 1. What is wrong with that?
That is exactly what i need. But when i used that command again i got dithered image.

It finally worked for me with this command:

Code: Select all

convert -quiet P_scan0006.tif ( scan0006.tif -channel a -separate +channel ) -alpha off -compose copy_opacity -composite -define tiff:alpha=unspecified P_scan0006_alpha_us.tif
Thank you so much. :D For you time, knowledge and patience!!!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: TIFF copy alpha channel from one image to another

Post by fmw42 »

I think somewhere along the way, Adobe changed the meaning of unassociated and unspecified. I get different results than you.
Post Reply