[gdal-dev] How to check if image is valid?
Even Rouault
even.rouault at mines-paris.org
Fri Nov 15 11:00:28 PST 2013
Le vendredi 15 novembre 2013 13:41:56, Jukka Rahkonen a écrit :
> Hi,
>
> Is there some fast method to check if an image is valid? I am creating
> overviews for some images and process yields this kind of errors:
>
> G:\m150_wms>gdaladdo -r average -ro --config COMPRESS_OVERVIEW JPEG
> --config PHOTOMETRIC_OVERVIEW YC
> BCR --config INTERLEAVE_OVERVIEW PIXEL TTEC_2011_M150_TM35_R4332B.TIF 2 4 8
> 16 32 64
> 0Warning 1: File open for read-only accessing, creating overviews
> externally. ...10...20Warning 1: JPEGLib:Premature end of JPEG file
> ERROR 1: JPEGLib:Not a JPEG file: starts with 0x00 0x00
> ERROR 1: TIFFReadEncodedTile() failed.
> ERROR 1: IReadBlock failed at X offset 36, Y offset 13
> ERROR 1: GetBlockRef failed at X block offset 36, Y block offset 13
> ...30...40...50...60...70...80...90...100 - done.
Are you sure that the error comes from the base image ? Overview building with
TIFF compression has been a source of various bugs in the past, so that could
be that too, although it finally seems to be quite stable since a few versions
now.
>
> Now I would like to run a check for a few thousand images and check if they
> are healthy. What is the recommended method to do it? Is it possible to run
> gdal_translate by using some dummy output format and capture just the
> filename and exit code into a log file so I could sort the images into good
> ones and probably corrupted?
"gdal_translate corrupted.tif /vsimem/foo.tif" returns a non 0 exit code. The
issue is that it can consume a lot of RAM (size of uncompressed image) if
corrupted.tif is very big.
> Or can I use gdalinfo with some parameters for
> this purpose?
I would have said "gdalinfo -checksum corrupted.tif", but actually the I/O
error during checksum computation doesn't have an influence on the error code,
so you can't use that
You can try the following Python script, let call it check_integrity.py
import sys
from osgeo import gdal
ds = gdal.Open(sys.argv[1])
for i in range(ds.RasterCount):
ds.GetRasterBand(1).Checksum()
if gdal.GetLastErrorType() != 0:
sys.exit(1)
sys.exit(0)
"python check_integrity.py corrupt.tif" will return 1 as error code.
(Checksum() isn't necessary the most efficient way of doing I/O in case of
interleave bands, but that the shortest script I could come with ;-))
Even
--
Geospatial professional services
http://even.rouault.free.fr/services.html
More information about the gdal-dev
mailing list