36 p_zoomer =
new QwtPlotZoomer(this->canvas());
37 setTitle(
"Histogram Plot");
39 QwtText *leftLabel =
new QwtText(
"Frequency", QwtText::PlainText);
40 leftLabel->setColor(Qt::red);
41 QFont font = leftLabel->font();
42 font.setPointSize(13);
44 leftLabel->setFont(font);
45 setAxisTitle(QwtPlot::yLeft, *leftLabel);
47 QwtText *rtLabel =
new QwtText(
"Percentage");
48 rtLabel->setColor(Qt::blue);
49 rtLabel->setFont(font);
50 setAxisTitle(QwtPlot::yRight, *rtLabel);
52 setAxisTitle(QwtPlot::xBottom,
"Pixel Value (DN)");
54 setAxisScale(QwtPlot::yRight, 0, 100);
55 enableAxis(QwtPlot::yRight,
true);
56 setCanvasBackground(Qt::white);
73 QVector<QPointF> histData;
74 QVector<QPointF> cdfData;
76 for(
int i = 0; i < hist.Bins(); i++) {
77 if(hist.BinCount(i) > 0) {
78 histData.append(QPointF(hist.BinMiddle(i), hist.BinCount(i)));
80 double pct = (double)hist.BinCount(i) / hist.ValidPixels() * 100.;
82 cdfData.append(QPointF(hist.BinMiddle(i), cumpct));
85 QPen *pen =
new QPen(Qt::red);
87 p_histCurve->setData(
new QwtPointSeriesData(histData));
92 pen->setColor(Qt::blue);
93 p_cdfCurve->setData(
new QwtPointSeriesData(cdfData));
133 static QPrinter *printer = NULL;
134 if(printer == NULL) printer =
new QPrinter;
135 QPageSize pageSize(QPageSize::Letter);
136 printer->setPageSize(pageSize);
137 printer->setColorMode(QPrinter::Color);
139 QPrintDialog printDialog(printer, (
QWidget *)parent());
140 if(printDialog.exec() == QDialog::Accepted) {
142 QPixmap pixmap = this->grab();
143 QImage img = pixmap.toImage();
146 QPainter painter(printer);
147 QRect rect = painter.viewport();
148 QSize size = img.size();
149 size.scale(rect.size(), Qt::KeepAspectRatio);
150 painter.setViewport(rect.x(), rect.y(),
151 size.width(), size.height());
152 painter.setWindow(img.rect());
153 painter.drawImage(0, 0, img);
165 QFileDialog::getSaveFileName((
QWidget *)parent(),
166 "Choose output file",
168 QString(
"Images (*.png *.jpg *.tif)"));
169 if(output.isEmpty())
return;
171 QString format = QFileInfo(output).suffix();
172 QPixmap pixmap = this->grab();
173 std::string formatString = format.toStdString();
174 if(!pixmap.save(output, formatString.c_str())) {
175 QMessageBox::information((
QWidget *)parent(),
"Error",
"Unable to save" + output);
186 QPen *pen =
new QPen(Qt::white);
187 if(canvasBackground() == Qt::white) {
188 setCanvasBackground(Qt::black);
193 setCanvasBackground(Qt::white);
194 pen->setColor(Qt::black);