当前位置:网站首页>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!!!
边栏推荐
- opencv的四个函数
- Solve server returns invalid timezone Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually
- HZOJ #236. 递归实现组合型枚举
- [learn micro services from 0] [02] move from single application to service
- SQL lab 11~20 summary (subsequent continuous update) contains the solution that Firefox can't catch local packages after 18 levels
- 2022-07-07日报:GAN发明者Ian Goodfellow正式加入DeepMind
- Guangzhou held work safety conference
- 广州市召开安全生产工作会议
- Preorder, inorder and postorder traversal of binary tree
- 【统计学习方法】学习笔记——第五章:决策树
猜你喜欢
金融数据获取(三)当爬虫遇上要鼠标滚轮滚动才会刷新数据的网页(保姆级教程)
Configure an encrypted web server
爱可可AI前沿推介(7.7)
SQL lab 21~25 summary (subsequent continuous update) (including secondary injection explanation)
Visual stdio 2017 about the environment configuration of opencv4.1
[statistical learning method] learning notes - support vector machine (I)
leetcode刷题:二叉树25(二叉搜索树的最近公共祖先)
Ctfhub -web SSRF summary (excluding fastcgi and redI) super detailed
leetcode刷题:二叉树26(二叉搜索树中的插入操作)
leetcode刷题:二叉树22(二叉搜索树的最小绝对差)
随机推荐
【深度学习】图像多标签分类任务,百度PaddleClas
Solutions to cross domain problems
Static routing assignment of network reachable and telent connections
About IPSec
Day-18 hash table, generic
leetcode刷题:二叉树21(验证二叉搜索树)
Tutorial on principles and applications of database system (009) -- conceptual model and data model
Learning and using vscode
SQL injection -- Audit of PHP source code (take SQL lab 1~15 as an example) (super detailed)
Day-19 IO stream
【PyTorch实战】用PyTorch实现基于神经网络的图像风格迁移
图形对象的创建与赋值
SQL head injection -- injection principle and essence
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)
Master formula. (used to calculate the time complexity of recursion.)
How much does it cost to develop a small program mall?
Airserver automatically receives multi screen projection or cross device projection
Day-14 common APIs
【统计学习方法】学习笔记——第五章:决策树
[statistical learning method] learning notes - support vector machine (Part 2)