# Corruption in image loading

**URL:** <https://forums.openmv.io/t/corruption-in-image-loading/11422>\
**Category:** OpenMV Boards\
**Created:** [November 19, 2025, 1:32pm UTC](https://forums.openmv.io/t/corruption-in-image-loading/11422 "2025-11-19T13:32:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![James2](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@James2](https://forums.openmv.io/u/James2)\
**Post date:** [November 19, 2025, 1:32pm UTC](https://forums.openmv.io/t/corruption-in-image-loading/11422/1 "2025-11-19T13:32:52Z")

</div>

Hi,  
I’m facing a very strange behavior after loading an image through OpenMV. For some unknown reason, the image loads correctly in the IDE interface, but the values in the framebuffer appear to be corrupted (colons of pixels are shifted) in memory. I can confirm this issue by simply saving the exact same file after the initial load.

Using a very basic script, I can reliably reproduce the bug.  
Does anyone know how to fix this issue?

Below is the minimal code example I used to reproduce the behavior:

```auto
   # CODE
mask = sensor.alloc_extra_fb(64, 64, sensor.GRAYSCALE)
mask.replace(image.Image(“bag_mask.png”, copy_to_fb=True))
print(mask.width() , mask.height(),“GRAYSCALE =”,mask.format()==image.GRAYSCALE)
mask.save(“bag_mask_openMV.png”)

```

Initial loaded picture

![bag_mask](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/0/06fcb2a6a500330e9cb871a26d9faafee6ba38df.png)

---

<div class="post-metadata">

**Author:** ![James2](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@James2](https://forums.openmv.io/u/James2)\
**Post date:** [November 19, 2025, 1:35pm UTC](https://forums.openmv.io/t/corruption-in-image-loading/11422/2 "2025-11-19T13:35:24Z")

</div>

Resulted saved picture :

![bag_mask_openMV](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/5/5440ad8c6ff7a697eeb78d401e6b8880ccc7854d.png)

---

<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:** [November 19, 2025, 8:02pm UTC](https://forums.openmv.io/t/corruption-in-image-loading/11422/3 "2025-11-19T20:02:39Z")

</div>

Hi, that’s a bug in the png file save code. Can you use bmp or jpg format instead? The png code is lightly tested. Also, please make a bug on github for us to fix after the next release.

---

<div class="post-metadata">

**Author:** ![James2](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@James2](https://forums.openmv.io/u/James2)\
**Post date:** [November 20, 2025, 1:54pm UTC](https://forums.openmv.io/t/corruption-in-image-loading/11422/4 "2025-11-20T13:54:11Z")

</div>

Thanks for the quick support. It works with both **PGM** and **BMP** files, but it fails with **JPG** for another reason. The issue is mainly from the loading of the file and not the saving, as I can also see the bit-shifted pattern when using this mask for basic operations (b\_and(), b\_or(), clear(), mean(), etc.).

I will open a bug report on GitHub and close this topic.  
Thank you.

---

<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:** [November 20, 2025, 7:22pm UTC](https://forums.openmv.io/t/corruption-in-image-loading/11422/5 "2025-11-20T19:22:32Z")

</div>

Hi, what’s the reason it fails for jpg? JPG should be well debugged and solid.

---

<div class="post-metadata">

**Author:** ![James2](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@James2](https://forums.openmv.io/u/James2)\
**Post date:** [November 24, 2025, 9:31am UTC](https://forums.openmv.io/t/corruption-in-image-loading/11422/6 "2025-11-24T09:31:48Z")

</div>

With JPEG, I initially thought the issue was due to the format not being fully supported, so I didn’t spend additional time investigating as switching to PGM solved the problem.  
The error I was getting was: **OSError: Non-Baseline JPEGs are not supported.**

---

<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:** [November 24, 2025, 12:59pm UTC](https://forums.openmv.io/t/corruption-in-image-loading/11422/7 "2025-11-24T12:59:15Z")

</div>

Hi, that’s an issue with the jpeg itself. You can probably fix that by creating it using a different program.

---

<div class="post-metadata">

**Author:** ![James2](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@James2](https://forums.openmv.io/u/James2)\
**Post date:** [November 24, 2025, 4:16pm UTC](https://forums.openmv.io/t/corruption-in-image-loading/11422/8 "2025-11-24T16:16:34Z")

</div>

thanks
