Page 1 of 1

Problem with converting .TIF to .JPEG

Posted: 2011-08-04T08:14:42-07:00
by mniuser
Hi Everyone,

I am just trying to convert a set of .TIF file to .JPEG...in this process I am facing some problems....Request your help.

Problem 1 --> Images with white background are getting converted to black background.
Problem 2 --> For some Images. two output files are being generated instead of one (one being just thumbnail and other one is actual file).

Command I am using is :: convert 1.tif 1.jpeg

and i have tried below options as well but no luck.

convert 1.tif -quality 100 -background white 1.jpeg


Any help would be highly appreciated, sorry if my query is very basic....I am new to ImageMagick.

Thanks
MN

Re: Problem with converting .TIF to .JPEG

Posted: 2011-08-04T09:30:10-07:00
by fmw42
Tiff can have multiple frames or resolutions. So if you just want one output image, use:

convert image.tif[0] image.jpg

Presumably this first "frame" is the full resolution one.


Some tif files have min as white rather than min as black. Post a link to your image or post the results of identify -verbose image.tif.

Also see http://www.imagemagick.org/Usage/formats/#tiff


toggle the photometric interpretation (Added IM 6.3.2-10)
-define quantum:polarity=min-is-black
-define quantum:polarity=min-is-white

Re: Problem with converting .TIF to .JPEG

Posted: 2011-08-05T07:00:39-07:00
by mniuser
Thanks a lot for your quick response... not able to share the image file...please find the results of -identify verbose below for the two TIF files for which i am facing problem to convert .

I have tried both the options '-define quantum:polarity=min-is-black' & '-define quantum:polarity=min-is-white' but no luck.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

For the Image:: APP_Fireball.tif

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Image: APP_Fireball.tif

Format: TIFF (Tagged Image File Format)

Class: DirectClass

Geometry: 491x280

Type: PaletteMatte

Endianess: MSB

Colorspace: RGB

Channel depth:

Red: 8-bits

Green: 8-bits

Blue: 8-bits

Alpha: 8-bits

Channel statistics:

Red:

Min: 0 (0)

Max: 234 (0.917647)

Mean: 47.4686 (0.186151)

Standard deviation: 90.698 (0.355678)

Green:

Min: 0 (0)

Max: 154 (0.603922)

Mean: 16.8877 (0.0662264)

Standard deviation: 41.8025 (0.163931)

Blue:

Min: 0 (0)

Max: 149 (0.584314)

Mean: 17.4056 (0.0682574)

Standard deviation: 40.9766 (0.160692)

Alpha:

Min: 255 (1)

Max: 0 (0)

Mean: 54.6354 (0.214256)

Standard deviation: 104.391 (0.409376)

Alpha: ( 0, 0, 0,255) #000000FF

Colors: 110

Histogram:

3: ( 13, 2, 2,239) #0D0202EF

107787: ( 0, 0, 0,255) none

19: ( 53, 35, 34,222) #352322DE

44: ( 60, 33, 32,210) #3C2120D2

13: (102, 54, 53,174) #663635AE

5: (107, 50, 50,164) #6B3232A4

7: (100, 58, 57,184) #643A39B8

8: ( 68, 31, 31,198) #441F1FC6

5: ( 97, 64, 62,192) #61403EC0

2: (139, 51, 53,120) #8B333578

3: (155, 61, 63,107) #9B3D3F6B

1: (187, 62, 65, 61) #BB3E413D

3: (169, 63, 65, 89) #A93F4159

5: (155, 68, 68,114) #9B444472

65: (154, 74, 73,120) #9A4A4978

9: (154, 81, 80,126) #9A51507E

1: (167, 69, 70, 95) #A745465F

1: (179, 70, 72, 79) #B346484F

2: (187, 68, 70, 65) #BB444641

10: (187, 76, 77, 69) #BB4C4D45

19: (179, 77, 78, 84) #B34D4E54

9: (188, 83, 83, 73) #BC535349

2: (191, 92, 91, 75) #BF5C5B4B

4: (180, 85, 84, 87) #B4555457

2: (183, 93, 92, 90) #B75D5C5A

6: (169, 77, 77,100) #A94D4D64

6: (170, 84, 84,105) #AA545469

1: (172, 92, 91,108) #AC5C5B6C

3: (183,120,116,116) #B7787474

1: (204, 46, 52, 23) #CC2E3417

3: (203, 53, 57, 29) #CB35391D

4: (206, 54, 59, 24) #CE363B18

17098: (213, 32, 39, 0) #D5202700

2: (213, 39, 45, 3) #D5272D03

39: (214, 39, 45, 2) #D6272D02

164: (214, 40, 46, 0) #D6282E00

13: (213, 45, 51, 6) #D52D3306

15: (214, 46, 52, 3) #D62E3403

1: (210, 43, 49, 11) #D22B310B

5: (211, 44, 50, 9) #D32C3209

102: (216, 47, 53, 0) #D82F3500

8: (215, 54, 59, 4) #D7363B04

17: (211, 51, 56, 12) #D333380C

4: (213, 53, 57, 8) #D5353908

5: (211, 58, 62, 14) #D33A3E0E

105: (217, 55, 60, 0) #D9373C00

7: (209, 50, 55, 16) #D1323710

19: (208, 56, 60, 19) #D0383C13

2: (202, 59, 63, 33) #CA3B3F21

2: (193, 60, 63, 49) #C13C3F31

11: (206, 61, 65, 28) #CE3D411C

184: (218, 63, 67, 0) #DA3F4300

10: (209, 63, 67, 22) #D13F4316

5: (198, 63, 66, 43) #C63F422B

4: (206, 69, 71, 30) #CE45471E

1: (215, 67, 71, 11) #D743470B

66: (220, 70, 74, 0) #DC464A00

2: (219, 76, 79, 6) #DB4C4F06

2: (212, 65, 69, 17) #D4414511

2: (210, 71, 73, 24) #D2474918

4: (213, 73, 76, 18) #D5494C12

124: (221, 78, 80, 0) #DD4E5000

74: (222, 86, 87, 0) #DE565700

1: (221, 91, 92, 6) #DD5B5C06

154: (223, 93, 94, 0) #DF5D5E00

2: (213, 86, 87, 26) #D556571A

1: (215, 94, 95, 26) #D75E5F1A

8: (199, 70, 72, 46) #C746482E

27: (202, 66, 69, 36) #CA424524

3: (203, 73, 75, 40) #CB494B28

2: (193, 67, 69, 53) #C1434535

5: (199, 77, 78, 49) #C74D4E31

18: (194, 73, 75, 57) #C2494B39

2: (206, 88, 89, 42) #CE58592A

11: (195, 81, 82, 60) #C351523C

3: (197, 89, 89, 61) #C559593D

1: (201, 85, 86, 51) #C9555633

1: (211, 91, 92, 34) #D35B5C22

2: (209, 96, 96, 43) #D160602B

2: (218,123,121, 40) #DA7B7928

86: (225,100,101, 0) #E1646500

93: (226,108,108, 0) #E26C6C00

63: (227,116,114, 0) #E3747200

172: (229,123,121, 0) #E57B7900

1: (198,109,107, 77) #C66D6B4D

1: (203,106,105, 64) #CB6A6940

1: (201,119,116, 78) #C977744E

2: (134, 61, 61,137) #863D3D89

1: (137, 56, 57,128) #89383980

17: (133, 67, 67,144) #85434390

7: (132, 73, 72,152) #84494898

9: (132, 80, 78,158) #84504E9E

3: (155, 89, 86,131) #9B595683

10: (132, 87, 84,165) #845754A5

57: (161,106,102,139) #A16A668B

1: (225,128,125, 21) #E1807D15

4: (199,131,127, 95) #C7837F5F

4: (219,144,140, 60) #DB908C3C

92: (230,131,128, 0) #E6838000

112: (231,139,135, 0) #E78B8700

168: (233,146,142, 0) #E9928E00

10154: (234,154,149, 0) #EA9A9500

7: (234,154,149, 1) #EA9A9501

3: (234,154,149, 4) #EA9A9504

4: (234,154,149, 8) #EA9A9508

2: (233,153,148, 15) #E999940F

1: (232,153,148, 23) #E8999417

7: (229,151,146, 34) #E5979222

4: (226,149,144, 46) #E295902E

1: (211,139,134, 76) #D38B864C

Rendering intent: Undefined

Resolution: 72x72

Units: PixelsPerInch

Filesize: 5.6e+02kb

Interlace: None

Background color: white

Border color: #DFDFDF00

Matte color: grey74

Page geometry: 491x280+0+0

Dispose: Undefined

Iterations: 0

Compression: None

Orientation: TopLeft

Signature: 0b2ef43bae6552c1e2ffc340900fede60c2ec6a07146ccca9b53e38465ea4dbf

Software: Adobe Photoshop CS3 Macintosh

Timestamp: 2007:10:26 10:53:08

Profile-iptc: 8 bytes

0x00000000: 02000002 000200a0 --------

unknown[2,0]:

Profile-xmp: 15567 bytes

<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>

<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.1-c036 46.276720, Mon Feb 19 2007 22:13:43 ">

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

<rdf:Description rdf:about=""

xmlns:xapMM="http://ns.adobe.com/xap/1.0/mm/"

xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#">

<xapMM:DocumentID>uuid:CE5744D14385DC118376DE62CD2FCE31</xapMM:DocumentID>

<xapMM:InstanceID>uuid:CF5744D14385DC118376DE62CD2FCE31</xapMM:InstanceID>

<xapMM:DerivedFrom rdf:parseType="Resource">

<stRef:instanceID>uuid:034285B84181DC11BA148B0E4AFB3FBD</stRef:instanceID>

<stRef:documentID>uuid:ECDDF6344081DC11BA148B0E4AFB3FBD</stRef:documentID>

</xapMM:DerivedFrom>

</rdf:Description>

<rdf:Description rdf:about=""

xmlns:xap="http://ns.adobe.com/xap/1.0/">

<xap:CreateDate>2007-10-26T10:53:08-04:00</xap:CreateDate>

<xap:ModifyDate>2007-10-26T10:53:08-04:00</xap:ModifyDate>

<xap:MetadataDate>2007-10-26T10:53:08-04:00</xap:MetadataDate>

<xap:CreatorTool>Adobe Photoshop CS3 Macintosh</xap:CreatorTool>

</rdf:Description>

<rdf:Description rdf:about=""

xmlns:dc="http://purl.org/dc/elements/1.1/">

<dc:format>image/tiff</dc:format>

</rdf:Description>

<rdf:Description rdf:about=""

xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">

<photoshop:ColorMode>3</photoshop:ColorMode>

<photoshop:History/>

</rdf:Description>

<rdf:Description rdf:about=""

xmlns:tiff="http://ns.adobe.com/tiff/1.0/">

<tiff:Orientation>1</tiff:Orientation>

<tiff:XResolution>720000/10000</tiff:XResolution>

<tiff:YResolution>720000/10000</tiff:YResolution>

<tiff:ResolutionUnit>2</tiff:ResolutionUnit>

<tiff:NativeDigest>256,257,258,259,262,274,277,284,530,531,282,283,296,301,318,319,529,532,306,270,271,272,305,315,33432;2666C00C29906AC9CF4175C417CAFCC1</tiff:NativeDigest>

<tiff:ImageWidth>491</tiff:ImageWidth>

<tiff:ImageLength>280</tiff:ImageLength>

<tiff:BitsPerSample>

<rdf:Seq>

<rdf:li>8</rdf:li>

<rdf:li>8</rdf:li>

<rdf:li>8</rdf:li>

<rdf:li>8</rdf:li>

</rdf:Seq>

</tiff:BitsPerSample>

<tiff:Compression>1</tiff:Compression>

<tiff:PhotometricInterpretation>2</tiff:PhotometricInterpretation>

<tiff:SamplesPerPixel>4</tiff:SamplesPerPixel>

<tiff:PlanarConfiguration>1</tiff:PlanarConfiguration>

</rdf:Description>

<rdf:Description rdf:about=""

xmlns:exif="http://ns.adobe.com/exif/1.0/">

<exif:PixelXDimension>491</exif:PixelXDimension>

<exif:PixelYDimension>280</exif:PixelYDimension>

<exif:ColorSpace>-1</exif:ColorSpace>

<exif:NativeDigest>36864,40960,40961,37121,37122,40962,40963,37510,40964,36867,36868,33434,33437,34850,34852,34855,34856,37377,37378,37379,37380,37381,37382,37383,37384,37385,37386,37396,41483,41484,41486,41487,41488,41492,41493,41495,41728,41729,41730,41985,41986,41987,41988,41989,41990,41991,41992,41993,41994,41995,41996,42016,0,2,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20,22,23,24,25,26,27,28,30;8810E4BB92B2EFF4B8B9195D62B8EE65</exif:NativeDigest>

</rdf:Description>

</rdf:RDF>

</x:xmpmeta>

<?xpacket end="w"?>pe</key>

<string>com.apple.print.PageFormatTicket</string>

</dict>

</plist>

8BIM

Tainted: False

Version: ImageMagick 6.2.8 04/17/08 Q16 file:/usr/share/ImageMagick-6.2.8/doc/index.html


----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

For the Image:: Ambersand300x300.tif - for this Image everything is just getting converting in to white.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Image: Ambersand300x300.tif

Format: TIFF (Tagged Image File Format)

Class: DirectClass

Geometry: 300x300

Type: Bilevel

Endianess: MSB

Colorspace: Gray

Channel depth:

Gray: 1-bits

Alpha: 8-bits

Channel statistics:

Gray:

Min: 255 (1)

Max: 255 (1)

Mean: 255 (1)

Standard deviation: 0 (0)

Alpha:

Min: 255 (1)

Max: 0 (0)

Mean: 98.4801 (0.386196)

Standard deviation: 123.357 (0.483752)

Alpha: (255,255,255,255) #FFFFFFFF

Colors: 17

Histogram:

33920: (255,255,255, 0) white

159: (255,255,255, 13) #FFFFFF0D

117: (255,255,255, 29) #FFFFFF1D

84: (255,255,255, 45) #FFFFFF2D

142: (255,255,255, 61) #FFFFFF3D

53: (255,255,255, 77) #FFFFFF4D

149: (255,255,255, 94) #FFFFFF5E

51: (255,255,255,110) #FFFFFF6E

153: (255,255,255,126) #FFFFFF7E

55: (255,255,255,142) #FFFFFF8E

135: (255,255,255,158) #FFFFFF9E

49: (255,255,255,175) #FFFFFFAF

141: (255,255,255,191) #FFFFFFBF

78: (255,255,255,207) #FFFFFFCF

134: (255,255,255,223) #FFFFFFDF

166: (255,255,255,239) #FFFFFFEF

54414: (255,255,255,255) #FFFFFFFF

Rendering intent: Undefined

Resolution: 72x72

Units: PixelsPerInch

Filesize: 14kb

Interlace: None

Background color: white

Border color: #DFDFDF00

Matte color: grey74

Page geometry: 300x300+0+0

Dispose: Undefined

Iterations: 0

Compression: LZW

Orientation: TopLeft

Signature: b4462aba863df770a6572ee5e6ad75e4348aab9856a5190da9c77cd7954ff309

Profile-iptc: 576 bytes

0x00000000: 42494d03 e9000000 00007801 00005000 48004800 8BIM-------x---P-H-H

0x00000190: 00000002 da0228ff e1ffe202 f9024650 00052803 -------(-------FP--(

0x00000320: fc000100 50004800 48000000 0002da02 28000000 -----P-H-H-------(--

0x000004b0: 00006400 00000000 00000000 00000127 0f000100 ---d------------'---

0x00000640: 01000000 00000000 00000000 00001200 00026400 -------------------d

0x000007d0: 00031800 00000022 72000100 01000300 02000000 --------"r----------

0x00000960: 00000000 00fe5c01 00000038 42494d03 ed000000 -------\----8BIM----

0x00000af0: 00001000 48000000 01000100 48000000 01000138 -----H-------H------

0x00000c80: 42494d03 ee000000 00000807 416c7068 61203138 8BIM---------Alpha 1

0x00000e10: 42494d04 15000000 00001400 00000800 41006c00 8BIM-------------A-l

0x00000fa0: 70006800 61002000 31000038 42494d03 ef000000 -p-h-a- -1--8BIM----

0x00001130: 00000e00 01b5b5ca caffff00 00002801 00384249 ---------------(--8B

0x000012c0: 4d040d00 00000000 04000000 78384249 4d03f300 IM-----------x8BIM--

0x00001450: 00000000 08000000 00000000 00384249 4d040a00 --------------8BIM--

0x000015e0: 00000000 01000038 42494d27 10000000 00000a00 --------8BIM'-------

0x00001770: 01000000 00000000 02384249 4d03f500 00000000 ----------8BIM------

0x00001900: 48002f66 66000100 6c666600 06000000 00000100 -H-/ff---lff--------

0x00001a90: 2f666600 0100a199 9a000600 00000000 01003200 -/ff---------------2

0x00001c20: 00000100 5a000000 06000000 00000100 35000000 -----Z-----------5--

0x00001db0: 01002d00 00000600 00000000 01384249 4d03f800 --------------8BIM--

0x00001f40: 00000000 700000ff ffffffff ffffffff ffffffff -----p--------------

0x000020d0: ffffffff ffffffff ff03e800 000000ff ffffffff --------------------

0x00002260: ffffffff ffffffff ffffffff ffffffff ff03e800 --------------------

0x000023f0: 000000ff ffffffff ffffffff ffffffff ffffffff --------------------

0x00002580: ffffffff ff03e800 000000ff ffffffff ffffffff --------------------

0x00002710: ffffffff ffffffff ffffffff ff03e800 00384249 ------------------8B

0x000028a0: 4d040800 00000000 10000000 01000002 40000002 IM---------------@--

0x00002a30: 40000000 00384249 4d041100 00000000 01010038 -@----8BIM----------

0x00002bc0: 42494d04 14000000 00000400 00000170 8BIM------------

Tainted: False

Version: ImageMagick 6.2.8 04/17/08 Q16 file:/usr/share/ImageMagick-6.2.8/doc/index.html

identify: incorrect count for field "MinSampleValue" (1, expecting 4); tag ignored. `Ambersand300x300.tif'.

identify: incorrect count for field "MaxSampleValue" (1, expecting 4); tag ignored. `Ambersand300x300.tif'.


----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Re: Problem with converting .TIF to .JPEG

Posted: 2011-08-05T09:34:30-07:00
by fmw42
identify: incorrect count for field "MinSampleValue" (1, expecting 4); tag ignored. `Ambersand300x300.tif'.

identify: incorrect count for field "MaxSampleValue" (1, expecting 4); tag ignored. `Ambersand300x300.tif'.
Possibly due to these bad tags

Can you create an image that you can provide that has the same problem?

Re: Problem with converting .TIF to .JPEG

Posted: 2011-08-06T10:04:28-07:00
by mniuser
-identify verbose results i have pasted in my earlier reply is of two files (APP_Fireball.tif & Ambersand300x300.tif)...but the below error is there in only second file.
identify: incorrect count for field "MinSampleValue" (1, expecting 4); tag ignored. `Ambersand300x300.tif'.
.

is there a way i can share the images here......i dont see any option to share.

Re: Problem with converting .TIF to .JPEG

Posted: 2011-08-06T10:16:05-07:00
by fmw42
is there a way i can share the images here......i dont see any option to share.
You can post your images to any free image hosting site (do a google search). Then put a link to your files from where you host here in your message.

Also your version of IM at 6.2.8 is ancient (over 400 versions old). You would be advised to upgrade if you can. You might also upgrade your libtif and libjpeg delegate libraries, as IM relies upon them to do the conversions.

Re: Problem with converting .TIF to .JPEG

Posted: 2011-08-08T11:08:52-07:00
by mniuser
When i was trying to upload the images on image hosting sites there also images with white background are getting converted to black...not sure why is this happening.

Re: Problem with converting .TIF to .JPEG

Posted: 2011-08-10T00:27:10-07:00
by mniuser
Hi,

I have managed to upload the files now, please find the link below.

https://rapidshare.com/files/1664683076/Images.zip


Thanks a lot for your help in advance.

Re: Problem with converting .TIF to .JPEG

Posted: 2011-08-10T09:24:40-07:00
by fmw42
Just looking at your image 4x3_protected.tif, I see that the image is pure black, but the alpha channel has all the detail. This is a very odd way of doing it.

try this to see what I mean.

identify -verbose 4x3_protected.tif
Image: 4x3_protected.tif
Format: TIFF (Tagged Image File Format)
Class: DirectClass
Geometry: 1920x1080+0+0
Resolution: 72x72
Print size: 26.6667x15
Units: PixelsPerInch
Type: Bilevel
Base type: Bilevel
Endianess: MSB
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 1-bit
alpha: 8-bit
Channel statistics:
Gray:
min: 0 (0)
max: 0 (0)
mean: 0 (0)

standard deviation: -0 (-0)
kurtosis: 0
skewness: 0
Alpha:
min: 0 (0)
max: 255 (1)
mean: 65.8573 (0.258264)
standard deviation: 110.7 (0.434117)
kurtosis: -0.763967
skewness: -1.10451

Then do:

convert 4x3_protected.tif -alpha off 4x3_protected_aoff.png
convert 4x3_protected.tif -alpha extract 4x3_protected_alpha.png

It looks like the alpha channel is what you want to convert to jpg.

convert 4x3_protected.tif -alpha extract 4x3_protected_alpha.jpg

Let me know about this one, before I look at the others.

Re: Problem with converting .TIF to .JPEG

Posted: 2011-08-10T10:40:51-07:00
by mniuser
Thanks a lot for your quick response.

Tried these option but didn't work....with these options black in TIF image is being converted in to white in JPEG and vice versa.

And one more thing the actual requirement is I need to convert around lakhs of TIF images to JPEG (TIF images are of both BLACK&WHITE and COLORED)...so I am trying to implement the script which should do the trick...hence I am looking for something generic which would work on both BLACK&WHITE and COLORED images.

If it is not possible to achieve my requirement through ImageMagick...is there any other way to achieve this ?

Thanks for the detailed explanation and for spending your precious time.

Re: Problem with converting .TIF to .JPEG

Posted: 2011-08-10T11:16:58-07:00
by fmw42
well lets deal with the first image. explain to me what it is that you expect. the image is being controlled by your alpha channel only. That is it has transparency. But jpg does not support transparency. So you must do something to flatten the alpha channel against some colored background. If you flatten against black you will see a totally black image the way you have your alpha channel set up. If you flatten against white, you get the negative of the alpha channel. So you can either do the flatten against white or extract the alpha channel and keep it or extract the alpha channel and -negate it.

Here I take your tif and resize it and convert to png. It looks the same as the tif image but smaller.

convert 4x3_protected.tif -resize 25% 4x3_protected.png
Image

convert 4x3_protected.tif -resize 25% -alpha extract 4x3_protected4_alpha.jpg
Image

convert 4x3_protected.tif -resize 25% -alpha extract -negate 4x3_protected4_alpha_neg.jpg
Image

convert 4x3_protected.tif -resize 25% -background white -flatten 4x3_protected4_white_flatten.jpg
Image


So what is it that you want for the result, if not one of the above?

Re: Problem with converting .TIF to .JPEG

Posted: 2011-10-17T11:15:32-07:00
by falakniazi
Following link might help while converting from .TIF to .JPG

http://sourcecodemania.com/converting-m ... if-in-php/