# Image quantization techniques?

**URL:** <https://discourse.slicer.org/t/image-quantization-techniques/13420>\
**Category:** Support\
**Created:** [September 10, 2020, 12:46pm UTC](https://discourse.slicer.org/t/image-quantization-techniques/13420 "2020-09-10T12:46:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [September 10, 2020, 12:46pm UTC](https://discourse.slicer.org/t/image-quantization-techniques/13420/1 "2020-09-10T12:46:24Z")

</div>

We recently had a new detector installed in our micro-CT machine that has resulted in significantly higher dataset sizes (from 0.5-1.0GB to 10GB). While this is really nice from a resolution and dynamic range point of view, working with big datasets has its challenges.

Some studies need the full dynamic range (16 bit) and just need to use a beefy computer to work with the data, or crop off areas to minimize dimensions, etc. But there are a number of studies where you only care about simple thresholds - bone vs matrix, air vs tissue, etc. For these datasets, 8 bit data would be a big space saver and would likely not impact results.

I’ve been looking at using some of the unu utilities (quantize, histo, etc) with the idea of establishing the range of absorbance values to best preserve dynamic range when converting to 8 bit to reduce dataset size. It seems fairly clear that this (quantization and binning techniques) is probably a well-traveled road. Can anyone provide pointers on how they’ve done similar tasks and added them to their workflow?

Thanks in advance!!!

-Hollister

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 10, 2020, 1:02pm UTC](https://discourse.slicer.org/t/image-quantization-techniques/13420/2 "2020-09-10T13:02:41Z")

</div>

“Simple filters” module offers a number of filters intensity rescaling, which can be used for compressing dynamic range of the image. Try RescaleIntensityFilter, IntensityWindowingFilter, ShiftScaleImageFilter, etc.

You can get the currently displayed window/level (or min/max) value from Volumes module, Display section.

Going from 16 bits to 8 bits is just 2x memory reduction, though, so it might not worth the trouble. If you increase spacing along each axis by 3x then you get 27x reduction.

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [September 10, 2020, 1:27pm UTC](https://discourse.slicer.org/t/image-quantization-techniques/13420/3 "2020-09-10T13:27:48Z")

</div>

Ah, ok - simple filters is a great idea, thanks! 2x reduction might not seem like a lot, but it’s enough to make the data useable.

Dumb question - can you convert 16 bit data to 8 bit data within Slicer? I’ve always used Fiji for this…

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 10, 2020, 1:30pm UTC](https://discourse.slicer.org/t/image-quantization-techniques/13420/4 "2020-09-10T13:30:57Z")

</div>

> [@hherhold](#):
>
> can you convert 16 bit data to 8 bit data within Slicer?

You can use “Cast scalar volume” module (or CastImageFilter in Simple Filters module) to change scalar type of a volume (16-bit short to 8-bit char).

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [September 10, 2020, 1:32pm UTC](https://discourse.slicer.org/t/image-quantization-techniques/13420/5 "2020-09-10T13:32:29Z")

</div>

Awesome! Thanks (again), Andras!

---

<div class="post-metadata">

**Author:** ![tsehrhardt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tsehrhardt/32/18470_2.png) [@tsehrhardt](https://discourse.slicer.org/u/tsehrhardt)\
**Post date:** [September 13, 2020, 11:33am UTC](https://discourse.slicer.org/t/image-quantization-techniques/13420/6 "2020-09-13T11:33:30Z")

</div>

Here is a sequence of steps to correctly convert 16bit to 8bit: [https://github.com/SlicerMorph/W\_2020/tree/master/Lab11\_SlicerPlusPlus#rescalecast](https://github.com/SlicerMorph/W_2020/tree/master/Lab11_SlicerPlusPlus#rescalecast)

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [September 13, 2020, 12:38pm UTC](https://discourse.slicer.org/t/image-quantization-techniques/13420/7 "2020-09-13T12:38:39Z")

</div>

Oh, that’s perfect! Thanks very much!

-Hollister

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 13, 2020, 1:29pm UTC](https://discourse.slicer.org/t/image-quantization-techniques/13420/8 "2020-09-13T13:29:28Z")

</div>

> [@tsehrhardt](#):
>
> Here is a sequence of steps to correctly convert 16bit to 8bit

This is very nice! I have submitted a [pull request](https://github.com/SlicerMorph/W_2020/pull/7) with a few minor corrections.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 5, 2022, 4:31pm UTC](https://discourse.slicer.org/t/image-quantization-techniques/13420/9 "2022-05-05T16:31:13Z")

</div>

A post was split to a new topic: [Compute volume in image](https://discourse.slicer.org/t/compute-volume-in-image/23288)
