Grdimage producing grey and black boxes around geotiffs

I’m attempting to overlay some geotiff satellite photography on various other maps of the same location, and it keeps plotting them with opaque grey and black boxes around them, as seen here:


The actual photograph of interest is black and white one, which is a Corona satellite photograph. The blue marble image is just for testing purposes. The bash scripts that produce the above images are as follows.

For ds1039-2088da057.tif, the black and white strip:

 
place=“-R-550/550/-200/375+uk”
projection=“-JOa47E/30N/130/20c+v”

gmt begin ../images/test jpg
  gmt coast $projection $place -W -Ir -Glightgray -Slightblue
  gmt grdimage ../data/ds1039-2088da057.tif
gmt end show
 

And for the blue marble photograph:

 
coronaRegion=$(gmt mapproject -R../data/ds1039-2088da057.tif -WO)
#the result of this is -R43.292019697276/32.8605131559633/46.1327453184498/33.4976145056641+r
place=“-R-550/550/-200/375+uk”
projection=“-JOa47E/30N/130/20c+v”

gmt begin ../images/test jpg
  gmt coast $projection $place -W -Ir -Glightgray -Slightblue
  gmt grdcut @earth_day_01m $coronaRegion $projection -G../data/workingGrid.tif
  gmt grdimage ../data/workingGrid.tif
gmt end show

 
ds1039-2088da057.tif can be downloaded from the Corona Atlas & Referencing System at https://cast-ftp1.cast.uark.edu/coronaftp2/1039-2088d/1039-2088da/ds1039-2088da057.tif (file is ~400 MB)

Any help with this problem would be greatly appreciated.

The gray come from the CPT background color. Try setting
gmt gmtset COLOR_BACKGROUND white@100
before the coast command.

And, really? That image has ~2 meters resolution and 105787 columns?

And, really? That image has ~2 meters resolution and 105787 columns?

lol yeah, I'm using it for ancient canal/settlement traces in mesopotamia. My poor laptop took eighteen minutes to render it

gmt set COLOR_BACKGROUND white@100 doesn't have any effect, COLOR_NAN white@100 does turn the grey area white!! But not transparent.

![test|261x500](upload://gRrCzTIxCtg4iSQ0TOS65YeQCs.jpeg)

Editing to add: adding -Q to grdimage in addition to changing COLOR_NAN did finally get rid of the unwanted space on the blue marble image!! Trying it again with the corona image.

not working for the corona image :frowning: The outer grey box is turned white, but still not transparent, and the inner box is still black, even with bakcground and nan colors both set to white@100 and -Q on grdimage.

Hmm, maybe -Q0 would get rid of the black pixels but now I start to think that the gray ones come from the reprojection and we can’t set two colors as transparent.

-Q0 doesn’t help, and a bunch more fiddling with background, foreground and nan colors and other grdimage parameters has not yielded any results either.

Does grdview read geotiff? If so, maybe it has a better grip on transparency :slight_smile:

unless both NaN colors were set to the same value? Is it possible to specify NaN color for the reprojection process?

I tried to convert the source .tif (it’s a 8-bit image BTW) to .nc, and the resulting .nc can be plotted with all NaN’s correctly made transparent using gmt grdimage -Qred -Cgray. However, the image color scale is apparently not correct. -Qred is needed as it appears NaN color is red, and it seems unaffected by setting COLOR_NAN before calling grdimage -Qred -Cgray:

# subsample tif to reduce tiff size and greatly reduce plotting time:
gdal_translate -tr 0.0026853258162  0.0026853258162 ds1039-2088da057.tif ds1039-2088da057-1.nc

place="-R-550/550/-200/375+uk"
projection="-JOa47E/30N/130/20c+v"

gmt begin test png
  gmt coast $projection $place -W -Ir -Glightgray -Slightblue -B
  gmt grdimage ds1039-2088da057-1.nc -Qred -Cgray
gmt end show

resut:

BTW grdimage complains about grid registration in .nc but does not accept -rp:

grdimage [WARNING]: Guessing of registration in conflict between x and y, using gridline

if I call gmt grdimage ds1039-2088da057-1.nc -Qred -Cgray -rp, it fails:

grdimage [ERROR]: Unrecognized option -r

Still fiddling around with your suggestions, just wanted to say thank you for suggesting gdal_translate to downsample the image, being able to test somethiing in a second instead of twenty minutes is a gamechanger all by itself.

You are welcome! Suggesting and showing how to downsample that 400M image is the very first decent thing in this situation. Good luck learning gmt, gdal and other GIS tools!

This case is quite challenge and I had not had time to try to investigate it. No idea why we have to use -Qred instead of -Qblack. The NaN colors make no sense here (except perhaps for the reprojection part) as the data being integer it cannot have NaNs (the concept doesn’t exist).
When we have indexed images the colormap should allow to set one color as transparent directly in the CPT.

The grdimage complain about registration is because probably gdal_translate did something wrong. What it is saying is that both the and the y vectors have conflicting information about registration, and we cannot use -r because we cannot change the registration here. It is supposed that the code identifies the data registration and proceed accordingly.

I wonder if it might be an issue of grdimage reading the file as a grid rather than an image… somehow. Passing -D to grdimage , which (I think) is intended to specify that the passed file should be handled as an image rather than as a grid, gives the error gmt_img_project: Input image does not have sufficient (2) padding

No, that is not the issue. GMT is able to detect images from grids in most cases. -D, like the manual says, is only for very obscure cases. Certainly not GeoTIFF’s.

The below seems to be a workaround for plotting the .tif

gmt image appears capable of correctly making the assigned (NaN) color transparent:

gmt image ds1039-2088da057-1.tif -Gblack+t -R-550/550/-200/375+uk -JOa47E/30N/130/20c+v -DjBL -F+c0/0+pthinnest,red -B -B+gred@90 -png gmt_image_tiff

gmt image is apparently not supposed to do reprojection. It just throws the image on the plot.

gmt grdimage (with corresponding settings for psconvert) can be used to generate a georeferenced .tif with background map color matching the source Geotiff’s black background and zero width map frame:

gmt grdimage ds1039-2088da057-1.tif --COLOR_NAN=black -R-550/550/-200/375+uk -JOa47E/30N/130/20c+v -B00 -B+gblack -tif gmt_grdimage_tiff_filled --PS_CONVERT="A,W+g"

The resulting gmt_grdimage_tiff_filled.tif (794.9 KB) is the reprojected image strip on the empty black map background.

next gmt image call is needed to overlay the new .tif over the background map with black color made transparent: gmt image gmt_grdimage_tiff_filled.tif -Gblack+t -DjBL:

gmt image gmt_grdimage_tiff_filled.tif -Gblack+t -DjBL -R-550/550/-200/375+uk -JOa47E/30N/130/20c+v -B -B+gred@90 -png forum_post

(ds1039-2088da057-1.tif is the downsampled .tif: gdal_translate -tr 0.0026853258162 0.0026853258162 ds1039-2088da057.tif ds1039-2088da057-1.tif)

Sir you are a hero :sob: I have been bashing my head into this brick wall for weeks, next time I’ll post here sooner.