当前位置:网站首页>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!!!
边栏推荐
- Realize a simple version of array by yourself from
- 广州市召开安全生产工作会议
- 对话PPIO联合创始人王闻宇:整合边缘算力资源,开拓更多音视频服务场景
- IPv6 experiment
- MPLS experiment
- Static routing assignment of network reachable and telent connections
- Day-20 file operation, recursive copy, serialization
- sql-lab (54-65)
- 2022-07-07日报:GAN发明者Ian Goodfellow正式加入DeepMind
- Day-19 IO stream
猜你喜欢

opencv的四个函数

Attack and defense world - PWN learning notes

IPv6 experiment

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

2022广东省安全员A证第三批(主要负责人)考试练习题及模拟考试

Pule frog small 5D movie equipment | 5D movie dynamic movie experience hall | VR scenic area cinema equipment

leetcode刷题:二叉树22(二叉搜索树的最小绝对差)

ICLR 2022 | 基于对抗自注意力机制的预训练语言模型

Day-16 set

Customize the web service configuration file
随机推荐
In the small skin panel, use CMD to enter the MySQL command, including the MySQL error unknown variable 'secure_ file_ Priv 'solution (super detailed)
Error in compiling libssl
SQL Lab (36~40) includes stack injection, MySQL_ real_ escape_ The difference between string and addslashes (continuous update after)
【从 0 开始学微服务】【02】从单体应用走向服务化
普乐蛙小型5d电影设备|5d电影动感电影体验馆|VR景区影院设备
[play RT thread] RT thread Studio - key control motor forward and reverse rotation, buzzer
NPM instal reports agent or network problems
How to use PS link layer and shortcut keys, and how to do PS layer link
The IDM server response shows that you do not have permission to download the solution tutorial
SQL lab 26~31 summary (subsequent continuous update) (including parameter pollution explanation)
Tutorial on principles and applications of database system (010) -- exercises of conceptual model and data model
广州市召开安全生产工作会议
Importance of database security
2022危险化学品生产单位安全生产管理人员考题及在线模拟考试
2022-07-07日报:GAN发明者Ian Goodfellow正式加入DeepMind
mysql怎么创建,删除,查看索引?
[疑难杂症]pip运行突然出现ModuleNotFoundError: No module named ‘pip‘
2022广东省安全员A证第三批(主要负责人)考试练习题及模拟考试
利用栈来实现二进制转化为十进制
【PyTorch实战】用RNN写诗