-1

I have TIF files that I would like to compress without losing any data, do you know the best tool for that? The data is very important. The data file looks like this: I have thousands of them. (It's X-ray data and it's black and white. ) enter image description here

8
  • 1
    You have thousands of black images? What is the native format of the files? What are their file sizes? What operating system and software do you have available to recompress the files? – xiota Mar 15 '20 at 21:30
  • @xiota Actually, this is black and white if you change the level of brightness you'd see some white parts. The file type is a TIF and can be read by specific tools. – Arash Mar 15 '20 at 21:35
  • If the file is already tif, what's the problem? – xiota Mar 15 '20 at 23:16
  • 1
    @xiota, I'm a software developer. I once worked on a software product that displayed MRI images. I didn't come into direct contact with the code that imported DICOM files, but I do remember the concept of window (a.k.a., window width) and "level" (a.k.a., window center). Those are knobs that the radiologist turns while trying to find important details in the picture. They change the mapping from the full bit-depth of the recorded image to the 8-bits per pixel of the display screen. – Solomon Slow Mar 16 '20 at 20:55
  • 1
    Are they grayscale (more than two levels per image, no color) or binary (just two levels per image) ? People often say "black and white" when they should say "grayscale". – StephenG Mar 17 '20 at 0:10
1

Your example image in png format seems to only have two states. The png is already losslessly compressed, albeit in full color mode, at 16.5 Kbytes.

Thresholding the image to pure Black and White and using GIF indexed color mode produces a 10.3 Kbyte file, roughly 2/3 size.

GIF indexed threshold

---------Edit to try to answer OP's additional questions

Loading the linked original image into GIMP, the image appears to be completely BLACK.

Gimp_1

Note that it is 8-bit Integer Indexed Color.

Now opening up the Histogram function in Gimp.

Histogram

and exporting a CSV file of the Histogram, we see:

Range start,Value

0,1002001.0
1,40674.0
2,0.0
3,0.0
4,0.0
5,0.0
...
255,0.0

So the image has a million zeros, 40 thousand one's, and nothing else.

Last but not least is the EXIF data from Gimp / Image / Metadata / View Metadata

Metadata

You can see the LZW compression here.

I actually extracted the LZW information using a different tool that examined the file format, but this is easier if EXIF is available.

8
  • The original file is uploaded here: mediafire.com/view/dkec9o4d6j0j367/S0_000.tif/file Please take a look – Arash Mar 17 '20 at 4:50
  • 1
    @Arash - I looked at the original you linked above. Interestingly it is already 8-bit indexed mode and lossly compressed to 12 KB. Initially the image appears all black but it actually has a single bit threshold. Applying a threshold for Black and White against the original produces exactly the same image I posted above, and it saves as the same 10.3 KB GIF. Incidentally I used GIMP to process the image. – user10216038 Mar 17 '20 at 16:55
  • 1
    @Arash - Sorry, I typo'd. That should have said losslessly. Not lossy! – user10216038 Mar 17 '20 at 22:44
  • 1
    Compressed means a smaller file size, but yes generally, and specifically in this case, the file structure states that it is compressed using LZW. – user10216038 Mar 18 '20 at 3:46
  • 1
    @Arash - I updated my answer with pictures for you. – user10216038 Mar 18 '20 at 22:13
3

Programs normally offer LZW compression for TIFF image files, which is 100% lossless. You should first make sure that your program that opens and views them can handle opening LZW compression (try one first), but LZW is very common for images.

Document files (text page archives, and fax) typically use TIFF with one of the CCITT compressions, also lossless, but which is not normally found in image programs, so that is not a good choice for your images.

4
  • Is TIF the same with TIFF? and how can I see/calculate the compression ratio? – Arash Mar 16 '20 at 1:27
  • 1
    Yes, same meaning, more or less. The technical specification describing the file format is named TIFF, but the computer file name extension is .TIF ... Compression is variable depending on how compressible the content. The uncompressed data size is 3 bytes per pixel for 24-bit RGB color images, 1 byte per pixel for grayscale, and one bit per pixel for line art files. Plus a small overhead for data tags and for any Exif added. Then it is smaller when written to a compressed file (LZW is perhaps 25% to 50% less). The ratio is the ratio of those two sizes, compressed and uncompressed file sizes. – WayneF Mar 16 '20 at 3:27
  • 1
    BTW, your PNG image is also always losslessly compressed (wtihout any losses), and a bit smaller than TIFF LZW (but large PNG files are slightly slower to open than TIF LZW), if your reading program is OK opening PNG. But JPG is relatively heavily compressed, and lossy, with losses.. – WayneF Mar 16 '20 at 3:40
  • 1
    Your PNG image is RGB color mode (3 bytes per pixel before compression), which seems a waste storage-wise, at least less appropriate. Color mode can also develop false color tints. It seems to have only two colors, black and one light gray tone. IMO, grayscale (1 byte per pixel) would make more sense for this one shown and would be 1/3 the file size. – WayneF Mar 16 '20 at 3:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.