non-square resolution

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
Red5

non-square resolution

Post by Red5 »

I'm a bit of newbie, using ImageMagick on WinXP.
I deal with TIFF images quite a bit, and currently use LeadTools to do some of our conversion. I'm trying to get IM to do realitively the same thing, but having a bit of hard time. My goal is to see if IM can compete with LeadTools in performance and quality for batch jobs.
My source images have the following traits:
TIFF
Resolution: 240x120
4-bit depth greyscale
full page scans, (8.5" x 11")
LZW compression

I would like my resulting images to be, probably using CONVERT:
TIFF image--> filename slightly different than original
Resolution: 240x240, but would like to know how to keep 240x120 as an option
1-bit depth greyscale (it would be nice to dictate which level of grey results in black during conversion)
A recommendation for compression, either LZW or Fax4

I deal with millions of image per project..so size is very important for SAN usage reasons
The best I've come up with is:

Code: Select all

convert 00000305.tif -resize 100%x200% -density 240x240 +dither -scale 100% -type bilevel -compress lzw output.tif
But the file size seems to be too large...and the process time seems rather slow.
LeadTools can do this in roughly 2 images per second on our dedicate workstations.
jhfry

Re: non-square resolution

Post by jhfry »

I don't know if it matters, but I wouldn't be supprised if your speed issues are related to SMP (mulitprocessor) support. I would imagine that your workstations have at least 2 cores and perhaps LeadTools uses both while IM only uses 1.

Try running multiple convert operations, at least one per core, at the same time and see if you notice an increase in overall images/second.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: non-square resolution

Post by fmw42 »

IM has been adding multiprocessor support of late, but I don't know to what extent -- if it covers your commands.

Try adding -depth to your command.

I would be surprised if IM could match a special function written to do what you need as IM was written to be a more general processing system and would not be optimized in the way that you perhaps need as it needs to be more flexible.

But hopefully the IM staff will add their comments here.
Red5

Re: non-square resolution

Post by Red5 »

Good point on the dual-core...I'm pretty sure our dedicated workstations are at least that. I can take that into account when I make my comparisons.

The whole conversion from 4-bit to 1-bit is a bit of mystery?
Should I resize first, then resample, then change bit depth?
Is there a standard acceptable order of these tasks to achieve high quality results?

The thing about these TIFF and their non-square resolution---some image viewer applications will redraw the image as 240x240 so it appears correct to your eye. Other apps will not, and the image is distorted when viewed (even though it is display it correctly as 240x120).
I really want the end result to be 240x240 without loss of data if possible.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: non-square resolution

Post by fmw42 »

post a reasonable sized example of your tiff file.
Red5

Re: non-square resolution

Post by Red5 »

fmw42 wrote:post a reasonable sized example of your tiff file.
Here is a sample TIFF that I would be handling:
http://www.acheson-creative.com/00000201.tif
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: non-square resolution

Post by fmw42 »

Your sample tiff is not what you think it is. According to

convert 00000201.tif -verbose info:

It is 9-bit and RLE compressed, not 4-bit and LZW.


convert 00000201.tif -verbose info:
Image: 00000201.tif
Format: TIFF (Tagged Image File Format)
Class: PseudoClass
Geometry: 1968x1312+0+0
Resolution: 240x120
Print size: 8.2x10.9333
Units: PixelsPerInch
Type: Grayscale
Base type: Palette
Endianess: Undefined
Colorspace: Gray
Depth: 9-bit
Channel depth:
gray: 9-bit
Channel statistics:
gray:
min: 0 (0)
max: 510 (0.996109)
mean: 493.399 (0.963684)
standard deviation: 71.3925 (0.139441)
Histogram:
2377628: (65280,65280,65280) #FF00FF00FF00 rgb(99.6109%,99.6109%,99.6109%)
75605: (57344,57344,57344) #E000E000E000 rgb(87.5013%,87.5013%,87.5013%)
30246: (36864,36864,36864) #900090009000 rgb(56.2509%,56.2509%,56.2509%)
16810: ( 4096, 4096, 4096) #100010001000 rgb(6.2501%,6.2501%,6.2501%)
14998: (45056,45056,45056) #B000B000B000 rgb(68.751%,68.751%,68.751%)
13387: (16384,16384,16384) #400040004000 rgb(25.0004%,25.0004%,25.0004%)
11507: (53248,53248,53248) #D000D000D000 rgb(81.2512%,81.2512%,81.2512%)
7794: ( 8192, 8192, 8192) #200020002000 rgb(12.5002%,12.5002%,12.5002%)
6659: (20480,20480,20480) #500050005000 rgb(31.2505%,31.2505%,31.2505%)
5861: ( 0, 0, 0) #000000000000 black
5843: (12288,12288,12288) #300030003000 rgb(18.7503%,18.7503%,18.7503%)
3640: (49152,49152,49152) #C000C000C000 rgb(75.0011%,75.0011%,75.0011%)
3305: (32768,32768,32768) #800080008000 grey50
3280: (24576,24576,24576) #600060006000 rgb(37.5006%,37.5006%,37.5006%)
2816: (28672,28672,28672) #700070007000 rgb(43.7507%,43.7507%,43.7507%)
2637: (40960,40960,40960) #A000A000A000 rgb(62.501%,62.501%,62.501%)
Colormap: 16
0: ( 0, 0, 0) #000000000000 black
1: ( 4096, 4096, 4096) #100010001000 rgb(6.2501%,6.2501%,6.2501%)
2: ( 8192, 8192, 8192) #200020002000 rgb(12.5002%,12.5002%,12.5002%)
3: (12288,12288,12288) #300030003000 rgb(18.7503%,18.7503%,18.7503%)
4: (16384,16384,16384) #400040004000 rgb(25.0004%,25.0004%,25.0004%)
5: (20480,20480,20480) #500050005000 rgb(31.2505%,31.2505%,31.2505%)
6: (24576,24576,24576) #600060006000 rgb(37.5006%,37.5006%,37.5006%)
7: (28672,28672,28672) #700070007000 rgb(43.7507%,43.7507%,43.7507%)
8: (32768,32768,32768) #800080008000 grey50
9: (36864,36864,36864) #900090009000 rgb(56.2509%,56.2509%,56.2509%)
10: (40960,40960,40960) #A000A000A000 rgb(62.501%,62.501%,62.501%)
11: (45056,45056,45056) #B000B000B000 rgb(68.751%,68.751%,68.751%)
12: (49152,49152,49152) #C000C000C000 rgb(75.0011%,75.0011%,75.0011%)
13: (53248,53248,53248) #D000D000D000 rgb(81.2512%,81.2512%,81.2512%)
14: (57344,57344,57344) #E000E000E000 rgb(87.5013%,87.5013%,87.5013%)
15: (65280,65280,65280) #FF00FF00FF00 rgb(99.6109%,99.6109%,99.6109%)
Rendering intent: Undefined
Interlace: None
Background color: white
Border color: rgb(223,223,223)
Matte color: grey74
Transparent color: black
Page geometry: 1968x1312+0+0
Dispose: Undefined
Iterations: 0
Compression: RLE
Orientation: TopLeft
Properties:
create-date: 2008-07-27T00:34:29-07:00
modify-date: 2008-07-27T00:34:29-07:00
signature: 1a714ebbcb766432cbb70c756181bfbf4d2023b0deaf2c6274fdfac02755f3e3
tiff:rows-per-strip: 8
tiff:software: TIFF.DLL from Black Ice Software, Inc.Version 6.14
Artifacts:
verbose: true
Tainted: False
Filesize: 103kb
Number pixels: 2.462mb
Version: ImageMagick 6.4.2 07/18/08 Q16 http://www.imagemagick.org
convert: incorrect count for field "DateTime" (1, expecting 20); tag ignored. `00000201.tif'.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: non-square resolution

Post by fmw42 »

Just as a quick test, I tried

convert 00000201.tif -depth 1 -compress LZW -density 240x240 tmp.tif

I got an error message about incorrect date/time, but the file was created. So I did

convert tmp.tif -verbose info:
Image: tmp.tif
Format: TIFF (Tagged Image File Format)
Class: PseudoClass
Geometry: 1968x1312+0+0
Resolution: 240x240
Print size: 8.2x5.46667
Units: PixelsPerInch
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: Gray
Depth: 1-bit
Channel depth:
gray: 1-bit
Channel statistics:
gray:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: -0 (-0)
Histogram:
2582016: ( 0, 0, 0) #000000 black
Colormap: 2
0: ( 0, 0, 0) #000000 black
1: (255,255,255) #FFFFFF white
Rendering intent: Undefined
Interlace: None
Background color: white
Border color: rgb(223,223,223)
Matte color: grey74
Transparent color: black
Page geometry: 1968x1312+0+0
Dispose: Undefined
Iterations: 0
Compression: LZW
Orientation: TopLeft
Properties:
create-date: 2008-07-27T00:46:55-07:00
modify-date: 2008-07-27T00:46:55-07:00
signature: 54c71e492d79a4c475e80ef618904544e173534e3a0c79758fe6d035518eea5c
tiff:document: tmp.tif
tiff:rows-per-strip: 33
tiff:software: ImageMagick 6.4.2 07/18/08 Q16 http://www.imagemagick.org
Artifacts:
verbose: true
Tainted: False
Filesize: 6.29kb
Number pixels: 2.462mb
Pixels per second: 2.462mb
User time: 0.120u
Elapsed time: 0:02
Version: ImageMagick 6.4.2 07/18/08 Q16 http://www.imagemagick.org


As you can see it is now depth 1 (bi-level) gray, i.e. black/white with Resolution: 240x240 and LZW compressed.

However, it is totally black.

So you will need to control what is black and what is white by adding -threshold to the command. But you will need to use trial and error to figure out what threshold to use.

convert 00000201.tif -threshold 50% -depth 1 -compress LZW -density 240x240 tmp.tif

This seemed to work adequately and the result is not totally black.
Red5

Re: non-square resolution

Post by Red5 »

Thank you fmw42!
I've learned a few things, not only about my original images, but about using Threshold and density. The conversion is fairly quick too. (I'm using IM 6.4.1-Q16)
If you right-click on the image and bring up the advance properties, WinXP sees it as 4-bit depth. I was relying on that for my base information. I wonder which one is really right?

I'm back to the one sticking point for this whole conversion process.
These images are created on high-speed scanners, hence the 240x120 resolution.
The IM conversion process refuses to put the image in a normal viewable format of square resolution. Running the code you supplied shows the original horizontal strech of the image when viewed with any available viewer.
Although the original 240x120 shows up on most viewers in the correct aspect ratio (to the eye anyway)
I changed your code to "density 240x120" to achieve this.

Any ideas on how best to eliminate that stretch and have an actual resolution of 240x240 or 120x120?

Thanks again for taking time to do what you did.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: non-square resolution

Post by anthony »

-resample 240x240 or -resample 120x120

This is a variation of -resize but resizing to adjust the images density to be what you want.

See IM Examples Resizing Images, Resampling
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Red5

Re: non-square resolution

Post by Red5 »

Thanks anthony...I was afraid you were going to say that.
The resample method is very slow. I can only convert approximately 1 image per 2 seconds or so.

So now I have a very good way to convert my images to a format that is usable for me, but the performace just isn't there yet like it is with LeadTools....
jhfry

Re: non-square resolution

Post by jhfry »

Sorry to jump in after this thread died... but did you resample the original before or after the conversion.

i would imagine that resampling as the last step would be faster than it would as the first step since the conversion to B&W would eliminate most of the image data.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: non-square resolution

Post by anthony »

I am sorry to say, resizing black and white is the same as for color in IM resize functions.

Better to do it first if this does not effect the desired quality, as a smaller image will be processed faster.

The -thumbnail resize is faster as it does -sample of the image first
to a smaller size, before doing the final sizing using -resize. You can do this yourself too. Similarly using a filter with a smaller 'support' will also resize faster (such as using Mitchell, rather than Lanczos).
The only problems with this is you will then need to calculate the final size wanted yourself, and set -density appropriately.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply