voidsalt(Mat &image, int n){
for (int k = 0; k < n; k++){
int i = rand() % image.cols;
int j = rand() % image.rows;
// rand() ranges from 0 to int.maxif the denominator is large its not
// uniform distribution
if (image.channels() == 1){
// 255 means white
image.at<uchar>(j, i) = 255;
}
else if (image.channels() == 3){
//color image has 3 channels : blue yellow red in scale form
image.at<Vec3b>(j, i)[0] = 255;
image.at<Vec3b>(j, i)[1] = 255;
image.at<Vec3b>(j, i)[2] = 255;
}
}
}
Then
// reducethe quality of each pixel
voidcolorReduce(Mat &image, int div = 64){
int nl = image.rows;
int nc = image.cols*image.channels();
for (int i = 0; i < nl; i++){
uchar* data = image.ptr<uchar>(i);
// .ptr is more efficient than .at
for (int j = 0; j < nc; j++){
data[j] = data[j] / div*div + div / 2;
//another way is to use bit operator which is a very efficientalternative
// data[j]=(data[j]&(0xFF<<n))+div/2;
}
}
}
2/4/2015 11:34 AM - Screen Clipping
If u wanna haveinput and output in the method
It can be wirttenlike void colorReduce(const Mat &image, Mat &result, int div=64);
To a continuous line
Image.reshape(1,rows*cols);
channel newrows
&image.at(j,i)
Means data =image.data+ j*image.step+i*image.elemSize()
Using iterator toaccess pixels
Mat_<Vec3b>::iteratorit = image.begin<Vec3b>(), itend = image.end<Vec3b>();
It++
(*it)[0]
Its convenient but the pointer type is the fastest
In the following waywe can count time is ms;
double duration = static_cast<double>(getTickCount());
colorReduce(image);
duration = static_cast<double>(getTickCount()) - duration;
duration /= getTickFrequency();
void sharpen(Mat &image,Mat &result){
result.create(image.size(), image.type());
for (int i = 1; i < image.rows-1;i++)
{
const uchar* previous = image.ptr<const uchar>(i - 1);
const uchar* current = image.ptr<const uchar>(i);
const uchar* next = image.ptr< const uchar>(i + 1);
uchar* output = result.ptr<uchar>(i);
for (int j = 1; j < image.cols - 1; j++){
*output++ =saturate_cast<uchar>( current[j] * 5 - current[j -1] - current[j + 1] - previous[j] - next[j]);
//saturate means 0<= uchar<=255
}
}
result.row(0).setTo(Scalar(0));
result.row(result.rows-1).setTo(Scalar(0));
result.col(0).setTo(Scalar(0));
result.col(result.cols-1).setTo(Scalar(0));
// deal with the whole row or column
}
Add onepic to another
// c[i]=a[i]+b[i];
cv::add(imageA,imageB,resultC);
// c[i]= a[i]+k;
cv::add(imageA,cv::Scalar(k),resultC);
// c[i]= k1*a[1]+k2*b[i]+k3;
cv::addWeighted(imageA,k1,imageB,k2,k3,resultC);
// c[i]= k*a[1]+b[i];
cv::scaleAdd(imageA,k,imageB,resultC);
Add weightis overloaded
result=0.7*image1+0.9*image2;
image=(image&cv::Scalar(mask,mask,mask))
+cv::Scalar(div/2,div/2,div/2);
Split andmerge
// create vector of 3 images
std::vector<cv::Mat> planes;
// split 1 3-channel image into 3 1-channelimages
cv::split(image1,planes);
// add to blue channel
planes[0]+= image2;
// merge the 3 1-channel images into 13-channel image
cv::merge(planes,result);
ROI
Rect(200,250,logoImage.cols,logoImage.rows)
cv::MatimageROI= image(cv::Range(270,270+logo.rows),
cv::Range(385,385+logo.cols))
image.colRange(start,end);
intmain(){
Mat logo= imread("logo.jpg");
Mat image = imread("rain.jpg");
//the same size
Mat ROI;
Mat result;
imshow("old", image);
result.create(image.size(), image.type());
double duration = static_cast<double>(getTickCount());
//
ROI = image(Rect(0, 0, logo.cols,logo.rows));
addWeighted(logo, 0.3,ROI, 1.0, 0.0,ROI);
//
duration = static_cast<double>(getTickCount()) - duration;
duration /= getTickFrequency();
cout << duration;
imshow("new",image);
waitKey(0);
}
相关推荐
爱分享、爱极客的编程怪兽--DaveBobo 博文 《【OpenCV学习笔记 005】 操作像素》 博文链接: http://blog.csdn.net/davebobo/article/details/52541612 OpenCV版本:2.4.9
https://www.bilibili.com/video/BV1PV411774y?p=47
主要为大家详细介绍了Python OpenCV处理图像之图像像素点操作,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
opencv入门学习文档,是根据个人学习记录的笔记总计三百多页,内含书签,文档简洁适合快速入门,了解图像处理,视频跟踪,神经网络等概念和基本原理,以及人脸识别案例在Opencv中的实现,内含了C++实现源代码。
使用opencv获得图像中每一点的像素值 可以对图像中的每一点像素值进行单独的操作
opencv入门教程,内含pdf书籍和每章c++源码opencv入门教程,内含pdf书籍和每章c++源码
OpenCV入门教程.pdf
爱分享、爱极客的编程怪兽--DaveBobo 博文 《【OpenCV学习笔记 007】使用直方图统计像素》 博文链接: http://blog.csdn.net/davebobo/article/details/52554968 OpenCV版本:2.4.9
OpenCV+TensorFlow 入门人工智能图像处理(无密完整)
摘要视图订阅标签: opencv腐蚀膨胀形态学图像处理分类:目录(?【OpenCV入门教程之十】 形态学图像处理(一):膨胀与腐蚀97882人阅读评论(73)收
OpenCV+TensorFlow 入门级别的人工智能图像处理视频教程
opencv图像处理入门,基础知识,基础简介,入门学习。从最基础开始学习。
opencv中的图像操作函数,方便的进行图像矩阵操作。
Opencv入门,讲解Opencv图像处理的基本知识,并配备了例子的源代码
OpenCV获取与设置像素点的值的几个方法
这是一段使用OpenCV和NumPy库进行图像像素操作的示例代码。代码中创建了一个黑色图像,并通过访问图像的通道(蓝色、绿色、红色)来操作像素值。在此示例中,代码将图像的一部分像素区域设置为红色,展示了如何使用...
爱分享、爱极客的编程怪兽--DaveBobo 博文 《【OpenCV学习笔记 012】估算图像间的投影关系》 博文链接: http://blog.csdn.net/davebobo/article/details/52653595 OpenCV版本:2.4.9
python-opencv获取二值图像轮廓及中心点坐标代码: groundtruth = cv2.imread(groundtruth_path)[:, :, 0] h1, w1 = groundtruth.shape contours, cnt = cv2.findContours(groundtruth.copy(), cv2.RETR_EXTERNAL, ...
《OpenCV3编程入门》适合于图像处理、计算机视觉领域的业余爱好者、开源项目爱好者做为通向新版OpenCV的参考手册之用