当前位置:网站首页>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!!!
边栏推荐
- 解密GD32 MCU产品家族,开发板该怎么选?
- layer弹出层的关闭问题
- Solutions to cross domain problems
- Guangzhou held work safety conference
- ICLR 2022 | 基于对抗自注意力机制的预训练语言模型
- "Series after reading" my God! It's so simple to understand throttling and anti shake~
- SQL lab 11~20 summary (subsequent continuous update) contains the solution that Firefox can't catch local packages after 18 levels
- Tutorial on principles and applications of database system (009) -- conceptual model and data model
- Talk about four cluster schemes of redis cache, and their advantages and disadvantages
- [Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
猜你喜欢
![Routing strategy of multi-point republication [Huawei]](/img/5c/2e3b739ce7199f0d2a4ddd7c3856fc.jpg)
Routing strategy of multi-point republication [Huawei]

Tutorial on the principle and application of database system (011) -- relational database

Solve server returns invalid timezone Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually

浅谈估值模型 (二): PE指标II——PE Band

图形对象的创建与赋值

Zhimei creative website exercise

金融数据获取(三)当爬虫遇上要鼠标滚轮滚动才会刷新数据的网页(保姆级教程)

Decrypt gd32 MCU product family, how to choose the development board?

Tutorial on principles and applications of database system (010) -- exercises of conceptual model and data model

Visual stdio 2017 about the environment configuration of opencv4.1
随机推荐
ip2long与long2IP 分析
Polymorphism, final, etc
【统计学习方法】学习笔记——第四章:朴素贝叶斯法
How to apply @transactional transaction annotation to perfection?
Tutorial on principles and applications of database system (009) -- conceptual model and data model
【PyTorch实战】图像描述——让神经网络看图讲故事
SQL Lab (32~35) contains the principle understanding and precautions of wide byte injection (continuously updated later)
爱可可AI前沿推介(7.7)
如何将 @Transactional 事务注解运用到炉火纯青?
The road to success in R & D efficiency of 1000 person Internet companies
[疑难杂症]pip运行突然出现ModuleNotFoundError: No module named ‘pip‘
Day-17 connection set
leetcode刷题:二叉树27(删除二叉搜索树中的节点)
Using stack to convert binary to decimal
2022-07-07日报:GAN发明者Ian Goodfellow正式加入DeepMind
Airserver automatically receives multi screen projection or cross device projection
Talk about four cluster schemes of redis cache, and their advantages and disadvantages
SQL lab 1~10 summary (subsequent continuous update)
What is an esp/msr partition and how to create an esp/msr partition
[statistical learning methods] learning notes - Chapter 5: Decision Tree