# How to change the Mat-Datatype to Pixelvalues?

**URL:** <https://forum.opencv.org/t/how-to-change-the-mat-datatype-to-pixelvalues/6110>\
**Category:** C++\
**Tags:** videoio, imgproc\
**Created:** [November 8, 2021, 10:07pm UTC](https://forum.opencv.org/t/how-to-change-the-mat-datatype-to-pixelvalues/6110 "2021-11-08T22:07:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbechtum](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@jbechtum](https://forum.opencv.org/u/jbechtum)\
**Post date:** [November 8, 2021, 10:07pm UTC](https://forum.opencv.org/t/how-to-change-the-mat-datatype-to-pixelvalues/6110/1 "2021-11-08T22:07:47Z")

</div>

Hello everybody,

I’ve written a program, wich saves an image to an opencv-Mat (Mat\_Test\_1).

If I debug, i can see, that there’s just one single value stored in “Mat\_Test\_1.data” (for example “W1!” / “87”).

When I use cv::imshow, the Image gets displayed correctly.

But I need to transform this single value in multiple Pixel-Values.

For example, “Mat\_Test\_2. data” should contain “Y1 Y1Y1Y1Y1Y0X0…” and so on.  
A workaround, which works is the following:

```auto
cv::imwrite("test.png", Mat_Test_1);
Mat_Test_2 = cv::imread("test.png", cv::IMREAD_COLOR);

```

But this is too slow to be done with 30fps or sth.
