当前位置:网站首页>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!!!
边栏推荐
- Guangzhou held work safety conference
- [statistical learning method] learning notes - support vector machine (I)
- Realize all, race, allsettled and any of the simple version of promise by yourself
- Several methods of checking JS to judge empty objects
- 【深度学习】图像多标签分类任务,百度PaddleClas
- 浅谈估值模型 (二): PE指标II——PE Band
- Realize a simple version of array by yourself from
- 普乐蛙小型5d电影设备|5d电影动感电影体验馆|VR景区影院设备
- Attack and defense world - PWN learning notes
- 【PyTorch实战】用RNN写诗
猜你喜欢
leetcode刷题:二叉树22(二叉搜索树的最小绝对差)
File upload vulnerability - upload labs (1~2)
Static vxlan configuration
What is an esp/msr partition and how to create an esp/msr partition
[pytorch practice] use pytorch to realize image style migration based on neural network
Several methods of checking JS to judge empty objects
[爬虫]使用selenium时,躲避脚本检测
SQL lab 11~20 summary (subsequent continuous update) contains the solution that Firefox can't catch local packages after 18 levels
Dialogue with Wang Wenyu, co-founder of ppio: integrate edge computing resources and explore more audio and video service scenarios
基于NeRF的三维内容生成
随机推荐
聊聊Redis缓存4种集群方案、及优缺点对比
利用棧來實現二進制轉化為十進制
2022-07-07日报:GAN发明者Ian Goodfellow正式加入DeepMind
leetcode刷题:二叉树25(二叉搜索树的最近公共祖先)
【从 0 开始学微服务】【03】初探微服务架构
[statistical learning method] learning notes - support vector machine (Part 2)
PHP调用纯真IP数据库返回具体地址
JS to convert array to tree data
[Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
解密GD32 MCU产品家族,开发板该怎么选?
Configure an encrypted web server
浅谈估值模型 (二): PE指标II——PE Band
Vxlan static centralized gateway
Day-16 set
Day-15 common APIs and exception mechanisms
HZOJ #235. 递归实现指数型枚举
visual stdio 2017关于opencv4.1的环境配置
金融数据获取(三)当爬虫遇上要鼠标滚轮滚动才会刷新数据的网页(保姆级教程)
Day-19 IO stream
Cookie