I have a tiff file that is 800kb in size (1pager), but when I read that tiff file with pil and save it again file size is reduced to 190KB. any reason why it happens??
from PIL import Image
path = tiff/file/path
img = Image.open(path)
img.save("test.tiff")
The most likely is that PIL has saved with a different compression scheme from your input file.
There are several tools you can use to check the content and compression of your files.
You could use exiftool
like this:
exiftool a.tif
Sample Output
ExifTool Version Number : 12.00
File Name : a.tif
Directory : .
File Size : 4.0 kB
File Modification Date/Time : 2021:05:17 11:39:02+01:00
File Access Date/Time : 2021:05:17 11:39:05+01:00
File Inode Change Date/Time : 2021:05:17 11:39:02+01:00
File Permissions : rw-r--r--
File Type : TIFF
File Type Extension : tif
MIME Type : image/tiff
Exif Byte Order : Little-endian (Intel, II)
Image Width : 640
Image Height : 480
Bits Per Sample : 8 8 8
Compression : LZW <--- CHECK COMPRESSION
Photometric Interpretation : RGB
Fill Order : Normal
Strip Offsets : 8
Orientation : Horizontal (normal)
Samples Per Pixel : 3
Rows Per Strip : 480
Strip Byte Counts : 3837
Planar Configuration : Chunky
Page Number : 0 1
Predictor : Horizontal differencing
White Point : 0.3127000032 0.328999996
Primary Chromaticities : 0.6399999856 0.330000013 0.3000000118 0.6000000237 0.1500000058 0.05999999844
Image Size : 640x480
Megapixels : 0.307
You could use tiffinfo
which is shipped with libtiff
like this:
tiffinfo a.tif
Sample Output
TIFF Directory at offset 0xf06 (3846)
Image Width: 640 Image Length: 480
Bits/Sample: 8
Compression Scheme: LZW
Photometric Interpretation: RGB color
FillOrder: msb-to-lsb
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Rows/Strip: 480
Planar Configuration: single image plane
Page Number: 0-1
White Point: 0.3127-0.329
PrimaryChromaticities: 0.640000,0.330000,0.300000,0.600000,0.150000,0.060000
Predictor: horizontal differencing 2 (0x2)
You could use ImageMagick like this:
magick identify -verbose a.tif
Sample Output
Image:
Filename: a.tif
Format: TIFF (Tagged Image File Format)
Mime type: image/tiff
Class: DirectClass
Geometry: 640x480+0+0
Units: PixelsPerInch
Colorspace: sRGB
Type: Palette
Base type: TrueColor
Endianness: LSB
Depth: 8-bit
Channel depth:
Red: 8-bit
Green: 1-bit
Blue: 1-bit
Channel statistics:
Pixels: 307200
Red:
min: 0 (0)
max: 255 (1)
mean: 169.934 (0.666406)
median: 127 (0.498039)
standard deviation: 85.0846 (0.333665)
kurtosis: -1.19989
skewness: -0.500312
entropy: 0.77808
Green:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
median: 0 (0)
standard deviation: 0 (0)
kurtosis: -3
skewness: 0
entropy: 0
Blue:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
median: 0 (0)
standard deviation: 0 (0)
kurtosis: -3
skewness: 0
entropy: 0
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 56.6445 (0.222135)
median: 42.3333 (0.166013)
standard deviation: 28.3615 (0.111222)
kurtosis: -0.0183471
skewness: 1.30265
entropy: 0.25936
Colors: 256
...
...
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Matte color: grey74
Background color: white
Border color: srgb(223,223,223)
Transparent color: none
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 640x480+0+0
Dispose: Undefined
Iterations: 0
Compression: LZW
Orientation: TopLeft
Convex hull: 0,0 639,0 639,478 638,479 1,479 0,478 0,0
Minimum bounding box: 639,0 639,479 0,479 0,0
Properties:
date:create: 2021-05-17T10:39:02+00:00
date:modify: 2021-05-17T10:39:02+00:00
minimum-bounding-box:_p: 0,0
minimum-bounding-box:_q: 639,0
minimum-bounding-box:_v: 638,479
minimum-bounding-box:angle: 0
minimum-bounding-box:area: 306081
minimum-bounding-box:height: 639
minimum-bounding-box:unrotate: -0
minimum-bounding-box:width: 479
signature: 3987e368758bcc020b1c3bc26cc30a0aaf67aaeb38f31ac109b459fd8d25e708
tiff:alpha: unspecified
tiff:endian: lsb
tiff:photometric: RGB
tiff:rows-per-strip: 480
Artifacts:
verbose: true
Tainted: False
Filesize: 4114B
Number pixels: 307200
Pixels per second: 48.0479MP
User time: 0.010u
Elapsed time: 0:01.006
Version: ImageMagick 7.0.10-48 Q16 x86_64 2020-12-10 https://imagemagick.org
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.