# Is there no binary type '01' in the pixel type of SimpleItk?

**URL:** https://discourse.itk.org/t/is-there-no-binary-type-01-in-the-pixel-type-of-simpleitk/6211
**Category:** Algorithms
**Tags:** python, simpleitk
**Created:** [September 15, 2023, 12:50pm UTC](https://discourse.itk.org/t/is-there-no-binary-type-01-in-the-pixel-type-of-simpleitk/6211 "2023-09-15T12:50:01Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![jumbojing](https://discourse.itk.org/user_avatar/discourse.itk.org/jumbojing/32/3468_2.png) [@jumbojing](https://discourse.itk.org/u/jumbojing)
#### Post date: [September 15, 2023, 12:50pm UTC](https://discourse.itk.org/t/is-there-no-binary-type-01-in-the-pixel-type-of-simpleitk/6211/1 "2023-09-15T12:50:01Z")

</div>

## Is there no binary type ‘01’ in the pixel type of SimpleItk?

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [September 15, 2023, 1:00pm UTC](https://discourse.itk.org/t/is-there-no-binary-type-01-in-the-pixel-type-of-simpleitk/6211/2 "2023-09-15T13:00:05Z")

</div>

SimpleITK and ITK commonly use unsigned bytes, uint8 or `sitkUInt8` type to represent binary images. These are commonly referred to as mask images. We have a FAQ entry in SimpleITK which discussed this common convention:

[https://simpleitk.readthedocs.io/en/master/conventions.html#mask-image-types-and-default-values](https://simpleitk.readthedocs.io/en/master/conventions.html#mask-image-types-and-default-values)

---

<div class="post-metadata">

### Author: ![jumbojing](https://discourse.itk.org/user_avatar/discourse.itk.org/jumbojing/32/3468_2.png) [@jumbojing](https://discourse.itk.org/u/jumbojing)
#### Post date: [September 15, 2023, 2:43pm UTC](https://discourse.itk.org/t/is-there-no-binary-type-01-in-the-pixel-type-of-simpleitk/6211/3 "2023-09-15T14:43:13Z")

</div>

Why is there no ‘2-bit int’ type? I think this type is very commonly used…

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [September 15, 2023, 2:54pm UTC](https://discourse.itk.org/t/is-there-no-binary-type-01-in-the-pixel-type-of-simpleitk/6211/4 "2023-09-15T14:54:21Z")

</div>

It is not directly addressable in memory. Reading memory which is not aligned with processor cache lines is inconvenient/slower, and most processor architectures, and therefore most programming languages, do not expose `bit` as a primitive type, like they do for `int`.

---

<div class="post-metadata">

### Author: ![jumbojing](https://discourse.itk.org/user_avatar/discourse.itk.org/jumbojing/32/3468_2.png) [@jumbojing](https://discourse.itk.org/u/jumbojing)
#### Post date: [September 15, 2023, 3:17pm UTC](https://discourse.itk.org/t/is-there-no-binary-type-01-in-the-pixel-type-of-simpleitk/6211/5 "2023-09-15T15:17:11Z")

</div>

Can’t make a _pseudo_ `bit int` type?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [September 15, 2023, 3:25pm UTC](https://discourse.itk.org/t/is-there-no-binary-type-01-in-the-pixel-type-of-simpleitk/6211/6 "2023-09-15T15:25:00Z")

</div>

In C and C++, that is available in structs. Read more about it:

> <https://stackoverflow.com/questions/35857111/c-how-to-use-bitfields/35857223#35857223>

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [September 15, 2023, 3:26pm UTC](https://discourse.itk.org/t/is-there-no-binary-type-01-in-the-pixel-type-of-simpleitk/6211/7 "2023-09-15T15:26:26Z")

</div>

Also, C++ has a specialized [`std::vector<bool>`](https://stackoverflow.com/questions/17794569/why-isnt-vectorbool-a-stl-container).

---

<div class="post-metadata">

### Author: ![jumbojing](https://discourse.itk.org/user_avatar/discourse.itk.org/jumbojing/32/3468_2.png) [@jumbojing](https://discourse.itk.org/u/jumbojing)
#### Post date: [September 15, 2023, 3:32pm UTC](https://discourse.itk.org/t/is-there-no-binary-type-01-in-the-pixel-type-of-simpleitk/6211/8 "2023-09-15T15:32:42Z")

</div>

Howto write a `bit-int` type with python?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [September 15, 2023, 3:43pm UTC](https://discourse.itk.org/t/is-there-no-binary-type-01-in-the-pixel-type-of-simpleitk/6211/9 "2023-09-15T15:43:12Z")

</div>

I don’t think Python has that:

> <https://stackoverflow.com/questions/142812/does-python-have-a-bitfield-type>

---

<div class="post-metadata">

### Author: ![jumbojing](https://discourse.itk.org/user_avatar/discourse.itk.org/jumbojing/32/3468_2.png) [@jumbojing](https://discourse.itk.org/u/jumbojing)
#### Post date: [September 15, 2023, 10:47pm UTC](https://discourse.itk.org/t/is-there-no-binary-type-01-in-the-pixel-type-of-simpleitk/6211/10 "2023-09-15T22:47:51Z")

</div>

Thanks!..it’s a hassle.
