Search code examples
pythonjpeg2000

python jpeg2000 compression with glymur


anyone familiar with glymur module?

I would like to use this module to generate different jp2k type distortion images, but i really cant figure out how to apply this module, i found the code official page of glymur,

https://glymur.readthedocs.org/en/release-0.7.3/how_do_i.html#read-images

but it seems raised errors.

Can anyone show me a part of code which read a jp2 file from say, "D:/1.jp2", and saves this to "D:/2.jp2"?


Solution

  • Using the latest releases:

    >>> glymur.version.version
    '0.8.0'
    >>> glymur.version.openjpeg_version
    '2.1.0'
    

    (the latter installed with macports on my Macbook Air, OSX 10.9.5) I copied the nemo image to the input filename you desire (not on D: of course as I don't have that on my Mac:-)...:

    $ cp /Library/Python/2.7/site-packages/glymur/data/nemo.jp2 ./1.jp2
    

    then reading and writing is really simple:

    >>> jp2 = glymur.Jp2k('1.jp2')
    >>> oth = glymur.Jp2k('2.jp2', jp2[:])
    

    and did verify (by eyeball with Preview) that the images look the same.

    I suspect your problem may come from some wrong step on your installation (I had no problem with sudo port install openjpeg and then sudo pip install glymur, but I don't know what the equivalent steps are for Windows) -- or maybe 0.7.3 or whatever openjpeg release you're using have problems on Windows, I would't know about that. Maybe try installing the latest and greatest releases...?