2

After georeferencing a black and white TIFF image, the QGIS Raster Georeferencer fills the corners with black pixels, creating black elongated triangles along the edges of the new image. I could not find anything in the Georeferencer settings to force these filler pixels to be while. I want to set all white pixels transparent when importing the image into QGIS, so eliminating the black corners is preferred. I tried editing the georeferenced TIFF image but it loses the reference data on saving. I tried the GeoTIFF tools (listgeo.exe and geotifcp.exe) but writing the data back to the TIFF image using geotifcp.exe gives a warning "LZW compression is not available to due to Unisys patent enforcement." It would be ideal if QGIS can be set to force the padding colour to white otherwise I am happy to try any other tools, methods or instructions how to achieve what I want.

Black borders added to georeferenced image marked in red X

1

If image gets rotated in the georeferencing process it is inevident that triangle shaped nodata areas appear at the corners of the georeferenced image. There are a few different ways to deal with the nodata area. I clipped a part of your image to be used as a test case.

enter image description here

  1. Do nothing with the nodata. Georeferencer just fills the slivers with black pixels. That is the default in QGIS georeferencer.

enter image description here

  1. Mark a certain pixel value to meand nodata so the viewer can handle those pixels as transparent. QGIS gives an option to mark black pixels as nodata but unfortunately it makes all black pixels transparent. If you had a good quality pure black and white scan you would see nothing in the map but now only the black border around Warner Estate disappears.

enter image description here

  1. Add alpha band that defines the nodata area. This method saves the real black pixels in the map but hides the slivers if the image viewer can deal with alpha band.

enter image description here

QGIS georeferencer does not have a direct option for writing alpha band but you can generate the GDAL commands from the user interface "File - Generate GDAL Script". You can edit the script by hand so that it includes the option for alpha band. Then run the commands from the command line. In my tests I used commands

gdal_translate -of GTiff -gcp 7.64286 140.143 163.767 -5.74727 -gcp 380.538 323.722 270.053 -430.893 -gcp 67.4699 362.241 -3.98671 -370.066 "/test/georef.png" "/Temp/georef.png"
gdalwarp -r near -order 1 -co COMPRESS=NONE -dstalpha "/Temp/georef.png" "/test/georef_modified.tif"

The program that you use seems to be quite old. The last LZW patent has expired in 2004 https://en.wikipedia.org/wiki/Lempel–Ziv–Welch#Patents. If you want to use LZW compression with the QGIS georeferencer edit the gdal_translate command a bit more:

gdalwarp -r near -order 1 -co COMPRESS=LZW -dstalpha "/Temp/georef.png" "/test/georef_modified.tif"
0

In the Georeferencer, check the 'Use 0 for transparency when needed' which will make the black pixels go away. To avoid white pixels, go to Layer properties and set 255 as the additional nodata value. enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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