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.
3 Answers
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"
-
If you are able to use gdal_translate, a fourth option is to use it to choose an arbitrary NoData value or make space for a nodata value. For example:
gdal_translate -a_nodata 177 "/test/georef.png" "/Temp/pregeoref.png"
orgdal_translate -a_nodata 0 -scale 0 255 1 255 "/test/georef.png" "/Temp/pregeoref.png"
orgdal_translate -a_nodata 255 -scale 0 255 0 254 "/test/georef.png" "/Temp/pregeoref.png"
and then georeference the pre-processed file. Georeferencing a file with a nodata value will use that to mark the newly missing data in the georeferenced file.– Dave XOct 30, 2020 at 15:55 -
I do not believe it does. For gdal_translate the order is input-output and the command is using
"/Temp/georef.png" "/test/georef_modified.tif"
. Oct 30, 2020 at 16:13 -
Right. I will edit, thank you. The commands still worked because the .png named tiff was used in the next command. Oct 30, 2020 at 16:22
-
Yes. I was a little confused when I tried to add GCPs to a png file--I could scale and set a nodata value and still get a .png formatted result, but if I tried the GCPs, the result was a TIFF– Dave XOct 30, 2020 at 16:43
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.