0

I have waveform images stored in a database that need to be displayed and analysed in python. Apparently, these images are stored as hex strings which are compressed with wctZLib method as shown in this extract of the database.

{
 "start_dt": "2021-02-01 07:28:35",
 "end_dt": "2021-02-01 07:30:49",
 "compress_method": "wctZLib",
 "waveform_data": "0x789CB57D07BC56D595BD22E8772E88D84BECBD6001E9B ...
}

A sample of the db can be found at github on : https://github.com/Ddest/wctZlib/blob/main/wave.json

I tried googling this compression method in order to decompress and display these images but to no avail.

Even after decompressing it and trying to display it with the PIL library...

with open(filepath,'r') as f:
    data=json.load(f)
    bytesData=bytearray.fromhex(data['waveform_data'][2:])
    
    image = Image.open(io.BytesIO(zlib.decompress(bytesData)))
    image.show()
    

...It didn't work :

Traceback (most recent call last):   
File "/home/usx/Desktop/decompress.py", line 24, in <module> main()   
File "/home/usx/Desktop/decompress.py", line 12, in main
    image = Image.open(io.BytesIO(zlib.decompress(bytesData)))   
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 3186, in open
    raise UnidentifiedImageError( PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f5773d6e020>

even trying to handly it as zip file didn't work.

Can someone give me some insight on how to solve this problem?

Dest
  • 11
  • 2
  • 2
    Do you have more details? How should data look like? One complete sample would probably help. 1st step is to convert every 2 characters into 1 byte. – CristiFati Feb 18 '23 at 19:50
  • It may just be using zlib (for which [a stdlib module exists](https://docs.python.org/3/library/zlib.html)). Your example begins with `789C`, which correlates with the `Default Compression` zlib header mentioned here: https://stackoverflow.com/questions/9050260/what-does-a-zlib-header-look-like We would need a full example value of that `waveform_data` to write a proper answer. – dskrypa Feb 18 '23 at 21:12
  • You are right, I added a sample of the db on github : [link]https://github.com/Ddest/wctZlib/blob/main/wave.json . Already tried decompressing it with no luck. The header is 60 0a 5d 0a 59 0a 54 0a AKA unrecognisable. – Dest Feb 19 '23 at 11:40

0 Answers0