I am trying to work with .tiff files and I want to ensure that I don't alter the files more than intended, so if I don' make any changes, I expect a 100% identical output with same file-size.

To validate that I, initially read and saved a tiff-File to see if there is any unexpected change, and yes, the file-size is ~3% larger.

This is my code:

import tifffile as tiff

image_file = "Image.tiff"
output_file = "Processed_Image.tiff"
image_array = tiff.imread(image_file)
tags = tiff.TiffFile(image_file).pages.pages[0].tags
compression = tags["Compression"].value
rowsperstrip = tags["RowsPerStrip"].value
tiff.imwrite(output_file, image_array, compression=compression, rowsperstrip=rowsperstrip)

I can't find a way to add these two tags:

tags["StripOffsets"].value
tags["StripByteCounts"].value

I analysed the differences of the array itself,Tiff-Object and with a tool called Exiftool.exe and found out there are differences in StripOffsets and StripByteCounts, but the compression, shape and array-values are identical (np.array_equal() returns True)

I tried to pass over as many arguments to the imwrite() function as possible, so it doesn't use unwanted default values to change the image.

0

There are 0 best solutions below