当前位置:网站首页>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!您的鼓励是我创作的最大动力!
边栏推荐
- Cholesterol-PEG-Azide CLS-PEG-N3 胆固醇-聚乙二醇-叠氮 MW:3400
- Cholesterol-PEG-Thiol CLS-PEG-SH 胆固醇-聚乙二醇-巯基
- MySQL 出现 The table is full 的解决方法
- PyTorch学习笔记08——加载数据集
- 自己设置的私密文件,在哪找
- 2021-09-30
- CAS:474922-22-0 Maleimide-PEG-DSPE Phospholipid-Polyethylene Glycol-Maleimide Brief Description
- Numpy常用函数
- Nmap的下载与安装
- DSPE-PEG-Thiol DSPE-PEG-SH phospholipid-polyethylene glycol-thiol liposome for later use
猜你喜欢
PyTorch学习笔记08——加载数据集
mPEG-DSPE 178744-28-0 Methoxy-polyethylene glycol-phosphatidylethanolamine linear PEG phospholipids
Cholesterol-PEG-Azide CLS-PEG-N3 Cholesterol-PEG-Azide MW:3400
DingTalk Enterprise Internal-H5 Micro Application Development
IDEA控制台不能输入信息的解决方法
cv2.imread()
DSPE-PEG-Azide DSPE-PED-N3 Phospholipid-Polyethylene Glycol-Azide Lipid PFG
活体检测PatchNet学习笔记
多元线性回归方程原理及其推导
Pytorch学习笔记7——处理多维特征的输入
随机推荐
RuntimeError: CUDA error: no kernel image is available for execution on the device问题记录
ROS 之订阅多个topic时间同步问题
2021-09-30
random.randint函数用法
[已解决]ssh连接报:Bad owner or permissions on C:\\Users/XXX/.ssh/config
Data Preprocessing, Feature Engineering, and Feature Learning - Excerpt
VTK环境配置
Cholesterol-PEG-NHS NHS-PEG-CLS cholesterol-polyethylene glycol-active ester can modify small molecular materials
钉钉企业内部-H5微应用开发
Jupyter内核正忙、内核挂掉
数据预处理、特征工程和特征学习-摘抄
Shell/Vim相关list
JS写一段代码,判断一个字符串中出现次数最多的字符串,并统计出现的次数JS
pyspark.ml特征变换模块
DSPE-PEG-Biotin, CAS: 385437-57-0, phospholipid-polyethylene glycol-biotin prolongs circulating half-life
Navicat从本地文件中导入sql文件
np.fliplr与np.flipud
钉钉H5微应用免登鉴权
Attention based ASR(LAS)
Cholesterol-PEG-Acid CLS-PEG-COOH 胆固醇-聚乙二醇-羧基修饰肽类化合物