---
# System prepended metadata

title: Untitled

---

Currently we have an IJS that is an image for which bitDepth>=8

There is a specific kind of images that are called 'Mask' that has bitDepth=1 and for which very few algorithms applies.

We would need to be able to write code like:

```javascript=
import {Mask} from 'image-js';

const mask = new Mask(100, 200);

for (let row=0; row<mask.height; row++) {
  for (let column=0; column<mask.width; column++) {
      // setBit accepts boolean or number
    mask.setBit(row, column, (row+column)%2===0);
  }
}

const image = mask.toGrey();
```

The data could be stored in a Uint8_array and the value either 0 or 1. We could improve this if we want to save some memory and store 8 pixels in one byte later if needed but it could be slower.

0 = black pixel, 1 = white pixel.

Class fields:
- width
- height
- size
- depth: 1
- colorModel: BINARY
- components: 1
- channels: 1
- alpha: false
- maxValue: 1

We could implement the following methods:
- setBit(row, column, value: boolean | number)
- setBitByIndex(index: number, value: boolean|number)
- getBit(row, column) : number
- getBitByIndex(index: number): number
- convertColor(ImageColorModel.GREY)
- fill(value: number | boolean)
- clone()
- invert()

A mask could also be created from a greyscale image:

```javascript=
const mask = threshold(image, {algorithm: '', threshold:})
```

And the current implementation of `threshold` should be changed to return a Mask:

https://github.com/image-js/image-js-typescript/blob/6fab889a67ff551a4b8c215ec3ef55ba89a0e164/src/operations/threshold.ts#L109-L124

write methods should be able to handle a Mask.


Here are some of the specific methods than can be applied on `Mask`:

- erode: https://github.com/image-js/image-js/blob/legacy/src/image/morphology/erode.js
- dilate: https://github.com/image-js/image-js/blob/legacy/src/image/morphology/dilate.js
- open: https://github.com/image-js/image-js/blob/legacy/src/image/morphology/open.js