cgohlke / imagecodecs

Image transformation, compression, and decompression codecs
https://pypi.org/project/imagecodecs
BSD 3-Clause "New" or "Revised" License
111 stars 21 forks source link

Where can I get the usage of this package #27

Closed TruePluto closed 2 years ago

TruePluto commented 2 years ago

I want to read some lossless JPEG images with SOF3 via Python , but I can't find any usage!I'll be appricaite if somebody give me a address or some code as a example。

cgohlke commented 2 years ago

Try:

import imagecodecs

with open('lossless.jpg', 'rb') as fh:
    encoded = fh.read()

image = imagecodecs.jpegsof3_decode(encoded)
# or
image = imagecodecs.ljpeg_decode(encoded)
TruePluto commented 2 years ago

It's work perfectly! Thank you very much.

alirezadizaji commented 2 years ago

Hi, I have tried the same code for a file with .LJPEG extension (DDSM), however its decompression didn't go well. could you guide me for this?

cgohlke commented 2 years ago

Can't reproduce using a few random LJPEG files from DDSM.

Please be more specific. Which file? Which codec? What is the traceback, if any?

The codecs are based on 3rd party libraries jpg_0XC3.cpp and liblj92. They are basically unmaintained.

libjpeg is probably the best maintained library for decoding LJPEG. It is GPL licensed and therefore can't be used by imagecodecs. There's a Python wrapper at pylibjpeg.

alirezadizaji commented 2 years ago

I have used the following code: `from imagecodecs import ljpeg_decode import imageio

with open(img_path, 'rb') as f: data = f.read() img = ljpeg_decode(data) imageio.imwrite(..., img)` the input data comes from this link (RIGHT_MLO), the saved image is as this link

cgohlke commented 2 years ago

All software and libraries I tried return the same image data. If you think they are all wrong, try the original software provided by USF at http://www.eng.usf.edu/cvprg/Mammography/software/heathusf_v1.1.0.html.