[gdal-dev] Gdal_edit and TIFFTAG_EXTRASAMPLES

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[gdal-dev] Gdal_edit and TIFFTAG_EXTRASAMPLES

jratike80
Hi,

I have been searching an easy way to change the interpretion of 4-channel images between RGBA and RGB+undefined. Wouldn't if be useful to make gdal_edit to support also changing the TIFFTAG_EXTRASAMPLES metadata? Or do we have some other easy way for performing that task?

-Jukka Rahkonen-
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Gdal_edit and TIFFTAG_EXTRASAMPLES

Even Rouault-2

On samedi 30 septembre 2017 21:01:57 CEST Rahkonen Jukka (MML) wrote:

> Hi,

>

> I have been searching an easy way to change the interpretion of 4-channel

> images between RGBA and RGB+undefined. Wouldn't if be useful to make

> gdal_edit to support also changing the TIFFTAG_EXTRASAMPLES metadata? Or do

> we have some other easy way for performing that task?

 

Jukka,

 

I couldn't find a clean working way.

 

I had though that calling ds.GetRasterBand(4).SetColorInterpretation(gdal.GCI_AlphaBand or gdal.GCI_Undefined) would work (which could have been done by a new option of gdal_edit to modify the color interpretation). But for some (not clear, and likely unneeded) reason, this is restricted on a fresh new file, not yet "crystalized" (if you do it on an existing file, the change will only go to the .aux.xml file). I don't see a strong reason for this restriction, so it could probably be removed.

 

 

I've also tried the tiffset utility, but for some reason it absolutely wants to set at least 2 values in the ExtraSamples tag. Sounds like a bug of tiffset/libtiff

 

So to set alpha:

 

tiffset -s 338 2 2 0 test.tif

 

338 = code for ExtraSamples

2 = 2 values

2 = alpha unassociated

0 = undefined (ignored, and somehow invalid since that sample doesn't exist)

 

(should normally be tiffset -s 338 1 2 test.tif if that worked properly)

 

or to set undefined

 

tiffset -s 338 2 0 0 test.tif

(should normally be tiffset -s 338 1 0 test.tif if that worked properly)

 

GDAL will be happy, but technically the TIFF is not so correct with that 2nd extra sample, since for a Photometric=RGB with 4 samples, you should just have 1 extra sample.

 

 

I would also have suggested to just take your favorite hexadecimal editor, and just alter the proper byte, but I don't feel this will be a popular option ;-)

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Gdal_edit and TIFFTAG_EXTRASAMPLES

Even Rouault-2

Updates:

 

1) I've improved the GTiff driver to support updating color interpretation in udpate mode

2) I've improved gdal_edit to support a

-colorinterp_X red|green|blue|alpha|undefined option where X is the band number.

3) I've fixed "tiffset -s ExtraSamples 1 val" to work (the issue was specific to specifying just one value indeed)

 

Note that with libtiff when you change an existing tag, the file size will slightly increase each time you do a change.

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Gdal_edit and TIFFTAG_EXTRASAMPLES

jratike80

Thanks Even.


I would guess that also other users who have both RGB+alpha and RGB+NIR images will appreciate these changes. At least for me it has been plain mystery when the fourth band appears as alpha and when as undefined, and how to change the interpretation despite using VRT.


-Jukka-


Lähettäjä: Even Rouault <[hidden email]>
Lähetetty: 1. lokakuuta 2017 22:54
Vastaanottaja: [hidden email]
Kopio: Rahkonen Jukka (MML)
Aihe: Re: [gdal-dev] Gdal_edit and TIFFTAG_EXTRASAMPLES
 

Updates:

 

1) I've improved the GTiff driver to support updating color interpretation in udpate mode

2) I've improved gdal_edit to support a

-colorinterp_X red|green|blue|alpha|undefined option where X is the band number.

3) I've fixed "tiffset -s ExtraSamples 1 val" to work (the issue was specific to specifying just one value indeed)

 

Note that with libtiff when you change an existing tag, the file size will slightly increase each time you do a change.

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev