为 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。

以下是 exiftool 对从 GIMP 2.10 导出的图像的操作:

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;
}

相关内容