Skip to content
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

Cannot make colours fully not visible #41

Closed
janceviciusjulius opened this issue Mar 15, 2022 · 4 comments
Closed

Cannot make colours fully not visible #41

janceviciusjulius opened this issue Mar 15, 2022 · 4 comments

Comments

@janceviciusjulius
Copy link

Good afternoon,

I have one question and I hope You are going to find some time to help me.

I have a file:
image

pixel values from 0 to 6 (at the moment)

All I want to do is to give colours for classified areas. For example, I want to colour all pixels with values 1 to blue. On the other hand, pixel with value 0 is no data pixels, and I do not want to colour them, I want to make when fully invisible. My demo code:
image

Result:
image

Maybe I do something wrong? I hope to get your answer. Thank You!

@neilflood
Copy link
Member

I believe that the TIFF format does not support the opacity channel. Other formats do (e.g. HFA, KEA), but I don't think TIFF does.

Anyway, apart from that, the best way to make null values invisible is to set the null value of the file. Then your display software (e.g. QGIS) will not display those pixels at all.

There are many ways to set the null value, depending on how you are creating the file. If you are using RIOS to create the output file, you can set this in the controls for the calculation, with something like this

from rios import applier
controls = applier.ApplierControls()
nullVal = 0
controls.setStatsIgnore(nullVal)

applier.apply(userFunc, infiles, outfiles, controls=controls)

Or, if you have created the file some other way, RIOS can do it using the calcstats module. Or, finally, you can do it directly using GDAL from Python, using the Band.SetNoDataValue() method.

@janceviciusjulius
Copy link
Author

janceviciusjulius commented Mar 15, 2022

I am so sorry, but if I understood correctly, I can use rat.setColourTable() just with UINT16, yes?

In additional, I would like to add, maybe You know how to change label's names in python? For instance:
image

For example label name now is 1, do you know how I can do this using gdal or something like that?

I am sorry for the additional question, but maybe you have heard. Thank You and have a nice day!

@neilflood
Copy link
Member

re: UINT16. Do you mean the datatype of the raster? This depends on the raster format, but with TIFF, you should be fine with either UINT8 or UINT16, and probably also UINT32.

re: labels. This also depends on the format. TIFF does not really support labels like this, but GDAL's (optional) PAM extensions do provide some support. This will be stored in a separate file with suffix .aux.xml, assuming that the GDAL you are using has this feature turned on. Whether the display software you are using will notice them is a separate problem.

@gillins
Copy link
Member

gillins commented Mar 15, 2022

re: uint16 and tif. I'd just be a bit careful with this, the result tends to be extremely slow to read with QGIS, Arc etc. Problem is that the tif standard requres 65535 entries for uint16 files in the colour table even if you only write a few. The software reading the file will not know that most of these entries are blank and will take a long time to read the lot in.

The other formats mentioned (HFA, KEA) do not have this limitation. As a bonus, they properly support RATs so you can write additional columns and have them stored in the file (whether you can see these depends on the software you use for reading).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants