Extracting a subset of a large TIFF image.

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
Rich_Morin
Posts: 3
Joined: 2018-05-03T15:14:46-07:00
Authentication code: 1152

Extracting a subset of a large TIFF image.

Post by Rich_Morin »

I'm trying to extract an uncompressed rectangular subset of a large TIFF image. It may be working,
but I'm getting a concerning nastygram.

Background

- The image is High Resolution Orthoimagery (HRO) from USGS (https://lta.cr.usgs.gov/high_res_ortho).
- It contains 12815 (rows) * 14632 (cols) of RGB (or RGBA ?) data.
- I'd like to feed the subset into GIMP, ImageMagick, and/or my own (Ruby) scripts.

I'm using a recent version of IM on macOS High Sierra (10.13.4):

Code: Select all

 convert --version
  Version: ImageMagick 7.0.7-22 Q16 x86_64 2018-01-13 http://www.imagemagick.org
  Copyright: © 1999-2018 ImageMagick Studio LLC
  License: http://www.imagemagick.org/script/license.php
  Features: Cipher DPC HDRI 
  Delegates (built-in): bzlib freetype jng jpeg lcms png raw tiff webp xml zlib
Command

Here's what I tried to extract a 640x480 image subset (using 16 bits per pixel) near the center of the input image:

base=3097_43_1_20150119
convert -depth 16 \
-extract 640x480+6000+6000 \
-size 16000x16000 \
$base.tif $base.ppm

When I run this, I get an output file (3097_43_1_20150119.ppm) that is 3015806 bytes in size, along with the following nastygram:

convert: Unknown field with tag 33550 (0x830e) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/994.
convert: Unknown field with tag 33922 (0x8482) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/994.
convert: Unknown field with tag 34735 (0x87af) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/994.
convert: Unknown field with tag 34737 (0x87b1) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/994.
convert: geometry does not contain image `3097_43_1_20150119.tif' @ warning/transform.c/CropImage/590.
convert: geometry does not contain image `3097_43_1_20150119.tif' @ warning/transform.c/CropImage/590.
convert: geometry does not contain image `3097_43_1_20150119.tif' @ warning/transform.c/CropImage/590.
convert: geometry does not contain image `3097_43_1_20150119.tif' @ warning/transform.c/CropImage/590.
convert: geometry does not contain image `3097_43_1_20150119.tif' @ warning/transform.c/CropImage/590.
convert: geometry does not contain image `3097_43_1_20150119.tif' @ warning/transform.c/CropImage/590.
convert: geometry does not contain image `3097_43_1_20150119.tif' @ warning/transform.c/CropImage/590.

Comments? Clues? Suggestions?

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

Re: Extracting a subset of a large TIFF image.

Post by fmw42 »

I may miss something, but I do not see where to download your exact tiff file from that link. Can you link to it directly?

In ImageMagick 7, you use magick rather than convert. Also IM 7 is more strict about syntax. So you need to read the tiff file first, then do the processing, then write the output. -size does nothing in your command. Why do you want that? Is it to pad the image to that size?

Try

Code: Select all

base="3097_43_1_20150119"
magick $base.tif +repage -depth 16 \
-crop 640x480+6000+6000 +repage \
$base.ppm
or

Code: Select all

base="3097_43_1_20150119"
magick $base.tif +repage -depth 16 \
-extent 640x480+6000+6000 +repage \
$base.ppm
I use [0] in case you have multiple pages. If you have more than one page or layer in the tif file, each one may be a different size. You should do

magick identify $base.tif

to see if you have multiple pages or layers in the file and what are their sizes.

The first 4 warnings can be ignored, since they are about special tiff meta tags that ImageMagick does not understand, perhaps Geo tags
Post Reply