# JPEG2000 lossless compression

**URL:** <https://community.wolfram.com/t/jpeg2000-lossless-compression/18279>\
**Category:** Questions\
**Tags:** image-processing\
**Created:** [June 14, 2021, 3:36pm UTC](https://community.wolfram.com/t/jpeg2000-lossless-compression/18279 "2021-06-14T15:36:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![richardbrogers](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@richardbrogers](https://community.wolfram.com/u/richardbrogers)\
**Post date:** [June 14, 2021, 3:36pm UTC](https://community.wolfram.com/t/jpeg2000-lossless-compression/18279/1 "2021-06-14T15:36:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![piotrw](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/piotrw/32/6225_2.png) [@piotrw](https://community.wolfram.com/u/piotrw)\
**Post date:** [June 14, 2021, 4:20pm UTC](https://community.wolfram.com/t/jpeg2000-lossless-compression/18279/2 "2021-06-14T16:20:58Z")

</div>

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"]}

```

---

<div class="post-metadata">

**Author:** ![richardbrogers](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@richardbrogers](https://community.wolfram.com/u/richardbrogers)\
**Post date:** [June 14, 2021, 9:24pm UTC](https://community.wolfram.com/t/jpeg2000-lossless-compression/18279/3 "2021-06-14T21:24:19Z")

</div>

Piotr, thanks for that quick and helpful reply! Rick
