当前位置:网站首页>Image pixel read / write operation
Image pixel read / write operation
2022-07-07 12:46:00 【When will we get ashore?】
The sample code is as follows :
void demo::pixel_demo(Mat &image)
{
int w = image.cols;
int h = image.rows;
int dims = image.channels();
for (int i = 0; i < h; i++)
{
for (int j = 0; j < w; j++)
{
if (dims == 1)// Grayscale image
{
int p = image.at<uchar>(i, j);
image.at<uchar>(i, j) = 255 - p;
}
if (dims == 3)// Color images
{
Vec3b g = image.at<Vec3b>(i, j);
image.at<Vec3b>(i, j)[0] = 255 - g[0];
image.at<Vec3b>(i, j)[1] = 255 - g[1];
image.at<Vec3b>(i, j)[2] = 255 - g[2];
}
}
}
imshow(" Pixel image ", image);
}
This time is mainly for further study Mat( matrix )
adopt image.at<uchar>(i,j) Images can be obtained image In position (i,j) The pixel size of , Because gray image pixels have only one value ,uchar It means a unsigned char Size .
stay opencv in Vec3b A list of three numbers , Also exist Vec3i and Vec3f.
give the result as follows :

Here is how to change pixels by pointer
void demo::pixel_demo(Mat &image)
{
int w = image.cols;
int h = image.rows;
int dims = image.channels();for (int i = 0; i < h; i++)
{
uchar*p = image.ptr<uchar>(i);
for (int j = 0; j < w; j++)
{
if (dims == 1)
{
*p++ = 255 - *p;// First assign and then add
}
if (dims == 3)
{
*p++ = 255 - *p;// First assign and then add
*p++ = 255 - *p;// First assign and then add
*p++ = 255 - *p;// First assign and then add
}
}
}
imshow(" Pixel image ", image);}
The result is the same :

over!!!
边栏推荐
- 编译 libssl 报错
- 【从 0 开始学微服务】【00】课程概述
- 【PyTorch实战】用RNN写诗
- [pytorch practice] image description -- let neural network read pictures and tell stories
- [deep learning] image multi label classification task, Baidu paddleclas
- 通讯协议设计与实现
- Tutorial on principles and applications of database system (010) -- exercises of conceptual model and data model
- Day-19 IO stream
- ip2long与long2IP 分析
- Ctfhub -web SSRF summary (excluding fastcgi and redI) super detailed
猜你喜欢

2022聚合工艺考试题模拟考试题库及在线模拟考试

Financial data acquisition (III) when a crawler encounters a web page that needs to scroll with the mouse wheel to refresh the data (nanny level tutorial)

Charles: four ways to modify the input parameters or return results of the interface

Preorder, inorder and postorder traversal of binary tree

Static vxlan configuration

About web content security policy directive some test cases specified through meta elements

爱可可AI前沿推介(7.7)
![[pytorch practice] image description -- let neural network read pictures and tell stories](/img/39/b2c61ae0668507f50426b01f2deee4.png)
[pytorch practice] image description -- let neural network read pictures and tell stories

Common knowledge of one-dimensional array and two-dimensional array
![[statistical learning methods] learning notes - Chapter 5: Decision Tree](/img/0e/c60e04ab4a7ae4728cc76eff1c028a.png)
[statistical learning methods] learning notes - Chapter 5: Decision Tree
随机推荐
Routing strategy of multi-point republication [Huawei]
ps链接图层的使用方法和快捷键,ps图层链接怎么做的
爱可可AI前沿推介(7.7)
2022危险化学品生产单位安全生产管理人员考题及在线模拟考试
In the small skin panel, use CMD to enter the MySQL command, including the MySQL error unknown variable 'secure_ file_ Priv 'solution (super detailed)
Day-17 connection set
SQL head injection -- injection principle and essence
SQL lab 21~25 summary (subsequent continuous update) (including secondary injection explanation)
[deep learning] image multi label classification task, Baidu paddleclas
Idea 2021 Chinese garbled code
Several methods of checking JS to judge empty objects
【从 0 开始学微服务】【03】初探微服务架构
Preorder, inorder and postorder traversal of binary tree
SQL lab 26~31 summary (subsequent continuous update) (including parameter pollution explanation)
How to use PS link layer and shortcut keys, and how to do PS layer link
SQL lab 1~10 summary (subsequent continuous update)
[play RT thread] RT thread Studio - key control motor forward and reverse rotation, buzzer
(to be deleted later) yyds, paid academic resources, please keep a low profile!
HZOJ #236. 递归实现组合型枚举
金融数据获取(三)当爬虫遇上要鼠标滚轮滚动才会刷新数据的网页(保姆级教程)