遍历图片上所有像素方法总结
来源:互联网 发布:java中如何计算时间差 编辑:程序博客网 时间:2024/05/16 11:10
方法大概有4中,这里只介绍其中3种:
一、基于c风格运算符[]访问
二、迭代法
三、核心函数LUT
这里第三种方法速度最快。如果使用指针的话,迭代法也不错。
以下为代码:
// b4.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <opencv245.h>using namespace std;using namespace cv;//c风格运算符【】访问void ScanP(Mat &img){CV_Assert(img.depth() != sizeof(uchar));int channels = img.channels();int nRows = img.rows;int nCols = img.cols * channels;if (img.isContinuous()){nCols *= nRows;nRows = 1;}for (int j = 0; j < nRows; j++){uchar* p = img.ptr<uchar>(j);for (int i = 0; i < nCols; i++){if (p[i] > 133){p[i] = 255;}}}}//运用Iterator指针来遍历void scanIterator(Mat &img){CV_Assert(img.depth() != sizeof(uchar));const int channels = img.channels();switch (channels){case 1:{MatIterator_<uchar> it, end;for ( it = img.begin<uchar>(), end = img.end<uchar>(); it != end; ++it)if (*it > 133){*it = 255;}break;}case 3:{MatIterator_<Vec3b> it, end;for ( it = img.begin<Vec3b>(), end = img.end<Vec3b>(); it !=end; ++it){if ( (*it)[0] > 100 | (*it)[1] > 100 | (*it)[2] > 100){(*it)[0] = 255;/*(*it)[1] = 255;(*it)[2] = 255;*/} }}}}//在进行批量图像元素查找和更改操作方法时,运用LUTvoid scanLUT(Mat &img, Mat &dst){int divideWith = 10;uchar table[256];for (int i = 0; i < 256; ++i){table[i] = i/divideWith * divideWith;}Mat lookUpTable(1, 256, CV_8U);uchar* p = lookUpTable.data;for (int i = 0; i < 256; ++i){p[i] = table[i];}LUT(img, lookUpTable, dst);}int _tmain(int argc, _TCHAR* argv[]){Mat src = imread("C:\\Users\\sony\\Desktop\\pic\\Airplane.jpg" );Mat dst;scanLUT(src, dst);imshow("img", dst);waitKey(0);return 0;}
- 遍历图片上所有像素方法总结
- 遍历图片上的所有像素
- 遍历sd卡上所有图片
- 遍历像素的方法
- OpenCV遍历图片像素点
- opencv高效访问图像像素(遍历像素的方法总结)
- 遍历页面上所有checkbox的两种方法
- C#中加载图片与读取图片上的像素点方法
- 遍历文件夹中的所有图片
- 快速保存网页上所有图片的方法
- 遍历图像像素点的方法
- 遍历图像像素的14种方法
- 递归调用的方式遍历SD卡上的所有图片
- 递归调用的方式遍历SD卡上的所有图片
- linux下遍历目录树方法总结(上)
- linux下遍历目录树方法总结(上)
- 从像素生成图片的方法
- opencv取图片像素的方法
- Linux Commands for Beginners--Creating Your First Scripting
- 考试系统之选择题评分
- oracle 如何将同一表中的某一列更新到另一列
- 测试neo4j
- java 调用 .net WebService
- 遍历图片上所有像素方法总结
- ssh_config详解
- 将目标文件的一部分或者全部内容拷贝到另外一个目标文件中 objcopy
- 【Chromium】多进程架构(Multi-process Architecture)
- oracle 导入数据库操作
- android HTTp协议获取数据总结
- openWrt软件开发教程1(交叉编译和ipk包生成)
- 滤波器的极点和零点是什么意思
- sql Server SQL分页语句