![]() The total image size is 4096x4096px, which is a grid of 8x8 tiles, so there are 64 tiles. ![]() To get the Green values, you need to go to TileOffset. TileOffsets: The byte offsets of each tile in the image, by sample, so the red values for the first tile start at TileOffsets, and the red values for the second tile start at TileOffsets.TileLength: 512 The tile height, in pixels again.TileWidth: 512 The image is divided into tiles, 512 pixels wide.Explaining why exactly this is true is a bit out of scope of this blog post, but you can read about it at the LZW reference linked above. If the hypothesis that adjacent pixels often resemble one another is true, then the data compressor can do a better job of compressing the data, since it is better able to compress long strings of contiguous values. For example, if the first value was 100% red, it would be 255, and if the second and third pixels were also 100% red, they would both be stored as 0. The TIFF encoder changes each pixel value to the difference from the previous pixel, rather than an absolute value. TIFF takes advantage of this fact with a preprocessing step, prior to compressing the image. Look at all that blue water in the sample image for example, or imagine a farmer’s field. What does this mean, and why does TIFF use this? The idea is that adjacent pixels in an image tend to resemble one another. The value for this image is 2, which means “ Horizontal differencing”. Predictor: 2 This value is related to compression, but not quite the same thing.The Compression value for this image is set to 5, which is LZW compression. As is this is TIFF, there are many ways this can happen. Compression: 5 As with many image formats, image data in TIFFs can be compressed.Let’s go through a few more tags to complete our understanding of this image: We‘re close to being able to do that, but we need to understand a few more things to be able to get at that pixel. Now that we understand how the pixel data is laid out, why don’t we try to read that first pixel? We will pretend it isn’t compressed for now, but we will discuss how compression works later: +-+ Byte Offset | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | | | Color | R R R R G G G G B B B B A A A A | | | Value | FF 00 00 00 00 FF 00 00 00 00 FF 00 FF FF FF FF | +-+ The pixel data would be written as in the following diagram. ![]() Imagine that each square is a 100% color value for each color sample, and the final value is black, like this: For example, imagine a 2x2 TIFF file with the same TIFF settings as our sample image. Every pixel of colour data is written by writing all of the red values, all of the green values, all the blue values, then all of the alpha values. PlanarConfiguration: 2 This means that Red,Green,Blue, and Alpha data are stored separately.SampleFormat: This means that each sample is unsigned integer data, which means each pixel value is a number from 0–255.BitsPerSample: This means that each sample is stored with 8 bits.What does an alpha channel mean when we’re representing geospatial data? How can part of the earth be transparent? After speaking with fellow Planeteer Kelsey Jordahl, I learned that it really is an alpha channel: but in this case, a transparent pixel means no data! Since Planet doesn’t image in places like the middle of the Pacific Ocean, there needs to be a good way to indicate no data in mosaics. So the fourth colour channel is an alpha channel. ExtraSamples: 2 The value is set to 2, which means “ Associated alpha data (with pre-multiplied color)”.The first three are easy to understand, RGB, but what is the 4th? Well, we can figure that out with: SamplesPerPixel: 4 The number of color channels per pixel.PhotometricInterpretation: 2 This is the color space of the image, which means whether the image is black and white, RGB, etc.ImageLength: 4096 The height of the image.ImageWidth: 4096 The width of the image.I’ll summarize the values that are important for us to read a pixel below: The tag dump should give us all the information we need to read a pixel out of the image. You can view the full output of this in this gist. Let’s run the script: $ go run tiff-dump.go la.tif Version: 42 Byte Order: little endian IFD 0: You may think this is cheating, but we already learned how to read these tags without special tools in the last post, so we are simply automating what we learned last time. To begin understanding this file, we’re going to decode all of the TIFF tags with a simple dumper tool. An image of Los Angeles from Planet’s February 2018 Basemap.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |