# Image dtype is printed differently across machines

**URL:** <https://forum.opencv.org/t/image-dtype-is-printed-differently-across-machines/7867>\
**Category:** Python\
**Created:** [March 9, 2022, 11:48am UTC](https://forum.opencv.org/t/image-dtype-is-printed-differently-across-machines/7867 "2022-03-09T11:48:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Heinz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/heinz/32/3966_2.png) [@Heinz](https://forum.opencv.org/u/Heinz)\
**Post date:** [March 9, 2022, 11:48am UTC](https://forum.opencv.org/t/image-dtype-is-printed-differently-across-machines/7867/1 "2022-03-09T11:48:11Z")

</div>

I have a code that prints float32 for an image that I am processing on my local machine. However, the code does not work when we port it to another machine and it somehow prints the same image as float64. Why is that so? Is it because of the machine architecture, or OpenCV versions, or the numpy version?

Local machine:

`print(image.dtype) : float32`

Remote machine:

`print(image.dtype) : float64`

As a result of this, obviously, none of the image processing functions work in the code. What is the best way to overcome this?

EDIT: OpenCV version 4.5.5  
OS: Ubuntu 20.04

Obviously, both machines run the same OS and have the same OpenCV versions.

Code:

```auto
normalized = np.ones_like(frame,dtype=np.float32)
edges = filters.sobel(normalized) # here it becomes float64
 edges = img_as_float32(edges) # required in some systems so that system does not throw float64/float32 in the next line
 gray = cv2.cvtColor(edges, cv2.COLOR_BGR2GRAY)

```

Error output:

```auto
...modules/imgproc/src/color.simd_helpers.hpp:94: error: (-2:Unspecified error) in function 'cv::impl::{anonymous}::CvtHelper<VScn, VDcn, VDepth, sizePolicy>::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::impl::{anonymous}::Set<3, 4>; VDcn = cv::impl::{anonymous}::Set<1>; VDepth = cv::impl::{anonymous}::Set<0, 2, 5>; cv::impl::{anonymous}::SizePolicy sizePolicy = cv::impl::<unnamed>::NONE; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'
> Unsupported depth of input image:
> 'VDepth::contains(depth)'
> where
> 'depth' is 6 (CV_64F)

```

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [March 9, 2022, 12:20pm UTC](https://forum.opencv.org/t/image-dtype-is-printed-differently-across-machines/7867/2 "2022-03-09T12:20:28Z")

</div>

please edit your question and add

- opencv version
- os
- code that lead to the result above

---

<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:** [March 9, 2022, 12:48pm UTC](https://forum.opencv.org/t/image-dtype-is-printed-differently-across-machines/7867/3 "2022-03-09T12:48:13Z")

</div>

more info please. what you’ve given so far is far from sufficient to even hypothesize.

you talk of architectures yet there’s no info on that at all. do you want us to think both machines run the same ubuntu and the same opencv version? what architectures are involved? who built OpenCV?

> **[How to create a Minimal, Reproducible Example - Help Center](https://stackoverflow.com/help/minimal-reproducible-example)**
>
> Stack Overflow | The World’s Largest Online Community for Developers

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [March 9, 2022, 2:10pm UTC](https://forum.opencv.org/t/image-dtype-is-printed-differently-across-machines/7867/6 "2022-03-09T14:10:48Z")

</div>

we still dont know, which **code** lead to the problem  
please tell !

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [March 9, 2022, 2:59pm UTC](https://forum.opencv.org/t/image-dtype-is-printed-differently-across-machines/7867/8 "2022-03-09T14:59:34Z")

</div>

`cvtColor` does not support float64 images, no matter if ENABLE\_FAST\_MATH was set in cmake or not

but you’re reporting, that the type of `edges` changed. if this is a bug, it needs to be reported, right ?

try to be helpful, and show, how you generate / process the `edges` , _please_

---

<div class="post-metadata">

**Author:** ![Heinz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/heinz/32/3966_2.png) [@Heinz](https://forum.opencv.org/u/Heinz)\
**Post date:** [March 9, 2022, 6:51pm UTC](https://forum.opencv.org/t/image-dtype-is-printed-differently-across-machines/7867/9 "2022-03-09T18:51:27Z")

</div>

OK, you were right. The reason why the code worked after I recompiled OpenCV was that the same setup file also re-installed **Skimage, which was the actual problem.**

```auto
 normalized = np.ones_like(frame,dtype=np.float32)
 kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))

    for i in range(3):
        normalized[:,:,i] = np.take(cumsum[i,:], frame[:,:,i]) / hist[i,:].sum()
    
    print("normalized:", normalized.dtype)
    edges = filters.sobel(normalized)
    print("edges:", edges.dtype)
    gray = cv2.cvtColor(edges, cv2.COLOR_BGR2GRAY)

```

output:

> normalized: float32  
> edges: float64

So, it appears the function `edges = filters.sobel(normalized)` from `Skimage` caused the problem.

Those who faced this problem, although this is OpenCV forum and not Skimage one, here is how to solve it:

```auto
from skimage.util import img_as_float32
image = img_as_float32(any_opencv_image)

```

I also apologize on my own behalf. I removed the misleading posts, and I updated my original question so that it is a complete question now.
