Message Boards Message Boards

0
|
3838 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

JPEG2000 lossless compression

Posted 3 years ago

I'm trying to use the lossless compression capability of the JPEG2000 format in Mathematica 12.2. I've consulted the online documentation for the syntax to specify the lossless setting. However, there is no change in export file size when I use the “Lossless” setting vs. the “JPEG2000” (lossy) setting, which makes me wonder what’s going on. Also, the “ImageEncoding” text in my code remains blue after executing it, which makes me suspect that it is being ignored. Here is a snip from my code of the relevant command:

Table[Export[exportString[[i]], imageStack2[[i]],
    ImageEncoding -> "JPEG2000"], {i, 1,
    Dimensions[imageStack2][[1]]}]];

I'd be grateful for any insight anyone could provide as to what I might be doing wrong.

POSTED BY: Rick Rogers
2 Replies

This is how you should use it:

In[1]:= img = RandomImage[1, {200, 300}, "Byte", ColorSpace -> "RGB"];

In[2]:= FileSize[Export["out.jp2", img, "ImageEncoding" -> "JPEG2000", CompressionLevel -> #]] & /@ {0.2, 0.5, 0.8}

Out[2]= {Quantity[144.878, "Kilobytes"], Quantity[91.122, "Kilobytes"], Quantity[36.79, "Kilobytes"]}

Notice that CompressionLevel option is ignored when "ImageEncoding" -> "Lossless":

In[3]:= FileSize[Export["out.jp2", img, "ImageEncoding" -> "Lossless", CompressionLevel -> #]] & /@ {0.2, 0.5, 0.8}

Out[3]= {Quantity[200.226, "Kilobytes"],  Quantity[200.226, "Kilobytes"], Quantity[200.226, "Kilobytes"]}
POSTED BY: Piotr Wendykier
Posted 3 years ago

Piotr, thanks for that quick and helpful reply! Rick

POSTED BY: Rick Rogers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract