TIFF画像に線形カラースペースを割り当てる

TIFF画像に線形カラースペースを割り当てる

線形カラースペースを持つと思われるTIFF画像があります

exiftool alps.tif
ExifTool Version Number         : 11.88
File Name                       : alps.tif
Directory                       : .
File Size                       : 2.1 GB
File Modification Date/Time     : 2022:05:15 14:13:32+02:00
File Access Date/Time           : 2022:06:09 18:42:11+02:00
File Inode Change Date/Time     : 2022:06:08 17:03:37+02:00
File Permissions                : rw-------
File Type                       : TIFF
File Type Extension             : tif
MIME Type                       : image/tiff
Exif Byte Order                 : Little-endian (Intel, II)
Image Width                     : 38160
Image Height                    : 15930
Bits Per Sample                 : 32
Compression                     : LZW
Photometric Interpretation      : BlackIsZero
Samples Per Pixel               : 1
Planar Configuration            : Chunky
Predictor                       : None
Tile Width                      : 256
Tile Length                     : 256
Tile Offsets                    : (Binary data 99752 bytes, use -b option to extract)
Tile Byte Counts                : (Binary data 63037 bytes, use -b option to extract)
Sample Format                   : Float
Pixel Scale                     : 0.000277777777777778 0.000277777777777778 0
Model Tie Point                 : 0 0 0 5.79999999999998 48.1251388888889 0
Geo Tiff Version                : 1.1.0
GT Model Type                   : Geographic
GT Raster Type                  : Pixel Is Area
Geographic Type                 : WGS 84
Geog Citation                   : WGS 84
Geog Angular Units              : Angular Degree
Geog Semi Major Axis            : 6378137
Geog Inv Flattening             : 298.257223563
Image Size                      : 38160x15930
Megapixels                      : 607.9

この画像を GIMP 2.10 で開くと、sRGB であると表示されます。

GIMP 2.10 からエクスポートされた画像に対する exiftool の結果は次のとおりです。

exiftool /dev/shm/slask.tiff
ExifTool Version Number         : 11.88
File Name                       : slask.tiff
Directory                       : /dev/shm
File Size                       : 1217 kB
File Modification Date/Time     : 2022:06:09 18:51:55+02:00
File Access Date/Time           : 2022:06:09 18:52:07+02:00
File Inode Change Date/Time     : 2022:06:09 18:51:55+02:00
File Permissions                : rw-rw-r--
File Type                       : TIFF
File Type Extension             : tif
MIME Type                       : image/tiff
Exif Byte Order                 : Little-endian (Intel, II)
Image Width                     : 512
Image Height                    : 512
Bits Per Sample                 : 32
Compression                     : Uncompressed
Photometric Interpretation      : BlackIsZero
Document Name                   : /dev/shm/slask.tiff
Image Description               : Created with GIMP
Orientation                     : Horizontal (normal)
Samples Per Pixel               : 1
Rows Per Strip                  : 128
X Resolution                    : 300
Y Resolution                    : 300
Planar Configuration            : Chunky
Page Name                       : Bakgrund
Resolution Unit                 : inches
Subfile Type                    : Reduced-resolution image
Strip Offsets                   : 1049421
Strip Byte Counts               : 196608
Sample Format                   : Float
Profile CMM Type                : Little CMS
Profile Version                 : 4.3.0
Profile Class                   : Display Device Profile
Color Space Data                : GRAY
Profile Connection Space        : XYZ
Profile Date Time               : 2022:06:09 16:48:40
Profile File Signature          : acsp
Primary Platform                : Apple Computer Inc.
CMM Flags                       : Not Embedded, Independent
Device Manufacturer             : 
Device Model                    : 
Device Attributes               : Reflective, Glossy, Positive, Color
Rendering Intent                : Perceptual
Connection Space Illuminant     : 0.9642 1 0.82491
Profile Creator                 : Little CMS
Profile ID                      : 0
Profile Description             : GIMP built-in D65 Linear Grayscale
Profile Copyright               : Public Domain
Media White Point               : 0.95045 1 1.08905
Gray Tone Reproduction Curve    : (Binary data 16 bytes, use -b option to extract)
Device Mfg Desc                 : GIMP
Device Model Desc               : D65 Linear Grayscale
Image Size                      : 512x512
Megapixels                      : 0.262
Thumbnail TIFF                  : (Binary data 196824 bytes, use -b option to extract)

/dev/shm/slask.tiff私の仮説をテストするために、 のカラー解釈データをに割り当てたいと思いますalps.tif。ピクセル値を変更したくないことに注意してください。メタデータを更新したいだけですが、どうやら GIMP ではそれができないようです。

使用できるようですtificcが、GeoTIFF タグが削除され、geotifcp を使用してタグを再度追加しようとすると、強度の解釈が失われます。

答え1

この解決策にはあまり満足していませんが、自分でやってみて、ピクセル値を exr ファイルにダンプすることはできます。

//@ {"target":{"name":"geotiff2exr.o", "pkgconfig_libs":["OpenEXR"]}}

#include "./geotiff_loader.hpp"
#include "./file.hpp"

#include <OpenEXR/ImfIO.h>
#include <OpenEXR/ImfOutputFile.h>
#include <OpenEXR/ImfChannelList.h>

int main(int argc, char** argv)
{
    if(argc != 3)
    {
        fprintf(stderr, "Usage: geotiff2exr input output\n");
        return 1;
    }

    auto tiff = make_tiff(argv[1]);
    auto const info = get_image_info(tiff.get());
    auto pixels = load_floats(tiff.get(), info);
    auto src_ptr = static_cast<float const*>(pixels.get());
    auto const w = info.size.sizes[0];
    auto const h = info.size.sizes[1];

    Imf::Header header{static_cast<int>(w), static_cast<int>(h)};
    header.channels().insert("Y", Imf::Channel{Imf::FLOAT});

    Imf::FrameBuffer fb;
    fb.insert("Y",
              Imf::Slice{Imf::FLOAT,
                         (char*)(src_ptr),
                         sizeof(float),
                         sizeof(float) * w});

    Imf::OutputFile dest{argv[2], header};
    dest.setFrameBuffer(fb);
    dest.writePixels(h);

    return 0;
}

関連情報