New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow grdimage to process byte images without indexed colors, via CPT #7827
Conversation
See forum discussion for background. This PR is almost there but has a 1/3 fraction issue...Perhaps @joa-quim knows what to improve.
OK, here's how I think this should work
This, with the example tif file used above would NOT render the expected result, but that is the image's fault. EDIT: If we have NoDataValue info, that value should not count as class and be assigned the color white. |
If the image (via gdalinfo) says NoData is 0, how come our image say header->nan_value = NaN? Must get set somewhere, no? |
Yes, should be somewhere in gdalread. Ofc it shouldn't be NaN for an integer type and that's likely an unnoticed bug so far because our use of it has always been for grids where everything ends up as float32. |
Note
so look maybe we can get it even if not a float or rub grid? |
It is set in
but it has to be set somewhere else too. Edit: yes, we can find it in
So each band has a NoData info. |
After latest updates, using this CPT (fix typo, otherwise the same):
Compare with plot at top. |
Now doing this check:
and then the node index gets start subtracted so 1 becomes 0, the first category. If 0, or if nan is set then we place the CPT nan color in the output image and we also turn on -Q. Seems OK? |
Shouldn't the |
Sure, will do that too. |
Done. |
We're getting an error like Was there some logic added to ensure that only Byte images with a single band require a CPT? |
Are those 3 bands not part of a RGB image? I mean, are they a pack of 3 indexed images? Does that thing exist in nature? |
We're passing in a GeoTIFF - rgb_image.tif.txt (remove the .txt extension after download). This is the output from
and from gdalinfo:
|
And what is the command that generates that error? When I plot it with GMT.jl default setting it works fine (also shown the GMT generated command that actually does the job)
|
Ran gmt [DEBUG]: GMT_Create_Session: Terminal width = 190
gmt [DEBUG]: Obtained the ppid from parent: 13262
gmt [DEBUG]: Enter: gmtinit_new_GMT_ctrl
gmt [DEBUG]: GMT->session.SHAREDIR = /home/user/mambaforge/envs/pygmt/share/gmt
gmt [DEBUG]: GMT->session.HOMEDIR = /home/user
gmt [DEBUG]: GMT->session.USERDIR = /home/user/.gmt [created]
gmt [DEBUG]: GMT->session.CACHEDIR = /home/user/.gmt/cache [created]
gmt [DEBUG]: GMT: 0. Will try to find subdir=postscriptlight stem = PSL_custom_fonts suffix=.txt
gmt [DEBUG]: GMT: 1. gmt_getsharepath trying current dir
gmt [DEBUG]: GMT: 2. gmt_getsharepath trying USERDIR /home/user/.gmt
gmt [DEBUG]: GMT: 3. gmt_getsharepath trying USERDIR subdir /home/user/.gmt/postscriptlight
gmt [DEBUG]: GMT: 4. gmt_getsharepath trying SHAREDIR subdir /home/user/mambaforge/envs/pygmt/share/gmt/postscriptlight
gmt [DEBUG]: GMT: 5. gmt_getsharepath trying SHAREDIR /home/user/mambaforge/envs/pygmt/share/gmt
gmt [DEBUG]: GMT: 6. gmt_getsharepath failed
gmt [DEBUG]: Map distance calculation will be Cartesian
gmt [DEBUG]: Exit: gmtinit_new_GMT_ctrl
gmt [DEBUG]: Enter: New_PSL_Ctrl
gmt [DEBUG]: Exit: New_PSL_Ctrl
gmt [DEBUG]: Enter: gmt_manage_workflow
gmt [DEBUG]: Exit : gmt_manage_workflow
gmt [DEBUG]: Enter: PSL_beginsession
gmt [DEBUG]: Exit : PSL_beginsession
gmt [DEBUG]: Enter: PSL_setdefaults
gmt [DEBUG]: Exit : PSL_setdefaults
gmt [DEBUG]: Enter: gmtlib_io_init
gmt [DEBUG]: Exit : gmtlib_io_init
gmt [DEBUG]: Enter: gmt_hash_init
gmt [DEBUG]: Exit: gmt_hash_init
gmt [DEBUG]: Enter: gmt_hash_init
gmt [DEBUG]: Exit: gmt_hash_init
gmt [DEBUG]: Enter: gmt_reload_settings
gmt [DEBUG]: The PROJ_GEODESIC set to Vincenty
gmt [DEBUG]: Look for file /home/user/gmt.conf
gmt [DEBUG]: Look for file /home/user/.gmt/gmt.conf
gmt [DEBUG]: Look for file /home/user/.gmt/server/gmt.conf
gmt [DEBUG]: Look for file /home/user/.gmt/cache/gmt.conf
gmt [DEBUG]: Could not find file gmt.conf
gmt [DEBUG]: Exit: gmt_reload_settings
gmt [DEBUG]: Enter: gmtlib_plot_C_format
gmt [DEBUG]: Exit: gmtlib_plot_C_format
gmt [DEBUG]: Enter: gmtinit_get_history
gmt [DEBUG]: Initialize FFTW with 16 threads.
gmt [DEBUG]: GMT_Create_Session initialized GMT structure
gmt [DEBUG]: Loading core GMT shared library: libgmt.so
gmt [DEBUG]: Shared Library # 0 (core). Path = libgmt.so
gmt [DEBUG]: Loading GMT plugins from: /home/user/mambaforge/envs/pygmt/lib/gmt/plugins
gmt [DEBUG]: Shared Library # 1 (supplements). Path = /home/user/mambaforge/envs/pygmt/lib/gmt/plugins/supplements.so
gmt [DEBUG]: Revised options: quick png
begin [INFORMATION]: Creating a workflow directory /home/user/.gmt/sessions/gmt_session.13262
begin [DEBUG]: The PROJ_GEODESIC set to Vincenty
begin [DEBUG]: Look for file /home/user/gmt.conf
begin [DEBUG]: Look for file /home/user/.gmt/gmt.conf
begin [DEBUG]: Look for file /home/user/.gmt/server/gmt.conf
begin [DEBUG]: Look for file /home/user/.gmt/cache/gmt.conf
begin [DEBUG]: Could not find file gmt.conf
begin [DEBUG]: Set session name to be quick png
begin [DEBUG]: Begin Workflow. Session ID = 13262. Directory /home/user/.gmt/sessions/gmt_session.13262 created.
begin [DEBUG]: GMT now running in modern mode [Session ID = 13262]
gmt [DEBUG]: Use PS filename /home/user/.gmt/sessions/gmt_session.13262/gmt_0.ps-
gmt [DEBUG]: gmtinit_get_current_panel: No current panel selected so not in subplot mode
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Replace file rgb_image.tif with path rgb_image.tif
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Replace file rgb_image.tif with path rgb_image.tif
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Object ID 0 : Registered Grid File rgb_image.tif as an Input resource with geometry Surface [n_objects = 1]
gmt [DEBUG]: gmtapi_begin_io: Input resource access is now enabled [container]
gmt [DEBUG]: gmtapi_import_grid: Passed ID = 0 and mode = 1
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Calling nc_open on rgb_image.tif, ncid = 0, err = -51
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Calling nc_open on rgb_image.tif, ncid = 0, err = -51
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Calling nc_open on rgb_image.tif, ncid = 0, err = -51
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Calling nc_open on rgb_image.tif, ncid = 0, err = -51
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Calling nc_open on rgb_image.tif, ncid = 0, err = -51
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Calling nc_open on rgb_image.tif, ncid = 0, err = -51
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Calling nc_open on rgb_image.tif, ncid = 0, err = -51
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [DEBUG]: Look for file rgb_image.hdr in /home/user/.gmt
gmt [DEBUG]: Look for file rgb_image.hdr in /home/user/.gmt/cache
gmt [DEBUG]: Look for file rgb_image.hdr in /home/user/.gmt/server
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [INFORMATION]: File rgb_image.tif reads with GDAL driver GTiff
gmt [DEBUG]: Found readable file rgb_image.tif
gmt [INFORMATION]: Cartesian input grid
gmt [INFORMATION]: Cartesian input grid
gmt [DEBUG]: GMT_End_IO: Input resource access is now disabled
gmt [DEBUG]: GMT_Destroy_Data: freed memory for a Grid for object 0
gmt [DEBUG]: gmtlib_unregister_io: Unregistering object no 0 [n_objects = 0]
gmt [DEBUG]: gmtlib_unregister_io: Object no 0 has non-NULL resource pointer
gmt [DEBUG]: Look for file -20116086.80687862/20116086.80687862/-20116086.80687862/20116086.80687862 in /home/user/.gmt
gmt [DEBUG]: Look for file -20116086.80687862/20116086.80687862/-20116086.80687862/20116086.80687862 in /home/user/.gmt/cache
gmt [DEBUG]: Look for file -20116086.80687862/20116086.80687862/-20116086.80687862/20116086.80687862 in /home/user/.gmt/server
gmt [DEBUG]: Modern: Adding -JX15c/15c to options since there is no history available.
gmt [DEBUG]: Revised options: rgb_image.tif -Vd -R-20116086.80687862/20116086.80687862/-20116086.80687862/20116086.80687862 -JX15c/15c
grdimage [DEBUG]: History: Process -R-20116086.80687862/20116086.80687862/-20116086.80687862/20116086.80687862
grdimage [DEBUG]: History: Process -JX15c/15c
grdimage [DEBUG]: Look for file -20116086.80687862/20116086.80687862/-20116086.80687862/20116086.80687862 in /home/user/.gmt
grdimage [DEBUG]: Look for file -20116086.80687862/20116086.80687862/-20116086.80687862/20116086.80687862 in /home/user/.gmt/cache
grdimage [DEBUG]: Look for file -20116086.80687862/20116086.80687862/-20116086.80687862/20116086.80687862 in /home/user/.gmt/server
grdimage [DEBUG]: Got regular w/e/s/n for region (-20116086.80687862/20116086.80687862/-20116086.80687862/20116086.80687862)
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Replace file rgb_image.tif with path rgb_image.tif
grdimage [DEBUG]: Replace file rgb_image.tif with rgb_image.tif
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: rgb_image.tif may be image or grid. Open via GDAL for checking
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Replace file rgb_image.tif with path rgb_image.tif
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Replace file rgb_image.tif with path rgb_image.tif
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Object ID 1 : Registered Image File rgb_image.tif as an Input resource with geometry Surface [n_objects = 1]
grdimage [DEBUG]: gmtapi_begin_io: Input resource access is now enabled [container]
grdimage [DEBUG]: gmtapi_import_image: Passed ID = 1 and mode = 513
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [INFORMATION]: Cartesian input grid
grdimage [DEBUG]: GMT_End_IO: Input resource access is now disabled
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Calling nc_open on rgb_image.tif, ncid = 0, err = -51
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Calling nc_open on rgb_image.tif, ncid = 0, err = -51
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Calling nc_open on rgb_image.tif, ncid = 0, err = -51
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Calling nc_open on rgb_image.tif, ncid = 0, err = -51
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Calling nc_open on rgb_image.tif, ncid = 0, err = -51
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Calling nc_open on rgb_image.tif, ncid = 0, err = -51
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Calling nc_open on rgb_image.tif, ncid = 0, err = -51
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [DEBUG]: Look for file rgb_image.hdr in /home/user/.gmt
grdimage [DEBUG]: Look for file rgb_image.hdr in /home/user/.gmt/cache
grdimage [DEBUG]: Look for file rgb_image.hdr in /home/user/.gmt/server
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [INFORMATION]: File rgb_image.tif reads with GDAL driver GTiff
grdimage [DEBUG]: Found readable file rgb_image.tif
grdimage [INFORMATION]: Cartesian input grid
grdimage [INFORMATION]: Cartesian input grid
grdimage [ERROR]: Byte image without indexed color requires a CPT via -C
grdimage [DEBUG]: gmtlib_get_graphics_item: Fig: 0 Subplot: 2 Panel: () Inset: 0
grdimage [DEBUG]: No current cpt file found
grdimage [DEBUG]: GMT now running in modern mode [Session ID = 13262]
grdimage [DEBUG]: Revised options: show
end [DEBUG]: End Workflow. Session ID = 13262. Directory /home/user/.gmt/sessions/gmt_session.13262 removed.
end [DEBUG]: No figure file /home/user/.gmt/sessions/gmt_session.13262/gmt.figures - nothing to do
end [DEBUG]: No figure file /home/user/.gmt/sessions/gmt_session.13262/gmt.figures - nothing to do
end [DEBUG]: Got session name as quick and default graphics formats as png
end [INFORMATION]: Process GMT figure queue: 1 figures found
end [INFORMATION]: Processing GMT figure #0 [quick png ]
end [INFORMATION]: Destroying the current workflow directory /home/user/.gmt/sessions/gmt_session.13262
end [DEBUG]: Delete gmt.conf
end [DEBUG]: Delete gmt.session
grdimage [DEBUG]: gmtlib_garbage_collection: Destroying object: C=0 A=0 ID=1 W=Input F=Image M=File S=Unused P=55776ef21aa0 N=rgb_image.tif
grdimage [DEBUG]: GMTAPI_Garbage_Collection freed 1 memory objects
grdimage [DEBUG]: gmtlib_unregister_io: Unregistering object no 1 [n_objects = 0]
gmt [DEBUG]: Entering GMT_Destroy_Session
gmt [DEBUG]: gmtlib_get_graphics_item: Fig: 0 Subplot: 2 Panel: () Inset: 0 Using |
Our ex52 example also fails with the same error:
|
Need to ensure that the image has only one band and no indexed color. Closes #7827.
Need to ensure that the image has only one band and no indexed color. Closes #7827.
See forum discussion for background. This PR is almost there - 45 minutes of work is not bad. Perhaps @joa-quim knows what to improve. There are an issue to resolve:
The image has values 0-8 for a total of 9, but CPT has 8. Since these are "keys" to categories 1-8 there are only 8 but GMT does not know the image contains categories and not index into a color table. I inserted a 0 row (white) to make this work for now.
Perhaps a 1-byte image without color table is expected to hold categories? If so we can subtract one and be OK
Should not be too hard to fix this but want @joa-quim input on this. See new renderer grdimage_img_byte_index.