其他分享
首页 > 其他分享> > QT灰度直方图

QT灰度直方图

作者:互联网

int imgwidth=img->width();

int imgheight=img->height();

unsigned char* graydata =img->bits();

vector<int> hist(256);

//初始为0;

for(int i=0;i<256;i++;)

{

hist[i]=0;

}

for(int i=0;i<imgheight;i++)

{

for(int j=0;i<imgwidth;j++)

{

QColor color=img->pixelcolor(j,i);

int redcolor=color.red();

int greencolor=color.green();

int bluecolor=color.blue();

int index=(redColor+greenColor+blueColor);

hist[index]=hist[index]++;

graydata+=3;

}

}

//画图

QtCharts::QLineSeries *series=new QtCharts::QLineSeries();

for(int i=0;i<256;i++;)

{

series->append(i,hist[i]);

}

QtCharts::QChartView *chartView=new QtCharts::QChartView(ui.graphicsView_4);

chartView->chart()->addSeries(series);

series->setName("直方图");

QtCharts::QValueAxis *axisx=new QtCharts::QValueAxis();

axisx->setTitleText("像元个数");

chartView->chart()->setAxisX(axisx,series);

QtCharts::QValueAxis *axisy=new QtCharts::QValueAxis();

axisy->setTitleText("灰度值");

chartView->chart()->setAxisY(axisY,series);

charView->resize(ui.graphicsView_4->width(),ui.graphicsView_4->heigtht());

charView->show();

标签:hist,QT,QValueAxis,int,series,QtCharts,color,直方图,灰度
来源: https://www.cnblogs.com/WordHorizon/p/14049310.html