• 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();

  • 相关阅读:
    MyBatis入门基础
    复制复杂链表
    二叉树中和为某一值的所有路径
    树的层次遍历
    Statement, PreparedStatement和CallableStatement的区别
    JSP有哪些动作?
    latex 输入矩阵
    Struts简单入门实例
    在Eclipse里面配置Struts2
    Windows使用Github
  • 原文地址:https://www.cnblogs.com/WordHorizon/p/14049310.html
Copyright © 2020-2023  润新知