Zeroing/blacking out pixels in a .tiff-like file (.svs or .ndpi)

130 views Asked by At

I am trying to zero out the pixels in some .tiff-like biomedical scans (.svs & .ndpi) by changing values directly in the binary file.

For reference, I am using the docs on the .tiff format here.

As a sanity check, I've confirmed that the first two bytes have values 73 and 73 (or I and I in ASCII), meaning it is little-endian, and that the two next bytes are the value 42 (both these things are expected as according to the docs just mentioned).

I wrote a Python script that reads the IFD (Image File Directory) and its components, but I am having troubles proceeding from there.

My code is this:

with open('scan.svs', "rb") as f:

    # Read away the first 4 bytes:
    f.read(4)

    # Read offset of first IFD as the four next bytes:
    IFD_offset = int.from_bytes(f.read(4), 'little') 

    # Move to IFD:
    f.seek(IFD_offset, 0)

    # Read IFD:
    IFD = f.read(12)

    # Get components of IFD:
    tag = int.from_bytes(IFD[:2], 'little')
    field_type = int.from_bytes(IFD[2:4], 'little')
    count = int.from_bytes(IFD[4:8], 'little')
    value_offset = int.from_bytes(IFD[8:], 'little')

    # Now what?

The values for the components are tag=16, field_type=254, count=65540 and value_offset=0.

How do I go from there?

Ps: Using Python is not a must, if there is some other tool that could more easily to the job.

0

There are 0 answers