필터 지우기
필터 지우기

Is there a way to write a GeoTiff file with Color and Alpha Channel Data using geotiffwrite?

조회 수: 22 (최근 30일)
Is there a way to write a GeoTiff file with Color and Alpha Channel Data using geotiffwrite? I tried defining a TiffTag for "ExtraSamples" as shown below, but I got an warning message. The image (img) is a n x m x 4 RGB image where the 4 index on dimension 3 is the alpha channel.
geotiffwrite('img.tif', img, R, 'TiffTags', struct('ExtraSamples', Tiff.ExtraSamples.Unspecified))
Warning Message:
Warning: Sum of Photometric color channels and ExtraSamples does not match the value specified in SamplesPerPixel.
Writing with this configuration will error in a future release. To correct the configuration, define the non-color channels as ExtraSamples.
I get an error if I try defining the "SamplesPerPixel" TiffTag as 4. I don't know how to define the non-color channels as ExtraSamples using geotiffwrite.
I used the following example for Tiff objects to try to create the alpha channel data:

답변 (1개)

Shubham
Shubham 2023년 5월 31일
Hi Sonoma,
Yes, it is possible to write a GeoTiff file with color and alpha channel data using geotiffwrite function in MATLAB. However, you need to correctly define the "ExtraSamples" TiffTag in order to do so.
From the error and warning messages you received, it seems like the "ExtraSamples" TiffTag was not defined correctly. Instead of defining it as "Unspecified", you can define the non-color channels as "ExtraSamples". For example, you can modify the "TiffTags" struct as follows:
TiffTags.Photometric = Tiff.Photometric.RGB;
TiffTags.BitsPerSample = 8;
TiffTags.SamplesPerPixel = 4;
TiffTags.ExtraSamples = Tiff.ExtraSamples.UnassociatedAlpha;
This sets the "Photometric" tag to RGB, "BitsPerSample" to 8 (assuming your image has 8-bit color depth), "SamplesPerPixel" to 4 (indicating that there are 4 color channels), and "ExtraSamples" to "UnassociatedAlpha" (indicating that the extra channel is an alpha channel that is not associated with any specific color).
Then, you can pass this "TiffTags" struct to the geotiffwrite function like this:
geotiffwrite('img.tif', img, R, 'TiffTags', TiffTags);
This should allow you to write a GeoTiff file with color and alpha channel data using geotiffwrite function in MATLAB.
  댓글 수: 1
Sonoma Rich
Sonoma Rich 2023년 5월 31일
Shubham,
when I run the script using your suggestion, I get the following error:
Error using geotiffwrite (line 245)
Expected TiffTags.BitsPerSample to match one of these values:
'Artist', 'Compression', 'Copyright', 'DateTime', 'DocumentName', 'DotRange', 'ExtraSamples', 'FillOrder', 'Group3Options',
'Group4Options', 'HalfToneHints', 'HostComputer', 'ICCProfile', 'ImageDepth', 'ImageDescription', 'InkNames', 'InkSet', 'JPEGColorMode',
'JPEGQuality', 'Make', 'MaxSampleValue', 'MinSampleValue', 'Model', 'NumberOfInks', 'Orientation', 'PageName', 'PageNumber',
'PhotometricInterpretation', 'Photoshop', 'PlanarConfiguration', 'PrimaryChromaticities', 'RPCCoefficientTag', 'ReferenceBlackWhite',
'ResolutionUnit', 'RichTIFFIPTC', 'RowsPerStrip', 'SGILogDataFmt', 'SMaxSampleValue', 'SMinSampleValue', 'SToNits', 'Software',
'TargetPrinter', 'Thresholding', 'TileLength', 'TileWidth', 'TransferFunction', 'WhitePoint', 'XMP', 'XPosition', 'XResolution',
'YCbCrCoefficients', 'YCbCrPositioning', 'YCbCrSubSampling', 'YPosition', 'YResolution', 'ZipQuality'
The input, 'BitsPerSample', did not match any of the valid values.
I am running Matlab 2020b. It this feature used on later versions of Matlab.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Data에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by