当前位置: 首页 > wzjs >正文

wordpress to phonegap百度快照优化排名怎么做

wordpress to phonegap,百度快照优化排名怎么做,上海做网站企业,wordpress把头像改为QQ头像第二节 图像像素操作 1.访问像素值2.用指针扫描图像3.扫描图像并访问相邻像素4.实现简单的图像运算5.图像重映射 1.访问像素值 以椒盐噪声为例展示像素值访问的几种方法 void salt(cv::Mat image, int n) {// C11 random number generatorstd::default_random_engine generat…

第二节 图像像素操作

  • 1.访问像素值
  • 2.用指针扫描图像
  • 3.扫描图像并访问相邻像素
  • 4.实现简单的图像运算
  • 5.图像重映射

1.访问像素值

以椒盐噪声为例展示像素值访问的几种方法

void salt(cv::Mat image, int n) {// C++11 random number generatorstd::default_random_engine generator;std::uniform_int_distribution<int> randomRow(0, image.rows - 1);std::uniform_int_distribution<int> randomCol(0, image.cols - 1);// use image with a Mat_ template 使用模板操作做转换后可直接访问cv::Mat_<uchar> img(image);int i,j;for (int k=0; k<n; k++) {// random image coordinatei= randomCol(generator);j= randomRow(generator);// 自适应通道数if (image.type() == CV_8UC1) { // gray-level image// single-channel 8-bit imageimage.at<uchar>(j,i)= 255; } else if (image.type() == CV_8UC3) { // color image// 3-channel imageimage.at<cv::Vec3b>(j,i)[0]= 255; image.at<cv::Vec3b>(j,i)[1]= 255; image.at<cv::Vec3b>(j,i)[2]= 255; // 直接使用位置访问 下列为单通道赋值img(j,i)= 255; // or simply:// image.at<cv::Vec3b>(j, i) = cv::Vec3b(255, 255, 255);}}
}

2.用指针扫描图像

以处理图像像素为例展示指针扫描图像,使用指针并结合位运算的速度远高于逐个计算,double duration = (cv::getTickCount() - start) / cv::getTickFrequency()使用该语句实现算法是耗时分析:

void colorReduceIO(const cv::Mat &image, // input imagecv::Mat &result,      // output imageint div = 64) {int nl = image.rows; // number of linesint nc = image.cols; // number of columnsint nchannels = image.channels(); // number of channels// allocate output image if necessaryresult.create(image.rows, image.cols, image.type());//1.指针扫描处理for (int j = 0; j<nl; j++) {// get the addresses of input and output row j// 每一行的开头地址const uchar* data_in = image.ptr<uchar>(j);uchar* data_out = result.ptr<uchar>(j);// 在opencv中按照BGR-BGR逐个排列for (int i = 0; i<nc*nchannels; i++) {// process each pixel ---------------------data_out[i] = data_in[i] / div*div + div / 2;// end of pixel processing ----------------} // end of line}//2.图像实现运算符重载int n= static_cast<int>(log(static_cast<double>(div))/log(2.0) + 0.5);// mask used to round the pixel valueuchar mask= 0xFF<<n; // e.g. for div=16, mask= 0xF0// perform color reductionimage=(image&cv::Scalar(mask,mask,mask))+cv::Scalar(div/2,div/2,div/2);//3. 整图对象遍历cv::MatIterator_<cv::Vec3b> it= image.begin<cv::Vec3b>();cv::MatIterator_<cv::Vec3b> itend= image.end<cv::Vec3b>();const cv::Vec3b offset(div/2,div/2,div/2);for ( ; it!= itend; ++it) {// process each pixel ---------------------*it= *it/div*div+offset;// end of pixel processing ----------------}
}

3.扫描图像并访问相邻像素

在图像运算中,时长需要访问周边位置的像素,比如边缘提取、边缘锐化,以边缘锐化为例,展示如何访问相邻像素:

void sharpen2D(const cv::Mat &image, cv::Mat &result) {// 1. 直接使用filter2D进行卷积计算cv::Mat kernel(3,3,CV_32F,cv::Scalar(0));// assigns kernel valueskernel.at<float>(1,1)= 5.0;kernel.at<float>(0,1)= -1.0;kernel.at<float>(2,1)= -1.0;kernel.at<float>(1,0)= -1.0;kernel.at<float>(1,2)= -1.0;//filter the imagecv::filter2D(image,result,image.depth(),kernel);//2.通过指针实现高效运算result.create(image.size(), image.type()); // allocate if necessaryint nchannels= image.channels();for (int j= 1; j<image.rows-1; j++) { // for all rows (except first and last)const uchar* previous= image.ptr<const uchar>(j-1); // previous rowconst uchar* current= image.ptr<const uchar>(j);	// current rowconst uchar* next= image.ptr<const uchar>(j+1);		// next rowuchar* output= result.ptr<uchar>(j);	// output rowfor (int i=nchannels; i<(image.cols-1)*nchannels; i++) {// apply sharpening operator*output++= cv::saturate_cast<uchar>(5*current[i]-current[i-nchannels]-current[i+nchannels]-previous[i]-next[i]); }}// Set the unprocess pixels to 0 屏蔽边缘像素result.row(0).setTo(cv::Scalar(0));result.row(result.rows-1).setTo(cv::Scalar(0));result.col(0).setTo(cv::Scalar(0));result.col(result.cols-1).setTo(cv::Scalar(0));
}

4.实现简单的图像运算

Mat进行实现图像的一些简单操作:

	cv::addWeighted(image1,0.7,image2,0.9,0.,result);// using overloaded operatorresult= 0.7*image1+0.9*image2;//两种操作等效

5.图像重映射

在日常处理中,诸如投影变换,重采样,等等变换中,需要根据对应像素坐标位置计算目标位置,可通过重映射来快速实现:
void wave(const cv::Mat &image, cv::Mat &result) {// the map functionscv::Mat srcX(image.rows,image.cols,CV_32F); // x-mapcv::Mat srcY(image.rows,image.cols,CV_32F); // y-map// creating the mappingfor (int i=0; i<image.rows; i++) {for (int j=0; j<image.cols; j++) {//使用指针会更加高效 这里没有srcX.at<float>(i,j)= j;srcY.at<float>(i,j)= i+3*sin(j/6.0);// horizontal flipping// srcX.at<float>(i,j)= image.cols-j-1;// srcY.at<float>(i,j)= i;}}// applying the mapping 重映射函数cv::remap(image,  // source imageresult, // destination imagesrcX,   // x mapsrcY,   // y mapcv::INTER_LINEAR); // interpolation method
}

该节相关代码已上传到个人文档,按需下载
链接: 点击下载

http://www.dtcms.com/wzjs/152520.html

相关文章:

  • 如何在免费网站上做推扩网络优化工作内容
  • 新浪云怎么做自己的网站网站注册搜索引擎的目的是
  • 商业网站建设百度指数明星搜索排名
  • 山东省个人网站备案百度大搜推广
  • 360安全浏览器做网站测试减少缓存设置源码时代培训机构官网
  • myeclipse做网站百度怎么发布自己的广告
  • 嘉定南翔网站建设最新疫情消息
  • 印江建设局网站国际机票搜索量大涨
  • 整形医院网站源码下载谷歌引擎搜索入口
  • 做立体字的网站安卓手机优化神器
  • 网站建设目录结构doc天猫seo搜索优化
  • 平台搭建不武汉seo网站管理
  • 茂名做网站dyiee磁力搜索器
  • 网站模板交易网络seo是什么意思
  • 网站建设精英引流最好的推广方法
  • 为外国人做非法网站聚名网
  • 顺义区专业网站制作网站建设免费sem工具
  • 宁国网站建设外链代发软件
  • o2o网站建设如何竞价托管代运营公司
  • 手机网站怎么切图关键词推广方法
  • 哪些网站可以做招商广告语百度广告上的商家可靠吗
  • 网站跳出率一般是多少广告推广平台代理
  • 黑河网站seo软文写作公司
  • 揭阳制作公司网站seo网站优化工具
  • 潍坊哪里能找到做网站的宣传软文是什么
  • 哪个网站做供求信息电商培训课程
  • 百度做的网站最近几天的新闻
  • 网站建设的规划和设计潮州seo建站
  • 做名片上什么网站百度怎么做网站
  • 网站怎么做万词杭州网站定制