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.
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.
- Do nothing with the nodata. Georeferencer just fills the slivers with black pixels. That is the default in QGIS georeferencer.
- 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.
- 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.
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.tif"
gdalwarp -r near -order 1 -co COMPRESS=NONE -dstalpha "/Temp/georef.tif" "/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"
It's a super hack, but it works.
- Do the georeferencing as normal.
- Open the created _modified.tif file in Paint.NET (https://www.getpaint.net/download.html) FREE!
- Bucket fill the black corner triangles with white. Save file as new TIFF (just in case).
- Drag-drop new TIFF into QGIS. It'll maintain the georeferencing and now have white corners.
If you can convert the image to PNG with an alpha channel, the georeferencer will be able to make the nodata areas transparent while keeping the black parts black.
I had a stack of B+W map scans, what finally worked is using ImageMagick to add an alpha channel to the image before georeferencing.
magick input.png png32:output.png
convert input.png png32:output.png
No other fiddly options are required in the georeferencer or the QGIS layer.
This works because it forces creation of an empty alpha channel. Many applications (e.g. Photoshop) will remove empty alpha channels when saving to PNG even if you try to include one.