# Setting the brightness of the image point

**URL:** <https://forum.opencv.org/t/setting-the-brightness-of-the-image-point/8025>\
**Category:** C++\
**Tags:** core\
**Created:** [March 20, 2022, 12:54pm UTC](https://forum.opencv.org/t/setting-the-brightness-of-the-image-point/8025 "2022-03-20T12:54:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tumanovalex](https://avatars.discourse-cdn.com/v4/letter/t/ba9def/32.png) [@tumanovalex](https://forum.opencv.org/u/tumanovalex)\
**Post date:** [March 20, 2022, 12:54pm UTC](https://forum.opencv.org/t/setting-the-brightness-of-the-image-point/8025/1 "2022-03-20T12:54:54Z")

</div>

In the program, I read the brightness of the image obtained using imread("img.jpg ", IMREAD\_GRAYSCALE), so:

```auto

int beg = (int)img.at<uchar>(x, y);

```

The brightness is read normally. Now I would like to set the brightness of the point, for example to zero (make the point black):  
`img.at<uchar>(x, y) = (uchar) 0;`  
I get an error:

```auto

OpenCV(4.5.5) Error: Assertion failed ((unsigned)(i 1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())) in cv::Mat::at, file C:\opencv\build\include\opencv2\core\mat.inl.hpp, line 899
OpenCV(4.5.5) C:\opencv\build\include\opencv2\core\mat.inl.hpp:899: error: (-215:Assertion failed) (unsigned)(i 1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()) in function 'cv::Mat::at'

```

As I understand it, there is an assignment error, but I don’t know how to fix it. Please help me.

---

<div class="post-metadata">

**Author:** ![sturkmen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/sturkmen/32/13_2.png) [@sturkmen](https://forum.opencv.org/u/sturkmen)\
**Post date:** [March 20, 2022, 1:17pm UTC](https://forum.opencv.org/t/setting-the-brightness-of-the-image-point/8025/2 "2022-03-20T13:17:52Z")

</div>

`img.at<uchar>(row,col) = 0; // attention row,col means y,x`

take a look at [the documentation](https://docs.opencv.org/4.x/d3/d63/classcv_1_1Mat.html#aa5d20fc86d41d59e4d71ae93daee9726)

---

<div class="post-metadata">

**Author:** ![tumanovalex](https://avatars.discourse-cdn.com/v4/letter/t/ba9def/32.png) [@tumanovalex](https://forum.opencv.org/u/tumanovalex)\
**Post date:** [March 20, 2022, 2:24pm UTC](https://forum.opencv.org/t/setting-the-brightness-of-the-image-point/8025/3 "2022-03-20T14:24:10Z")

</div>

Thank you very much. Mixed up x and y.
