宁夏建设工程质量网站,丰润区建设局网站,吉林市网站建设公司哪家好,晋中做网站1.什么是直方图
直方图是一种图形化展示数据频率分布的方式。它将样本数据分成一系列相邻的区间#xff0c;统计每个区间内数据所占比例或数量#xff0c;并用矩形条形图表现出来。直方图可以反映样本数据的分布情况#xff0c;例如它们的集中趋势、对称性和离散程度等。
…1.什么是直方图
直方图是一种图形化展示数据频率分布的方式。它将样本数据分成一系列相邻的区间统计每个区间内数据所占比例或数量并用矩形条形图表现出来。直方图可以反映样本数据的分布情况例如它们的集中趋势、对称性和离散程度等。
直方图在数据分析和处理过程中有广泛的应用例如 可以用于检查数据是否符合正态分布从而判断使用什么类型的统计方法。 可以用于比较多组数据的分布情况从而寻找它们的异同点。 可以用于数字图像处理中对图像像素的亮度、对比度等特征进行定量描述。 可以用于形态学图像处理中比如分割和重建等。
总的来说直方图的作用是通过直观的图形展示方式帮助分析者快速理解和评估数据的统计特征从而更准确和全面地进行数据分析和处理。
2.qt编写灰度图像直方图 // 统计灰度级别的像素数量 绘制直方图QVectorint histogram(256, 0); // 存储每个灰度级别的像素数量for (int i 0; i image.width(); i){for (int j 0; j image.height(); j){QColor color(image.pixel(i, j));int gray qGray(color.rgb()); // 获取灰度级别if((gray 30) ( gray 225)){histogram[gray];}}}QImage histogramImage(256, 256, QImage::Format_RGB32); // 创建直方图图像histogramImage.fill(Qt::black); // 设置背景颜色QPainter painter(histogramImage);painter.setPen(Qt::white);int maxCount *std::max_element(histogram.begin(), histogram.end()); // 获取像素数量最大值for (int i 0; i 256; i){int count histogram[i];int x i;int y histogramImage.height() - (static_castdouble(count) / maxCount) * histogramImage.height();painter.drawLine(x, histogramImage.height(), x, y);}QPixmap pixmap_hisinput;pixmap_hisinput pixmap_hisinput.fromImage(histogramImage);ui-lb_histir-setPixmap(pixmap_hisinput.scaled(ui-lb_histir-size(), Qt::KeepAspectRatio, Qt::FastTransformation)); 3.qt绘制rgb图像直方图 QVectorint redHistogram(256, 0); // 存储红色通道灰度级别的像素数量QVectorint greenHistogram(256, 0); // 存储绿色通道灰度级别的像素数量QVectorint blueHistogram(256, 0); // 存储蓝色通道灰度级别的像素数量for (int i 0; i image.width(); i){for (int j 0; j image.height(); j){QColor color(image.pixel(i, j));int red color.red(); // 获取红色通道的灰度级别int green color.green(); // 获取绿色通道的灰度级别int blue color.blue(); // 获取蓝色通道的灰度级别//if ((red 30) (red 225) (green 30) (green 225) (blue 30) (blue 225)){redHistogram[red];greenHistogram[green];blueHistogram[blue];}}}// 绘制红色通道直方图QImage redHistogramImage(256, 256, QImage::Format_RGB32); // 创建红色通道直方图图像redHistogramImage.fill(Qt::black); // 设置背景颜色QPainter redHistogramPainter(redHistogramImage);redHistogramPainter.setPen(Qt::red);int maxRedCount *std::max_element(redHistogram.begin(), redHistogram.end());for (int i 0; i 256; i){int count redHistogram[i];int x i;int y redHistogramImage.height() - (static_castdouble(count) / maxRedCount) * redHistogramImage.height();redHistogramPainter.drawLine(x, redHistogramImage.height(), x, y);}// 绘制绿色通道直方图QImage greenHistogramImage(256, 256, QImage::Format_RGB32); // 创建绿色通道直方图图像greenHistogramImage.fill(Qt::black); // 设置背景颜色QPainter greenHistogramPainter(greenHistogramImage);greenHistogramPainter.setPen(Qt::green);int maxGreenCount *std::max_element(greenHistogram.begin(), greenHistogram.end());for (int i 0; i 256; i){int count greenHistogram[i];int x i;int y greenHistogramImage.height() - (static_castdouble(count) / maxGreenCount) * greenHistogramImage.height();greenHistogramPainter.drawLine(x, greenHistogramImage.height(), x, y);}// 绘制蓝色通道直方图QImage blueHistogramImage(256, 256, QImage::Format_RGB32); // 创建蓝色通道直方图图像blueHistogramImage.fill(Qt::black); // 设置背景颜色QPainter blueHistogramPainter(blueHistogramImage);blueHistogramPainter.setPen(Qt::blue);int maxBlueCount *std::max_element(blueHistogram.begin(), blueHistogram.end());for (int i 0; i 256; i){int count blueHistogram[i];int x i;int y blueHistogramImage.height() - (static_castdouble(count) / maxBlueCount) * blueHistogramImage.height();blueHistogramPainter.drawLine(x, blueHistogramImage.height(), x, y);}// 将直方图图像显示到三个控件中QPixmap redPixmap;redPixmap redPixmap.fromImage(redHistogramImage);ui-lb_histrgb_red-setPixmap(redPixmap.scaled(ui-lb_histrgb_red-size(), Qt::KeepAspectRatio, Qt::FastTransformation));QPixmap greenPixmap;greenPixmap greenPixmap.fromImage(greenHistogramImage);ui-lb_histrgb_green-setPixmap(greenPixmap.scaled(ui-lb_histrgb_green-size(), Qt::KeepAspectRatio, Qt::FastTransformation));QPixmap bluePixmap;bluePixmap bluePixmap.fromImage(blueHistogramImage);ui-lb_histrgb_blue-setPixmap(bluePixmap.scaled(ui-lb_histrgb_blue-size(), Qt::KeepAspectRatio, Qt::FastTransformation));