Can someone explain what the difference is?

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
jaffamuffin
Posts: 59
Joined: 2009-01-30T03:46:08-07:00

Can someone explain what the difference is?

Post by jaffamuffin »

Two set of commands here : one is split into 4 seperate commands, the other is all in one.

The separate commands produce an output the is shifted to the right by about 100px, the all in one 'seems' to produce the 'correct' output. What have I missed?

By shifted to the right I mean the block of text on the page relative to the image edge. - it's a greyscale scan of a page of a book. Both output images are the same dimension...

Code: Select all

e.g. 
[i]Working on 0037.tif
spine mark is 2847
image width is 2922
top mark (edge) is 240
img height is 3976
offset 75
[/i]

SET pageheight=3525
SET pagewidth=2380

convert %filenameext% -gravity northeast -crop %pagewidth%x%pageheight%+%offset%+%topmark% +repage .\done1\1_%filenameext%

convert .\done1\1_%filenameext% -background white -deskew 40%%  -level 10%%,90%%,1 .\done1\2_%filenameext%

convert .\done1\2_%filenameext% -shave 40x40 .\done1\3_%filenameext%

convert .\done1\3_%filenameext% -background white -splice 100x100 -gravity center -crop %pagewidth%x%pageheight% +repage .\done1\4_%filenameext%

rem ----------------------

convert %filenameext% -gravity northeast -crop %pagewidth%x%pageheight%+%offset%+%topmark% +repage -background white -deskew 40%%  -level 10%%,90%%,1 -shave 40x40 -background white -splice 100x100 -gravity center -crop %pagewidth%x%pageheight% +repage .\done1\5_%filenameext%

snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Can someone explain what the difference is?

Post by snibgo »

I haven't tested this, but I suspect the problem is "-gravity". In the all-in-one command, the value "northeast" is carried through until you change it to "center". In the separate commands, it will be reinitialise (to "northwest"?) at each command.
snibgo's IM pages: im.snibgo.com
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Can someone explain what the difference is?

Post by Bonzo »

Again I have not tied it but you may need to use ( )
Try:

Code: Select all

convert ( %filenameext% -gravity northeast -crop %pagewidth%x%pageheight%+%offset%+%topmark% +repage ) -background white -deskew 40%%  -level 10%%,90%%,1 -shave 40x40 -background white -splice 100x100 -gravity center -crop %pagewidth%x%pageheight% +repage .\done1\5_%filenameext%
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Can someone explain what the difference is?

Post by snibgo »

Brackets don't localise the gravity change to within the brackets.

To get the multi-command to give the same version as the all-in-one, insert "-gravity northeast" at the start of the final command:

Code: Select all

convert .\done1\3_%filenameext% -gravity northeast -background white -splice 100x100 -gravity center -crop %pagewidth%x%pageheight% +repage .\done1\4_%filenameext%
snibgo's IM pages: im.snibgo.com
jaffamuffin
Posts: 59
Joined: 2009-01-30T03:46:08-07:00

Re: Can someone explain what the difference is?

Post by jaffamuffin »

After further processing I have realised that the final output of the 'multi' command is actualyl what I want, and the all in one has the problem of the image 'shifting'

What appears to be happening is the splice is pushing the image over to the left. I shall post up some examples.

But, the all in one file has 4 pages, with pages, 2 -4 being thin strips and a square of white...



Some examples - tif images, I've blacked out the text as it is sensitive data and unrelated to the problem in hand

original file
output from multi - desired output but with one page, not 4
output from single command with 4 pages

I would like one command that produces output same as multi.. Suggestions welcomed on alternate approaches to what I have done to the images..
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Can someone explain what the difference is?

Post by snibgo »

The extra output files will be because your shave or splice or both will need zero offsets: "+0+0". If you post your original file, we can test with what you've got, so our advice may be more precise.

Also, let us know what IM version you are using.
snibgo's IM pages: im.snibgo.com
jaffamuffin
Posts: 59
Joined: 2009-01-30T03:46:08-07:00

Re: Can someone explain what the difference is?

Post by jaffamuffin »

W:\left>convert --version
Version: ImageMagick 6.5.7-5 2009-11-03 Q8 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
Features: OpenMP

My script output this when i processes tif 61 :

W:\test>crop_book_left_dir .
W:\test\0061.tif
Working on 0061.tif
spine mark is 2892
image width is 2922
top mark (edge) is 224
img height is 3976
offset 30
convert: "XPosition": Information lost writing value (-0.00333333) as (unsigned)
RATIONAL. `.\done1\2_0061.tif' @ tiff.c/TIFFWarnings/703.
convert: "YPosition": Information lost writing value (-0.01) as (unsigned) RATIO
NAL. `.\done1\2_0061.tif' @ tiff.c/TIFFWarnings/703.


edit - spinemark looks morelike 2821, looks like my script is reading the right side of the mark rather than the left side... this probablyexplainsthe small variations in image psosition, but my main problem still remains.
jaffamuffin
Posts: 59
Joined: 2009-01-30T03:46:08-07:00

Re: Can someone explain what the difference is?

Post by jaffamuffin »

Hi

I have adjusted the commands and I now beleive it is outputting what I require - great! Except I added +0+0 to the shave / splice commands but I still am getting a 4 page output file?

Here is my command:

Code: Select all

convert %filenameext% ^
-gravity northeast -crop %pagewidth%x%pageheight%+%offset%+%topmark% +repage ^
-background white -deskew 40%% ^
-level 10%%,90%%,1 ^
-gravity northwest -shave 40x40+0+0 ^
-background white -splice 100x100+0+0 ^
-gravity center -crop %pagewidth%x%pageheight% +repage ^
.\done1\5_%filenameext%


Working on 0061.tif
backtrack 63
markcount 7
spine mark is 2821
image width is 2922
top mark (edge) is 224
img height is 3976
offset 101
What am I missing ?

Cheers
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Can someone explain what the difference is?

Post by snibgo »

You are missing +0+0 on the crop.

Rule of thumb: geometry (axb+c+d) with no offsets always needs "+0+0".
snibgo's IM pages: im.snibgo.com
Post Reply