lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.27k stars 1.3k forks source link

TIF file converted to PNG Pure Black #3929

Open ShareQiu1994 opened 10 months ago

ShareQiu1994 commented 10 months ago

澳门WGS84.zip

Windows prewview image

Convert TIF to PNG preview using Sharp image

my code image

root@eulee:/home/eulee_geo_docker/geo_services_data/uploads/raster# identify -verbose 澳门WGS84.tif Image: 澳门WGS84.tif Format: TIFF (Tagged Image File Format) Mime type: image/tiff Class: DirectClass Geometry: 609x910+0+0 Units: PixelsPerInch Colorspace: Gray Type: Grayscale Endianess: LSB Depth: 16/8-bit Channel depth: gray: 8-bit Channel statistics: Pixels: 554190 Gray: min: 0 (0) max: 65535 (1) mean: 11621 (0.177326) standard deviation: 25021.3 (0.3818) kurtosis: 0.855851 skewness: 1.6898 entropy: 0.113158 Colors: 90 Histogram: 454878: ( 0, 0, 0) #000000000000 gray(0) 254: ( 257, 257, 257) #010101010101 gray(1) 178: ( 514, 514, 514) #020202020202 gray(2) 104: ( 771, 771, 771) #030303030303 gray(3) 78: ( 1028, 1028, 1028) #040404040404 gray(4) 59: ( 1285, 1285, 1285) #050505050505 gray(5) 32: ( 1542, 1542, 1542) #060606060606 gray(6) 36: ( 1799, 1799, 1799) #070707070707 gray(7) 30: ( 2056, 2056, 2056) #080808080808 gray(8) 17: ( 2313, 2313, 2313) #090909090909 gray(9) 13: ( 2570, 2570, 2570) #0A0A0A0A0A0A gray(10) 13: ( 2827, 2827, 2827) #0B0B0B0B0B0B gray(11) 8: ( 3084, 3084, 3084) #0C0C0C0C0C0C gray(12) 7: ( 3341, 3341, 3341) #0D0D0D0D0D0D gray(13) 6: ( 3598, 3598, 3598) #0E0E0E0E0E0E gray(14) 3: ( 3855, 3855, 3855) #0F0F0F0F0F0F gray(15) 3: ( 4112, 4112, 4112) #101010101010 gray(16) 9: ( 4369, 4369, 4369) #111111111111 gray(17) 7: ( 4626, 4626, 4626) #121212121212 gray(18) 4: ( 4883, 4883, 4883) #131313131313 gray(19) 1: ( 5140, 5140, 5140) #141414141414 gray(20) 9: ( 5397, 5397, 5397) #151515151515 gray(21) 7: ( 5654, 5654, 5654) #161616161616 gray(22) 7: ( 5911, 5911, 5911) #171717171717 gray(23) 5: ( 6168, 6168, 6168) #181818181818 gray(24) 3: ( 6425, 6425, 6425) #191919191919 gray(25) 3: ( 6682, 6682, 6682) #1A1A1A1A1A1A gray(26) 8: ( 6939, 6939, 6939) #1B1B1B1B1B1B gray(27) 5: ( 7196, 7196, 7196) #1C1C1C1C1C1C gray(28) 5: ( 7453, 7453, 7453) #1D1D1D1D1D1D gray(29) 8: ( 7710, 7710, 7710) #1E1E1E1E1E1E gray(30) 5: ( 7967, 7967, 7967) #1F1F1F1F1F1F gray(31) 2: ( 8224, 8224, 8224) #202020202020 gray(32) 9: ( 8481, 8481, 8481) #212121212121 gray(33) 1: ( 8738, 8738, 8738) #222222222222 gray(34) 6: ( 8995, 8995, 8995) #232323232323 gray(35) 2: ( 9252, 9252, 9252) #242424242424 gray(36) 8: ( 9509, 9509, 9509) #252525252525 gray(37) 6: ( 9766, 9766, 9766) #262626262626 gray(38) 6: (10023,10023,10023) #272727272727 gray(39) 7: (10280,10280,10280) #282828282828 gray(40) 9: (10537,10537,10537) #292929292929 gray(41) 1: (10794,10794,10794) #2A2A2A2A2A2A gray(42) 2: (11051,11051,11051) #2B2B2B2B2B2B gray(43) 3: (11308,11308,11308) #2C2C2C2C2C2C gray(44) 1: (11565,11565,11565) #2D2D2D2D2D2D gray(45) 1: (11822,11822,11822) #2E2E2E2E2E2E gray(46) 1: (12079,12079,12079) #2F2F2F2F2F2F gray(47) 3: (12336,12336,12336) #303030303030 gray(48) 2: (12593,12593,12593) #313131313131 gray(49) 1: (12850,12850,12850) #323232323232 gray(50) 3: (13107,13107,13107) #333333333333 gray(51) 2: (13364,13364,13364) #343434343434 gray(52) 2: (13621,13621,13621) #353535353535 gray(53) 4: (13878,13878,13878) #363636363636 gray(54) 3: (14135,14135,14135) #373737373737 gray(55) 3: (14392,14392,14392) #383838383838 gray(56) 1: (14906,14906,14906) #3A3A3A3A3A3A gray(58) 3: (15163,15163,15163) #3B3B3B3B3B3B gray(59) 2: (15420,15420,15420) #3C3C3C3C3C3C gray(60) 4: (15677,15677,15677) #3D3D3D3D3D3D gray(61) 1: (15934,15934,15934) #3E3E3E3E3E3E gray(62) 3: (16191,16191,16191) #3F3F3F3F3F3F gray(63) 4: (16448,16448,16448) #404040404040 gray(64) 1: (16705,16705,16705) #414141414141 gray(65) 6: (16962,16962,16962) #424242424242 gray(66) 3: (17219,17219,17219) #434343434343 gray(67) 3: (17476,17476,17476) #444444444444 gray(68) 1: (17733,17733,17733) #454545454545 gray(69) 5: (17990,17990,17990) #464646464646 gray(70) 1: (18247,18247,18247) #474747474747 gray(71) 6: (18504,18504,18504) #484848484848 gray(72) 2: (18761,18761,18761) #494949494949 gray(73) 3: (19018,19018,19018) #4A4A4A4A4A4A gray(74) 1: (19275,19275,19275) #4B4B4B4B4B4B gray(75) 2: (19789,19789,19789) #4D4D4D4D4D4D gray(77) 1: (20046,20046,20046) #4E4E4E4E4E4E gray(78) 1: (62451,62451,62451) #F3F3F3F3F3F3 gray(243) 3: (62708,62708,62708) #F4F4F4F4F4F4 gray(244) 4: (62965,62965,62965) #F5F5F5F5F5F5 gray(245) 9: (63222,63222,63222) #F6F6F6F6F6F6 gray(246) 28: (63479,63479,63479) #F7F7F7F7F7F7 gray(247) 28: (63736,63736,63736) #F8F8F8F8F8F8 gray(248) 66: (63993,63993,63993) #F9F9F9F9F9F9 gray(249) 105: (64250,64250,64250) #FAFAFAFAFAFA gray(250) 130: (64507,64507,64507) #FBFBFBFBFBFB gray(251) 568: (64764,64764,64764) #FCFCFCFCFCFC gray(252) 481: (65021,65021,65021) #FDFDFDFDFDFD gray(253) 462: (65278,65278,65278) #FEFEFEFEFEFE gray(254) 96359: (65535,65535,65535) #FFFFFFFFFFFF gray(255) Rendering intent: Undefined Gamma: 0.454545 Background color: gray(255) Border color: gray(223) Matte color: gray(189) Transparent color: gray(0) Interlace: None Intensity: Undefined Compose: Over Page geometry: 609x910+0+0 Dispose: Undefined Iterations: 0 Compression: LZW Orientation: TopLeft Properties: date:create: 2024-01-04T10:08:51+00:00 date:modify: 2024-01-03T08:47:35+00:00 signature: f37786d5a8106cd02e436a3eb3a8888311c1f47bb265aa586de45cd3e484a4cf tiff:alpha: unspecified tiff:endian: lsb tiff:photometric: min-is-black Artifacts: filename: 澳门WGS84.tif verbose: true Tainted: False Filesize: 140087B Number pixels: 554190 Pixels per second: 55.419MB User time: 0.010u Elapsed time: 0:01.010 Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org identify-im6.q16: Unknown field with tag 33550 (0x830e) encountered. TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/949. identify-im6.q16: Unknown field with tag 33922 (0x8482) encountered.TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/949. identify-im6.q16: Unknown field with tag 34735 (0x87af) encountered. TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/949. identify-im6.q16: Unknown field with tag 34736 (0x87b0) encountered.TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/949. identify-im6.q16: Unknown field with tag 34737 (0x87b1) encountered. TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/949. identify-im6.q16: Unknown field with tag 42112 (0xa480) encountered.TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/949. identify-im6.q16: Unknown field with tag 42113 (0xa481) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/949.

lovell commented 10 months ago

I think this image might be slightly corrupt (there are quite a few unknown TIFF tags) and/or have invalid/unexpected data.

This is likely to relate to bit depth - the image claims to be 16-bit but contains what appears to be 8-bit values.

Depth: 16/8-bit Channel depth: gray: 8-bit

Using vips at the command line, the maximum pixel value is only 161. I would expect this to be 65535.

$ vips max 澳门WGS84.tif
(vips:21878): VIPS-WARNING **: 12:40:10.974: Unknown field with tag 33550 (0x830e) encountered
(vips:21878): VIPS-WARNING **: 12:40:10.974: Unknown field with tag 33922 (0x8482) encountered
(vips:21878): VIPS-WARNING **: 12:40:10.974: Unknown field with tag 34735 (0x87af) encountered
...
161.000000

Do you know the source of this image e.g. which software was used to create it?

ShareQiu1994 commented 10 months ago

@lovell Thanks! I can use your method to convert TIF to digits and browse PNG thumbnails normally

I use the Python OpenCV library to implement it

The code is as follows

import cv2 image_16bit = cv2.imread('am.tif', cv2.IMREAD_UNCHANGED) image_8bit = cv2.normalize(image_16bit, None, 0, 255, cv2.NORM_MINMAX, dtype=cv2.CV_8U) cv2.imwrite('am2.tif', image_8bit)

am2.zip

But I cannot effectively convert TIF files to 8-bit using Sharp Can Sharp find a way to solve the conversion problem?

ShareQiu1994 commented 10 months ago

2f900ecc173174e91fe8fcb4f172a38

ShareQiu1994 commented 10 months ago

reply “Do you know the source of this image e.g. which software was used to create it?“

This TIF image is DEM digital elevation data captured by Advanced Land Observing Satellite 1 https://search.asf.alaska.edu/#/

lovell commented 8 months ago

@ShareQiu1994 Were you able to make any progress with this?

koniuszy commented 8 months ago

I did my best with sharp but to no avail…

magick file.tif -auto-level -negate -transparent white file.png did the work instead :D