# 1D array to 16bits greyscale mat

**URL:** <https://forum.opencv.org/t/1d-array-to-16bits-greyscale-mat/3888>\
**Category:** C++\
**Tags:** mat, core\
**Created:** [June 17, 2021, 12:17am UTC](https://forum.opencv.org/t/1d-array-to-16bits-greyscale-mat/3888 "2021-06-17T00:17:09Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [June 17, 2021, 6:53am UTC](https://forum.opencv.org/t/1d-array-to-16bits-greyscale-mat/3888/3 "2021-06-17T06:53:29Z")

</div>

> [@superdu](#):
>
> `Mat m(Img.size[1], Img.size[0], CV_16U, Img.data);`

type problem here, your `img` struct has an `int` data pointer  
(4 bytes per pixel, not 2, that’s why every second CV\_16U pixel is 00)

it should be either:

```
Mat m(Img.size[1], Img.size[0], CV_32S, Img.data);

```

(and the range be adjusted)

or `ushort *data` in the Img struct

---

_[View the full topic](https://forum.opencv.org/t/1d-array-to-16bits-greyscale-mat/3888)._
