# Using \`imread\` to read a image then multiply a number in one line, the value is wrong! BUG?

**URL:** <https://forum.opencv.org/t/using-imread-to-read-a-image-then-multiply-a-number-in-one-line-the-value-is-wrong-bug/16080>\
**Category:** Python\
**Tags:** numpy\
**Created:** [January 7, 2024, 5:30pm UTC](https://forum.opencv.org/t/using-imread-to-read-a-image-then-multiply-a-number-in-one-line-the-value-is-wrong-bug/16080 "2024-01-07T17:30:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![isJHan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/isjhan/32/8144_2.png) [@isJHan](https://forum.opencv.org/u/isJHan)\
**Post date:** [January 7, 2024, 5:30pm UTC](https://forum.opencv.org/t/using-imread-to-read-a-image-then-multiply-a-number-in-one-line-the-value-is-wrong-bug/16080/1 "2024-01-07T17:30:53Z")

</div>

I use cv2.imread to read a depth map like `depth = 200*cv2.imread(path,-1)/65535`. But I found the value is invalid! When I change my code to `depth = 200.0*cv2.imread(path,-1)/65535`, it looks right. Besides, when I read the depth like `depth = cv2.imread(path,-1)/65535 depth *= 200`, it looks right too!

Is that a bug of opencv or numpy?

---

<div class="post-metadata">

**Author:** ![matti.vuori](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@matti.vuori](https://forum.opencv.org/u/matti.vuori)\
**Post date:** [January 7, 2024, 7:21pm UTC](https://forum.opencv.org/t/using-imread-to-read-a-image-then-multiply-a-number-in-one-line-the-value-is-wrong-bug/16080/2 "2024-01-07T19:21:25Z")

</div>

The bug is in your code - with the multiplication by 200 your 16 bit values will overflow

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [January 7, 2024, 8:38pm UTC](https://forum.opencv.org/t/using-imread-to-read-a-image-then-multiply-a-number-in-one-line-the-value-is-wrong-bug/16080/3 "2024-01-07T20:38:23Z")

</div>

> [@isJHan](#):
>
> -1

and that magic number should be written as **`cv.IMREAD_UNCHANGED`**

---

<div class="post-metadata">

**Author:** ![isJHan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/isjhan/32/8144_2.png) [@isJHan](https://forum.opencv.org/u/isJHan)\
**Post date:** [January 8, 2024, 1:32am UTC](https://forum.opencv.org/t/using-imread-to-read-a-image-then-multiply-a-number-in-one-line-the-value-is-wrong-bug/16080/4 "2024-01-08T01:32:40Z")

</div>

OMG!Thank you! I’m too careless!

---

<div class="post-metadata">

**Author:** ![isJHan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/isjhan/32/8144_2.png) [@isJHan](https://forum.opencv.org/u/isJHan)\
**Post date:** [January 8, 2024, 1:36am UTC](https://forum.opencv.org/t/using-imread-to-read-a-image-then-multiply-a-number-in-one-line-the-value-is-wrong-bug/16080/5 "2024-01-08T01:36:42Z")

</div>

Thanks for your reply!  
I searched the document of opencv, -1 equals with cv::IMREAD\_UNCHANGED. You can find it [here](https://docs.opencv.org/4.x/d8/d6a/group __imgcodecs__ flags.html).
