找到灰度图像中心条纹最大值的极值法?
#include<opencv2/core/core.hpp>
#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<iostream>
#include <vector>
using namespace std;
using namespace cv;
void colorReduce(Mat& inputImage,Mat& outputImage);
int main()
{
Mat gray,dstImage;
Mat srcImage=imread("002.jpg");
cvtColor(srcImage,gray,CV_RGB2GRAY);
imshow("灰度图",gray);
dstImage.create(srcImage.rows,srcImage.cols,srcImage.type());
double time0=static_cast<double>(getTickCount());
colorReduce(gray,dstImage);
time0=((double)getTickCount()-time0)/getTickFrequency();
cout<<"此方法运行时间为:"<<time0<<"秒"<<endl;
imshow("效果图",dstImage);
waitKey(0);
}
void colorReduce(Mat& inputImage,Mat& outputImage)
{
outputImage=inputImage.clone();
int rowNumber=outputImage.rows;
int colNumber=outputImage.cols*outputImage.channels();
for(int i=0;i<rowNumber;i++)
{
uchar*data=outputImage.ptr<uchar>(i);
int max=190;
for(int j=0;j<colNumber;j++)
{
if (max<data[j])
{
max=data[j];
}
else
{
data[j]=0;
}
}
}
}
像素处理部分有问题,得出的图像有的行有两个像素点。请问编程如何选其一?