当前位置:网站首页>Three methods of accessing image pixels in opencv
Three methods of accessing image pixels in opencv
2022-07-31 06:32:00 【xp_fangfei】
Pointer to access pixels
这种方法最快,但是有点抽象
例1:Simple pixel manipulation
for (int i = 0; i < _img.rows; i++) //行循环
{
uchar *data = _img.ptr<uchar>(i); //获取第i行的首地址
for (int j = 0; j < _img.cols; j++) //列循环
{
data[j] = data[j]/2; //处理每个像素
}
}
Dynamic address manipulation of pixels
This method is simple and clear in line with everyone's understanding of pixels;
例2:Simple pixel manipulation
for (size_t i = 0; i < _img.rows; i++) //行循环
{
for (size_t j = 0; j < _img.cols; j++) //列循环
{
_img.at<cv::Vec3b>(i,j) = cv::Vec3b(0,0,0); //处理每个像素
}
}
例3:Determine the pixel value under certain conditions,Operations on pixel values
for (size_t i = 0; i < _img.rows; i++) //行循环
{
for (size_t j = 0; j < _img.cols; j++) //列循环
{
//The following pixel operations
if (_img.at<cv::Vec3b>(i,j)[0] >= 100 && _img.at<cv::Vec3b>(i,j)[0] <= 124 &&
_img.at<cv::Vec3b>(i,j)[1] >= 43 && _img.at<cv::Vec3b>(i,j)[1] <= 255 &&
_img.at<cv::Vec3b>(i,j)[2] >= 46 && _img.at<cv::Vec3b>(i,j)[2] <=255)
{
_img.at<cv::Vec3b>(i,j) = cv::Vec3b(0,0,0);;
}else{
_img.at<cv::Vec3b>(i,j) = cv::Vec3b(255,255,255);
}
}
}
迭代器操作像素
This method is to get the image matrixbegin和end,然后增加迭代从begin到end,将*操作符添加在迭代指针前,即可访问当前指向的内容.
例3
cv::Mat_<cv::Vec3b>::iterator it = _img.begin<cv::Vec3b>(); //初始位置的迭代器
cv::Mat_<cv::Vec3b>::iterator itend = _img.end<cv::Vec3b>(); //终止位置的迭代器
//存取彩色图像像素
for(;it != itend; ++it)
{
(*it)[0] = (*it)[0]/2;
(*it)[1] = (*it)[1]/2;
(*it)[2] = (*it)[2]/2;
}
So far, several methods have been introduced!
If the above helps you,Please follow and add favorites!您的鼓励是我创作的最大动力!
边栏推荐
- DSPE-PEG-Thiol DSPE-PEG-SH 磷脂-聚乙二醇-巯基脂质体制备用
- 2021-09-30
- DingTalk H5 micro-app login authentication
- 自然语言处理相关list
- DSPE-PEG-Thiol DSPE-PEG-SH phospholipid-polyethylene glycol-thiol liposome for later use
- Pytorch每日一练——预测泰坦尼克号船上的生存乘客
- 这些数组技巧,我爱了
- Pytorch学习笔记09——多分类问题
- Learn how to get a database connection with JDBC
- Cholesterol-PEG-Amine CLS-PEG-NH2 Cholesterol-Polyethylene Glycol-Amino Research Use
猜你喜欢

pyspark.ml特征变换模块

IDEA控制台不能输入信息的解决方法

CLS-PEG-FITC Fluorescein-PEG-CLS 胆固醇-聚乙二醇-荧光素简介

多元线性回归方程原理及其推导

VTK:Could not locate vtkTextRenderer object.

二进制转换成十六进制、位运算、结构体

Software Testing Interview Questions 2021

OpenCV中的图像数据格式CV_8U定义

Cholesterol-PEG-NHS NHS-PEG-CLS cholesterol-polyethylene glycol-active ester can modify small molecular materials

MW:3400 4-Arm PEG-DSPE 四臂-聚乙二醇-磷脂一种饱和的18碳磷脂
随机推荐
CNN的一点理解
数据预处理、特征工程和特征学习-摘抄
MW:3400 4-Arm PEG-DSPE 四臂-聚乙二醇-磷脂一种饱和的18碳磷脂
The content of the wangeditor editor is transferred to the background server for storage
如何修改数据库密码
pytorch模型微调finetuning训练image_dog(kaggle)
【解决问题】RuntimeError: The size of tensor a (80) must match the size of tensor b (56) at non-singleton
Cholesterol-PEG-Amine CLS-PEG-NH2 胆固醇-聚乙二醇-氨基科研用
softmax函数详解
The solution to the IDEA console not being able to enter information
Wangeditor rich text editor to upload pictures and solve cross-domain problems
TransactionTemplate transaction programmatic way
DingTalk H5 micro-app login authentication
CAS: 1403744-37-5 DSPE-PEG-FA Phospholipid-Polyethylene Glycol-Folic Acid for Scientific Research
科研试剂Cholesterol-PEG-Maleimide,CLS-PEG-MAL,胆固醇-聚乙二醇-马来酰亚胺
【Rhapsody学习笔记】3:Dishwasher
浏览器中的画中画(Picture-in-Picture)API
opencv之访问图像像素的三种方法
会话和饼干,令牌
mysql 事务原理详解