5

I am working with a lot of old black and white maps extracted from scanned PDFs. When I use the QGIS georeference the resulting files are much larger than the original 10x to 100x. Is there a way to prevent this. The starting TIFFs are true black and white with 1 bit per pixel encoding (CCITT Group 4 Fax Encoding) but the resulting files are greyscale with 16 bits. Is there a way to get QGIS to make and work with true B&W TIFFs?

1
  • 1
    Have you set a compression in the georeferencing settings? Maybe you can translate the outputs to fix the bit depth problem (and compress)?
    – BERA
    Apr 22 at 5:35

1 Answer 1

5

The right parameters for the compression that you want to use are documented in https://gdal.org/drivers/raster/gtiff.html and they are

-co COMPRESS=CCITTFAX4 -co NBITS=1 

By the documentation "The apparent pixel type should be Byte" and that can be forced by the gdalwarp parameter -ot byte https://gdal.org/programs/gdalwarp.html#cmdoption-gdalwarp-ot.

The problem with the QGIS georeferencer is that if exposes only a small subset of the GDAL options in the GUI. For example, user can select only these compression methods:

enter image description here

What you can do is to generate the GDAL commands with the QGIS georeferencer and edit them manually.

An example: QGIS creates commands like this:

gdal_translate -of GTiff -gcp 1046.753 2423 49483.801 661482.876 -gcp 4941.956 5306.063 49819.728 661241.55 -gcp 1905.538 5336.734 49387.426 661167.8 "input.tif" "output.tif"

gdalwarp -r near -order 1 -co COMPRESS=DEFLATE  -t_srs EPSG:2053 "output.tif" "input_modified.tif"

Edited commands:

gdal_translate -of VRT -gcp 1046.753 2423 49483.801 661482.876 -gcp 4941.956 5306.063 49819.728 661241.55 -gcp 1905.538 5336.734 49387.426 661167.8 "input.tif" "output.vrt"

gdalwarp -r near -order 1 -ot byte -co COMPRESS=CCITTFAX4 -co NBITS=1  -t_srs EPSG:2053 "output.vrt" "input_modified.tif"

I changed also the file format of the gdal_translate output into virtual raster (VRT) https://gdal.org/drivers/raster/vrt.html. That is not necessary but there is no benefit at all in writing a physical temporary TIFF file.

I made a test with some real data and the warped output is a 1-bit binary image. Gdalinfo reports such images like this:

Image Structure Metadata:
  COMPRESSION=CCITTFAX4
  INTERLEAVE=BAND
...
Band 1 Block=20186x3 Type=Byte, ColorInterp=Palette
  Image Structure Metadata:
    NBITS=1
  Color Table (RGB with 2 entries)
    0: 255,255,255,255
    1: 0,0,0,255
6
  • Thanks for the detailed answer. I'm not familiar with editing the code directly. So I'll wait for a few few hours before trying to implement your suggestion. I'll post my results.
    – bpatey
    Apr 26 at 12:56
  • I've finally got a few free hours to try this but now I can't find a way to execute the edited GDAL script. I've looked in 3.36 and 3.30 but can't find anything. I'm probably making an extreme beginner mistake.
    – bpatey
    Apr 28 at 17:53
  • You must run the script from a command window, not through QGIS. Do you use Linux or Windows, and how did you install QGIS?
    – user30184
    Apr 28 at 18:03
  • I'm on Windows 10. and I installed QGIS using the downloaded *.msi file.
    – bpatey
    Apr 28 at 21:03
  • I do not know if it installs also GDAL command line tools. Anyway you can install them for example with the OSGeo4W installer, by downloading a zip file from gisinternals.com, or by using Conda. You can find instructions from the web, for example developers.planet.com/docs/integrations/qgis/install-qgis-gdal.
    – user30184
    Apr 28 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.