Need to Force "convert" to Produce Image Type DirectClass

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
anyoneis
Posts: 19
Joined: 2011-08-08T12:29:34-07:00
Authentication code: 8675308

Need to Force "convert" to Produce Image Type DirectClass

Post by anyoneis »

I am producing 16 tiles (.png) from a large image (.tif) by first transferring the image to an MPC and then using 16 separate "convert -crop" commands to create the tiles.

The tiles created by convert are usually image type DirectClass, but sometimes I will get one of the images in the set converting as image type PseudoClass.

I need these tiles to all be of the same image type. If convert allwed me to specify "-imagetype DirectClass" I would have a solution, but alas, it does not.

Any other ideas? I am using ImageMagick-6.7.1-Q8. The commands are:
identify "WRL 15 1A.tif[2]"
WRL 15 1A.tif[2] TIFF 57632x615 84 57632x61584+0+0 8-bit DirectClass 1.1209GB 0.062u 0:00.203
convert "WRL 15 1A.tif[2]" f:\imagemagick\image.mpc
convert "f:\imagemagick\image.mpc" -crop 14408x15396+0+0 +repage -scene 0 "e:\imagemagick\extract_png\WRL_15_1A_0.png"
convert "f:\imagemagick\image.mpc" -crop 14408x15396+14408+0 +repage -scene 0 "e:\imagemagick\extract_png\WRL_15_1A_1.png"
convert "f:\imagemagick\image.mpc" -crop 14408x15396+28816+0 +repage -scene 0 "e:\imagemagick\extract_png\WRL_15_1A_2.png"
...
Thanks,
David
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need to Force "convert" to Produce Image Type DirectCla

Post by fmw42 »

try -type truecolor
anyoneis
Posts: 19
Joined: 2011-08-08T12:29:34-07:00
Authentication code: 8675308

Re: Need to Force "convert" to Produce Image Type DirectCla

Post by anyoneis »

fmw42 wrote:try -type truecolor
Hi Fred. I tried that again, first before the input file and then just before the output file name. No change.

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

Re: Need to Force "convert" to Produce Image Type DirectCla

Post by fmw42 »

IM appears to be too smart and if it knows that the number of colors is 256 or less it makes the result pseudoclass. The only way I can see to override that would be to do some kind of processing that introduces more colors. But I am not an expert on this and hopefully the IM developers can be more informative.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Need to Force "convert" to Produce Image Type DirectCla

Post by anthony »

The PNG codec has a lot of special program options. It may not be responding to the -type setting as it should, when no special PNG defines are present.

See the special PNG coder defines in...
http://www.imagemagick.org/Usage/formats/#png_write
or in the header comments of the coder/png.c codec source.

I'll send Glen (the developer of the PNG codec) a copy of this message for his comment.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need to Force "convert" to Produce Image Type DirectCla

Post by fmw42 »

I tried using that with no success, i.e. -define png:color-type=2

For png:

convert logo: -type truecolor logo.png
identify -verbose logo.png
Image: logo.png
Format: PNG (Portable Network Graphics)
Class: PseudoClass
Geometry: 640x480+0+0
Resolution: 72x72
Print size: 8.88889x6.66667
Units: Undefined
Type: Palette


For miff:

convert logo: -type truecolor logo.miff
identify -verbose logo.miff
Image: logo.miff
Format: MIFF (Magick Image File Format)
Class: DirectClass
Geometry: 640x480+0+0
Resolution: 72x72
Print size: 8.88889x6.66667
Units: Undefined
Type: Palette
Base type: TrueColor
Last edited by fmw42 on 2011-08-18T17:52:14-07:00, edited 1 time in total.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Need to Force "convert" to Produce Image Type DirectCla

Post by glennrp »

Try writing to PNG24:output.png
or if you know it's transparent, PNG32:output.png

What happened when you used -define png:colortype=2 ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need to Force "convert" to Produce Image Type DirectCla

Post by fmw42 »

glennrp wrote:Try writing to PNG24:output.png
or if you know it's transparent, PNG32:output.png

What happened when you used -define png:colortype=2 ?
convert logo: -define png:colortype=2 logo2.png
identify -verbose logo2.png
Image: logo2.png
Format: PNG (Portable Network Graphics)
Class: PseudoClass
Geometry: 640x480+0+0
Resolution: 72x72
Print size: 8.88889x6.66667
Units: Undefined
Type: Palette


This seems to work with PNG24:

convert logo: -type truecolor PNG24:logo3.png
freds-mac-mini:~ fred$ idv logo3.png
Image: logo3.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 640x480+0+0
Resolution: 72x72
Print size: 8.88889x6.66667
Units: Undefined
Type: Palette
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Need to Force "convert" to Produce Image Type DirectCla

Post by glennrp »

Try -define png:color-type=2

You omitted the hyphen in color-type

However, that didn't work for me. The decoder refused to do it, with
a warning.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need to Force "convert" to Produce Image Type DirectCla

Post by fmw42 »

sorry, I just copied your command from above, which did not have the hyphen and did not look it up properly


convert logo: -define png:color-type=2 logo4.png
identify -verbose logo4.png
Image: logo4.png
Format: PNG (Portable Network Graphics)
Class: PseudoClass
Geometry: 640x480+0+0
Resolution: 72x72
Print size: 8.88889x6.66667
Units: Undefined
Type: Palette
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Need to Force "convert" to Produce Image Type DirectCla

Post by glennrp »

The -define PNG:color-type2 option should work now for PseudoClass input, SVN revision 4996, which will be IM-6.7.1-8 in a few days.
anyoneis
Posts: 19
Joined: 2011-08-08T12:29:34-07:00
Authentication code: 8675308

Re: Need to Force "convert" to Produce Image Type DirectCla

Post by anyoneis »

I may be misunderstanding, but the problem I posted about was forcing convert to produce DirectClass. I am using the output of convert as input to another image processing utility. Just in case, I tried adding the define, as in:

Code: Select all

c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "\\silo\cds\CDS-CS\Programming\BPATH\Hudkins_WRL 15 1A.tif[9]" f:\imagemagick\image.mpc
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+0+0 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_00.png"
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+114+0 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_01.png"
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+228+0 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_02.png"
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+342+0 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_03.png"
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+0+122 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_04.png"
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+114+122 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_05.png"
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+228+122 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_06.png"
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+342+122 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_07.png"
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+0+244 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_08.png"
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+114+244 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_09.png"
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+228+244 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_10.png"
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+342+244 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_11.png"
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+0+366 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_12.png"
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+114+366 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_13.png"
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+228+366 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_14.png"
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+342+366 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_15.png"
But I still got mixed image types:

F:\_code\BPathImagePrep\BPathImagePrep\bin\x64\Debug>for %a in (e:\imagemagick\extract_png\Hudkins_WRL_15_1A_*.png) do @identify %a
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_00.png PNG 114x122 114x122+0+0 8-bit DirectClass 13.1KB 0.000u 0:00.001
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_01.png PNG 114x122 114x122+0+0 8-bit DirectClass 8.68KB 0.000u 0:00.001
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_02.png PNG 114x122 114x122+0+0 8-bit DirectClass 17.2KB 0.000u 0:00.001
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_03.png PNG 114x122 114x122+0+0 8-bit DirectClass 17.9KB 0.000u 0:00.000
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_04.png PNG 114x122 114x122+0+0 8-bit DirectClass 29.8KB 0.000u 0:00.001
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_05.png PNG 114x122 114x122+0+0 8-bit DirectClass 27.7KB 0.000u 0:00.000
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_06.png PNG 114x122 114x122+0+0 8-bit DirectClass 18.3KB 0.000u 0:00.001
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_07.png PNG 114x122 114x122+0+0 8-bit DirectClass 13KB 0.000u 0:00.001
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_08.png PNG 114x122 114x122+0+0 8-bit DirectClass 24.8KB 0.000u 0:00.000
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_09.png PNG 114x122 114x122+0+0 8-bit DirectClass 16.9KB 0.000u 0:00.000
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_10.png PNG 114x122 114x122+0+0 8-bit DirectClass 25.4KB 0.000u 0:00.001
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_11.png PNG 114x122 114x122+0+0 8-bit DirectClass 18.1KB 0.000u 0:00.000
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_12.png PNG 114x122 114x122+0+0 8-bit PseudoClass 115c 4.54KB 0.000u 0:00.000
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_13.png PNG 114x122 114x122+0+0 8-bit PseudoClass 166c 5.21KB 0.000u 0:00.000
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_14.png PNG 114x122 114x122+0+0 8-bit DirectClass 23KB 0.016u 0:00.001
e:\imagemagick\extract_png\Hudkins_WRL_15_1A_15.png PNG 114x122 114x122+0+0 8-bit DirectClass 9.14KB 0.000u 0:00.000

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

Re: Need to Force "convert" to Produce Image Type DirectCla

Post by fmw42 »

What version of IM did you use on your last tests and exactly what was the command line?

Did you try skipping the -define and just use PNG24: or PNG32: (if transparency) to preface the output.

In any case, if you are on the current version of IM and -define still fails, then you should post a link to one or all of those failing images so that Glenn can test with them.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Need to Force "convert" to Produce Image Type DirectCla

Post by glennrp »

anyoneis wrote:I may be misunderstanding, but the problem I posted about was forcing convert to produce DirectClass. I am using the output of convert as input to another image processing utility. Just in case, I tried adding the define, as in:

Code: Select all

c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "\\silo\cds\CDS-CS\Programming\BPATH\Hudkins_WRL 15 1A.tif[9]" f:\imagemagick\image.mpc
c:\Program Files (x86)\ImageMagick-6.7.1-Q8\convert "f:\imagemagick\image.mpc" -crop 114x122+0+0 +repage -scene 0 -define PNG:color-type2 "e:\imagemagick\extract_png\Hudkins_WRL_15_1A_00.png"
David[/quote]
It's PNG:color-type=2 not PNG:color-type2
Note the equals-sign.
anyoneis
Posts: 19
Joined: 2011-08-08T12:29:34-07:00
Authentication code: 8675308

Re: Need to Force "convert" to Produce Image Type DirectCla

Post by anyoneis »

Good eye, mate! So it is! Problem solved.

Thanks All!

David
Post Reply