# image.binary() outputs image in GRAYSCALE instead of BINARY

**URL:** <https://forums.openmv.io/t/image-binary-outputs-image-in-grayscale-instead-of-binary/1860>\
**Category:** OpenMV Boards\
**Created:** [August 4, 2020, 12:59am UTC](https://forums.openmv.io/t/image-binary-outputs-image-in-grayscale-instead-of-binary/1860 "2020-08-04T00:59:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mos.pp](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@mos.pp](https://forums.openmv.io/u/mos.pp)\
**Post date:** [August 4, 2020, 12:59am UTC](https://forums.openmv.io/t/image-binary-outputs-image-in-grayscale-instead-of-binary/1860/1 "2020-08-04T00:59:08Z")

</div>

Hi,  
  
  
I am trying to save image in sensor.BINARY format but image.binary saves in sensor.GRAYSCALE format.

I have used example,

> color\_binaqry\_filter\_1.py
> 
> ```python
> 
> ```

# Color Binary Filter Example

# 

# This script shows off the binary image filter. You may pass binary any

# number of thresholds to segment the image by.

import sensor, image, time

sensor.reset()  
sensor.set\_framesize(sensor.QVGA)  
sensor.set\_pixformat(sensor.GRAYSCALE) # USING GLOBAL SHUTTER CAMERA → changed from sensor.RGB565  
sensor.skip\_frames(time = 2000)  
clock = time.clock()  
while(True):

```
# Test red threshold
for i in range(100):
    clock.tick()
    img = sensor.snapshot()
    img.binary([red_threshold])
    print(img)
    
    ...

```

```auto
>
> OUTPUT: {"w":320, "h":240, "type"="grayscale", "size":76800}

Because of this problem, I cannot save image.binary() into extra frame buffer pre-defined as "sensor.BINARY".

I was expecting it would automatically convert image to binary format after image.binary().

Without looping through image and assigning pixel-by-pixel into frame buffer, is there a simple method doing this?

I tried to look for examples but there is no conversion examples for binary image.

I look forward to your reply,
\
\
Kind Regards
Phil
```

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [August 4, 2020, 1:50am UTC](https://forums.openmv.io/t/image-binary-outputs-image-in-grayscale-instead-of-binary/1860/2 "2020-08-04T01:50:29Z")

</div>

Try

```python
img.binary([red_threshold], to_bitmap=True)

```

[https://docs.openmv.io/library/omv.image.html#image.image.binary](https://docs.openmv.io/library/omv.image.html#image.image.binary)

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 4, 2020, 3:23am UTC](https://forums.openmv.io/t/image-binary-outputs-image-in-grayscale-instead-of-binary/1860/3 "2020-08-04T03:23:51Z")

</div>

Binary just thresholds an image. Use to\_bitmap() to get a binary image.

Yes, the terminology is confusing because this all wasn’t designed at the same time and we can’t rename things.

---

<div class="post-metadata">

**Author:** ![mos.pp](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@mos.pp](https://forums.openmv.io/u/mos.pp)\
**Post date:** [August 4, 2020, 4:53am UTC](https://forums.openmv.io/t/image-binary-outputs-image-in-grayscale-instead-of-binary/1860/4 "2020-08-04T04:53:10Z")

</div>

Thank you all for the reply.

“to\_bitmap()” works like a magic!

Sorry I have missed out reading about “to\_bitmap” flag.
