splitting an image into rows with overlap

Help
Roland
2012-06-18
2013-03-27
  • Roland
    Roland
    2012-06-18

    HI,
    I have to split a large File (1GB Tiff) into rows with a static width, but these rows have to overlap
    with a certain number of pixels.
    Can I do this in one command, or do I have to use crop for every row?
    (This would mean, cutting into 30 rows would last very long, because I have to load the full Tiff file 30 times)
    Greetings
    Roland

     
  • GraphicsMagick can not do this directly in one invocation from the command line.  If you are willing to write a PerlMagick script, TclMagick script, C program, C++ program, or one of the other GraphicsMagick programming methods, then you can easily do it with one read.

    As a work-around, you can use the MPC format as a temporary representation. This format reads quite quickly as long as the computer has enough RAM to cache the uncompressed representation.

    gm convert file.tiff file.mpc
    gm convert file.mpc -crop args tile1.tiff
    gm convert file.mpc -crop args tile2.tiff
    .
    .
    .

    This approach still requires that you have a way to produce the crop arguments for each strip (e.g. some sort of a program).

    Please note that MPC "format" is really two files.  One contains the metadata and the other contains the pixel data in the same way that GraphicsMagick stores it in memory.

    Bob

     
  • Roland
    Roland
    2012-06-20

    Hi Bob,
    thanks for your answer.
    I just came from imagemagick and had the same problem there and used exactly your method.
    It still took some time to convert from tiff to mpc.
    As a great suprise (for me) gm is that much faster, that this approach works just fine with gm.
    Thanks!

    So I switch to GM , no doubt.

    leading to another problem:
    I have to get the image resolution in dots per inch even if photoshop saved it in dots per centimeter.
    in IM I did this with convert picture.mpc -units pixelsperinch -format "%x" info:
    I know I have to use info:- with GM, and switch the options to the beginning but it still does not work.
    the gm identify does not support -units.
    I could live with using IM to get this information but the mpc file format differs, so IM gives a resolution of 0 on GM mpc files.

    How do I get the wanted Information?

    Greetings,
    Roland

     
  • I will look into seeing how -units should be handled to display in with different units.  The 'info' coder is relatively new in GraphicsMagick.  I think that the forthcoming release (snapshot/repository version)  is somewhat more advanced so that the 'info' coder does more of what 'identify' does.

    The .mpc file is mostly just a small text file (which you could easily parse), although the text may be followed by embedded binary profiles.  The image pixels are in a .cache file.

    Bob

     
  • I am not seeing a problem with how -units is handled here:

    % gm convert  EADT6030.mpc -units PixelsPerInch -format '%xx%y' info:-
    240x240

    % gm convert  EADT6030.mpc -units PixelsPerCentimeter -format '%xx%y' info:-
    609.6x609.6

    Here is part of the header from the MPC file:

    id=MagickCache
    quantum-depth=16
    class=DirectClass  matte=False
    compression=None
    columns=5220  rows=3473  depth=8
    Resolution=240x240  units=pixels-per-inch
    profile-ICM=560
    profile-8BIM=14502
    profile-XMP=11134
    artist={Matt flor}
    timestamp={2004:08:23 09:50:58}
    comment={Late afternoon sun aluminates a patch of tall grass, Winthrop WA}
    make=Canon
    model={Canon EOS-1DS}
    software={Adobe Photoshop CS Macintosh}
    ^L

    Bob

     
  • Roland
    Roland
    2012-06-21

    Hi Bob,
    I get:

    gm convert: No encode delegate for this image format (-) .

    after typing your line gm convert EADT6030.mpc -units PixelsPerInch -format '%xx%y' info:-

    I guess the gm version of ubuntu 12.04 is outdated… gm version:
    GraphicsMagick 1.3.12 2010-03-08 Q8 http://www.GraphicsMagick.org/

    I have to use a stable version for productivty.
    Which version shall I use?

    Greetings and thanks
    Roland

     
  • The current release is 1.3.15, which was released on April 28th, 2012.  Debian Experimental is updated to 1.3.15 so perhaps Ubuntu will do so someday as well.

    One way to make sure that you are always using the current stable release is to compile it from source code.  This is pretty easy once you install all of the developer packages for the libraries that GraphicsMagick uses.

     
  • Roland
    Roland
    2012-06-21

    Hi Bob,
    I downloaded the latest version, compiled it, everything wokrs fine but:
    The calculation is wrong.
    look at your own example you posted: the pixel per inch is 2.54 times smaller than the pixel per centimeter.
    It should be 2.54 time bigger ;-)

    Greeting
    Roland

     
  • Roland
    Roland
    2012-06-22

    Hi Bob,
    thanks for the fix.
    I fixed it myself in my copy of command.c and recompiled it.
    Fine, it is working as expected.

     
  • Good.  If all goes well, I will pump out a new formal release this coming weekend.