TIFF (Tagged Image File Format) files are structured around a set ofmetadata elements called “tags”. These tags contain information aboutthe image data, such as dimensions, color space, compression method, andother properties. Theijtiff package provides functions towork with these tags, allowing you to both read existing tags from TIFFfiles and understand which tags are supported.
Theget_supported_tags() function returns a namedinteger vector of all TIFF tags that are supported by theijtiff package. Let’s see what tags are available:
library(ijtiff)print(supported_tags<-get_supported_tags())#> ImageWidth ImageLength ImageDepth#> 256 257 32997#> BitsPerSample SamplesPerPixel SampleFormat#> 258 277 339#> PlanarConfiguration RowsPerStrip TileWidth#> 284 278 322#> TileLength Compression Threshholding#> 323 259 263#> XResolution YResolution XPosition#> 282 283 286#> YPosition ResolutionUnit Orientation#> 287 296 274#> Copyright Artist DocumentName#> 33432 315 269#> DateTime ImageDescription Software#> 306 270 305#> PhotometricInterpretation ColorMap#> 262 320The names in this vector are the human-readable tag names, and thevalues are the corresponding tag codes defined in the TIFFspecification.
To read the tags from an existing TIFF file, you can use theread_tags() function. Let’s read tags from a sample TIFFfile included with the package:
sample_tiff<-system.file("img","Rlogo.tif",package ="ijtiff")tags<-read_tags(sample_tiff)tags[[1]]#> $ImageWidth#> [1] 100#>#> $ImageLength#> [1] 76#>#> $ImageDepth#> [1] 1#>#> $BitsPerSample#> [1] 8#>#> $SamplesPerPixel#> [1] 4#>#> $SampleFormat#> [1] "unsigned integer data"#>#> $PlanarConfiguration#> [1] "contiguous"#>#> $RowsPerStrip#> [1] 76#>#> $TileWidth#> NULL#>#> $TileLength#> NULL#>#> $Compression#> [1] "LZW"#>#> $Threshholding#> [1] 1#>#> $XResolution#> [1] 299.99#>#> $YResolution#> [1] 299.99#>#> $XPosition#> NULL#>#> $YPosition#> NULL#>#> $ResolutionUnit#> [1] "inch"#>#> $Orientation#> [1] "top_left"#>#> $Copyright#> NULL#>#> $Artist#> NULL#>#> $DocumentName#> NULL#>#> $DateTime#> NULL#>#> $ImageDescription#> NULL#>#> $Software#> NULL#>#> $PhotometricInterpretation#> [1] "RGB"#>#> $ColorMap#> NULLTheread_tags() function returns a list where eachelement corresponds to the tags from one frame of the TIFF file.
Different tags have different data types and interpretations. Let’sexamine the values of some common tags:
TIFF files can contain multiple frames, and each frame can havedifferent tag values. Let’s examine a multi-frame TIFF file:
multi_frame_tiff<-system.file("img","Rlogo-banana.tif",package ="ijtiff")multi_frame_tags<-read_tags(multi_frame_tiff)length(multi_frame_tags)#> [1] 8We can compare tags across frames to see if they differ:
dimensions<-data.frame(Frame =character(),Width =integer(),Height =integer(),stringsAsFactors =FALSE)for (iinseq_along(multi_frame_tags)) { frame_name<-names(multi_frame_tags)[i] dimensions<-rbind( dimensions,data.frame(Frame = frame_name,Width = multi_frame_tags[[i]]$ImageWidth,Height = multi_frame_tags[[i]]$ImageLength,stringsAsFactors =FALSE ) )}dimensions#> Frame Width Height#> 1 frame1 100 78#> 2 frame2 100 78#> 3 frame3 100 78#> 4 frame4 100 78#> 5 frame5 100 78#> 6 frame6 100 78#> 7 frame7 100 78#> 8 frame8 100 78TIFF tags provide rich metadata about image files. Using theijtiff package, you can both read these tags from existingfiles and understand which tags are supported. This can be particularlyuseful for scientific image analysis, where metadata like resolution,units, and creation time can be crucial for proper interpretation ofresults.
For more information about TIFF tags, you can refer to the TIFF 6.0specification or visit the Library of Congress’sTIFFTag Reference.