Page 1 of 1

Convert TIFF to gray scale while preserving transparency ?

Posted: 2011-07-01T09:46:20-07:00
by homer314
Hi, i'm trying to convert colored tiffs images with transp. backgrounds to graysscale tiffs preserving their alpha channel (background).

I tried lots of combinations (IM 6.7.0-9 compiled from source with standard config) found in this forum but i get allways white background instated of transparent

Is it possibile ? Thank's!

Re: Convert TIFF to gray scale while preserving transparency

Posted: 2011-07-01T09:58:55-07:00
by fmw42
what was your exact command(s) that you tried? can you post a link to an example image that has this problem? that way others can test it or see if there is a problem with the file -- or at least confirm your problem.

The problem may be that TIFFs support two kinds of transparency, background and alpha channel. IM can handle only one and has probably chosen the wrong one. This is a know problem. But if you post a link I can look at it.

Re: Convert TIFF to gray scale while preserving transparency

Posted: 2011-07-01T10:05:14-07:00
by homer314
fmw42 wrote:what was your exact command(s) that you tried? can you post a link to an example image that has this problem? that way others can test it or see if there is a problem with the file -- or at least confirm your problem.

The problem may be that TIFFs support two kinds of transparency, background and alpha channel. IM can handle only one and has probably chosen the wrong one. This is a know problem. But if you post a link I can look at it.
Really thank's for the reply.

This is an example input

http://www.sisteco.it/downloads/test.tif

i tried for example

Code: Select all

convert input -type grayscalematte out
or

Code: Select all

convert -verbose input -channel RGBA -matte -colorspace gray out
Again, really thank's

Re: Convert TIFF to gray scale while preserving transparency

Posted: 2011-07-01T11:13:04-07:00
by fmw42
this works for me fine on IM 6.7.0.9 Q16 Mac OSX Tiger. In this case your image has no background transparency but has an alpha channel, which IM finds.


convert test.tif -colorspace gray test2.tif

identify -verbose test2.tif
Image: test2.tif
Format: TIFF (Tagged Image File Format)
Class: DirectClass
Geometry: 413x413+0+0
Resolution: 72x72
Print size: 5.73611x5.73611
Units: PixelsPerInch
Type: GrayscaleMatte
Base type: Grayscale
Endianess: MSB
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 8-bit
alpha: 8-bit
Channel statistics:
Gray:
min: 205 (0.803922)
max: 255 (1)
mean: 232.263 (0.910835)
standard deviation: 24.8974 (0.0976368)
kurtosis: -1.96696
skewness: -0.181776
Alpha:
min: 0 (0)
max: 255 (1)
mean: 115.285 (0.452099)
standard deviation: 126.694 (0.496839)
kurtosis: -1.96025
skewness: -0.192486
Alpha: rgba(255,255,255,0) #FFFFFF00

Re: Convert TIFF to gray scale while preserving transparency

Posted: 2011-07-04T01:33:54-07:00
by homer314
fmw42 wrote:this works for me fine on IM 6.7.0.9 Q16 Mac OSX Tiger. In this case your image has no background transparency but has an alpha channel, which IM finds.


convert test.tif -colorspace gray test2.tif

identify -verbose test2.tif
Image: test2.tif
Format: TIFF (Tagged Image File Format)
Class: DirectClass
Geometry: 413x413+0+0
Resolution: 72x72
Print size: 5.73611x5.73611
Units: PixelsPerInch
Type: GrayscaleMatte
Base type: Grayscale
Endianess: MSB
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 8-bit
alpha: 8-bit
Channel statistics:
Gray:
min: 205 (0.803922)
max: 255 (1)
mean: 232.263 (0.910835)
standard deviation: 24.8974 (0.0976368)
kurtosis: -1.96696
skewness: -0.181776
Alpha:
min: 0 (0)
max: 255 (1)
mean: 115.285 (0.452099)
standard deviation: 126.694 (0.496839)
kurtosis: -1.96025
skewness: -0.192486
Alpha: rgba(255,255,255,0) #FFFFFF00

Hi, i tried but i get white BG instead of transparent on output

This is the identify log

Format: TIFF (Tagged Image File Format)
Class: DirectClass
Geometry: 413x413+0+0
Resolution: 72x72
Print size: 5.73611x5.73611
Units: PixelsPerInch
Type: GrayscaleMatte
Base type: Grayscale
Endianess: MSB
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 8-bit
alpha: 8-bit
Channel statistics:
Gray:
min: 205 (0.803922)
max: 255 (1)
mean: 232.263 (0.910835)
standard deviation: 24.8974 (0.0976368)
kurtosis: -1.96696
skewness: -0.181776
Alpha:
min: 0 (0)
max: 255 (1)
mean: 115.285 (0.452099)
standard deviation: 126.694 (0.496839)
kurtosis: -1.96025
skewness: -0.192486
Alpha: rgba(255,255,255,0) #FFFFFF00
Colors: 17
Histogram:
76665: (205,205,205,255) #CDCDCD rgba(205,205,205,1)
104: (205,205,205,160) #CDCDCDA0 rgba(205,205,205,0.627451)
96: (205,205,205,240) #CDCDCDF0 rgba(205,205,205,0.941176)
96: (205,205,205, 16) #CDCDCD10 rgba(205,205,205,0.0627451)
80: (205,205,205, 64) #CDCDCD40 rgba(205,205,205,0.25098)
64: (205,205,205,192) #CDCDCDC0 rgba(205,205,205,0.752941)
64: (205,205,205,128) #CDCDCD80 rgba(205,205,205,0.501961)
64: (205,205,205, 32) #CDCDCD20 rgba(205,205,205,0.12549)
60: (205,205,205, 48) #CDCDCD30 rgba(205,205,205,0.188235)
56: (205,205,205,224) #CDCDCDE0 rgba(205,205,205,0.878431)
56: (205,205,205,208) #CDCDCDD0 rgba(205,205,205,0.815686)
40: (205,205,205,144) #CDCDCD90 rgba(205,205,205,0.564706)
40: (205,205,205,112) #CDCDCD70 rgba(205,205,205,0.439216)
40: (205,205,205, 80) #CDCDCD50 rgba(205,205,205,0.313725)
24: (205,205,205, 96) #CDCDCD60 rgba(205,205,205,0.376471)
16: (205,205,205,176) #CDCDCDB0 rgba(205,205,205,0.690196)
93004: (255,255,255, 0) #FFFFFF00 rgba(255,255,255,0)
Rendering intent: Undefined
Interlace: None
Background color: white
Border color: rgba(223,223,223,1)
Matte color: grey74
Transparent color: none
Compose: Over
Page geometry: 413x413+0+0
Dispose: Undefined
Iterations: 0
Compression: LZW
Orientation: TopLeft
Properties:
date:create: 2011-07-04T10:30:25+02:00
date:modify: 2011-07-04T10:30:25+02:00
signature: e5601daf3ef80f14cc21d5e880423641a668fc70e1dff07ae408abd731169114
tiff:alpha: unassociated
tiff:document: out.tif
tiff:endian: lsb
tiff:photometric: min-is-black
tiff:rows-per-strip: 9
Artifacts:
verbose: true
Tainted: False
Filesize: 10.6KBB
Number pixels: 171KB
Pixels per second: 17.06MB
User time: 0.000u
Elapsed time: 0:01.009
Do i need another step to convert a channel to transparent ?

Really Thank's

Re: Convert TIFF to gray scale while preserving transparency

Posted: 2011-07-04T10:28:31-07:00
by fmw42
did you try my suggestion of:

convert test.tif -colorspace gray test2.tif

or

convert test.tif -channel rgba -alpha on -colorspace gray test3.tif


which both worked for me. How are you viewing it? If in PS, your image does not have background transparency, so you won't see the transparency as it is an alpha channel. Try other viewers or just display in your browser.

Re: Convert TIFF to gray scale while preserving transparency

Posted: 2011-07-05T02:13:12-07:00
by homer314
fmw42 wrote:did you try my suggestion of:

convert test.tif -colorspace gray test2.tif

or

convert test.tif -channel rgba -alpha on -colorspace gray test3.tif


which both worked for me. How are you viewing it? If in PS, your image does not have background transparency, so you won't see the transparency as it is an alpha channel. Try other viewers or just display in your browser.
i'm using Adobe Fireworks to view outputs. Original file as transparent BG in this viewer.

using convert test.tif -channel rgba -alpha on -colorspace gray test3.tif this is the output

http://www.sisteco.it/downloads/out.tif

Thank's

Re: Convert TIFF to gray scale while preserving transparency

Posted: 2011-07-05T10:26:51-07:00
by fmw42
It looks fine in my viewers. See my comments about Adobe PS and other viewer handling of background and alpha transparencies. Adobe viewers do not show alpha channel transparency in the display, only background transparency. Your image has only alpha channel transparency. Choose channels to see that the alpha channel is there. Your base image is yellow circle on white background with an alpha channel to make the white transparent. In Adobe viewers all you will see in the display is the yellow on white. You have to choose channels to see that there is an alpha channel listed, but it will not show as transparent.

Display it in IM or some other non-Adobe viewer, which shows alpha channel transparency rather than background transparency.

Re: Convert TIFF to gray scale while preserving transparency

Posted: 2011-07-05T15:17:02-07:00
by homer314
fmw42 wrote:It looks fine in my viewers. See my comments about Adobe PS and other viewer handling of background and alpha transparencies. Adobe viewers do not show alpha channel transparency in the display, only background transparency. Your image has only alpha channel transparency. Choose channels to see that the alpha channel is there. Your base image is yellow circle on white background with an alpha channel to make the white transparent. In Adobe viewers all you will see in the display is the yellow on white. You have to choose channels to see that there is an alpha channel listed, but it will not show as transparent.

Display it in IM or some other non-Adobe viewer, which shows alpha channel transparency rather than background transparency.
you're right, it works!

Really really really thank's for the help !