std::vector<int> visionUtils::updateHSVAdaptiveSkin(std::vector<Mat> pixelPlanes, bool displayFaces)//( int, char** argv ) { if (displayFaces) { drawHist(pixelPlanes, 35); } Scalar b_mean, b_stdDev; meanStdDev(pixelPlanes[0], b_mean, b_stdDev); int b_min=b_mean[0] - b_stdDev[0]*3; int b_max=b_mean[0] + b_stdDev[0]*3; Scalar g_mean,g_stdDev; meanStdDev(pixelPlanes[1], g_mean,g_stdDev); int g_min=g_mean[0] - g_stdDev[0]*3; int g_max=g_mean[0] + g_stdDev[0]*3; Scalar r_mean, r_stdDev; meanStdDev(pixelPlanes[2], r_mean, r_stdDev); int r_min=r_mean[0] - r_stdDev[0]*3; int r_max=r_mean[0] + r_stdDev[0]*3; std::vector<int> hsvAdaptiveUpdated; hsvAdaptiveUpdated.push_back(b_min); hsvAdaptiveUpdated.push_back(g_min); hsvAdaptiveUpdated.push_back(r_min); hsvAdaptiveUpdated.push_back(b_max); hsvAdaptiveUpdated.push_back(g_max); hsvAdaptiveUpdated.push_back(r_max); return hsvAdaptiveUpdated; }
void MainWindow::on_actionGrayscale_triggered() { QPixmap pixmap = pixmapItem->pixmap().copy(); QImage image = pixmap.toImage(); for (int y = 0; y < image.height(); ++y) for (int x = 0; x < image.width(); ++x) { QRgb oldColor = image.pixel(x, y); int gray = qPow( 0.2126 * qPow(qRed(oldColor), 2.2) + 0.7152 * qPow(qGreen(oldColor), 2.2) + 0.0722 * qPow(qBlue(oldColor), 2.2), 1/2.2 ); QRgb newColor = qRgba(gray, gray, gray, qAlpha(oldColor)); image.setPixel(x, y, newColor); } pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }
void MainWindow::on_actionBinarization_manual_triggered() { Dialogbinarization dialog; if (dialog.exec() == QDialog::Accepted) { QPixmap pixmap = pixmapItem->pixmap().copy(); QRgb black = qRgb(0,0,0); QRgb white = qRgb(255,255,255); QImage image = pixmap.toImage(); for (int y = 0; y < image.height(); ++y) for (int x = 0; x < image.width(); ++x) { QRgb oldColor = image.pixel(x, y); int gray = qPow( 0.2126 * qPow(qRed(oldColor), 2.2) + 0.7152 * qPow(qGreen(oldColor), 2.2) + 0.0722 * qPow(qBlue(oldColor), 2.2), 1/2.2 ); QRgb newColor; if (dialog.methodChosed() == 1) { int treshold = dialog.treshold1(); if ( gray < treshold ) newColor = black; else newColor = white; } else if (dialog.methodChosed() == 2) { int treshold = dialog.treshold1(); if ( gray > treshold ) newColor = black; else newColor = white; } else { int treshold1 = dialog.treshold1(); int treshold2 = dialog.treshold2(); if ( treshold1 < gray && gray <= treshold2 ) newColor = black; else newColor = white; } image.setPixel(x, y, newColor); } pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); } }
void MainWindow::on_actionLoad_triggered() { QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image")); QPixmap pixmap(fileName); if ( ! pixmap.isNull() ) { pixmapItem->setPixmap(pixmap); scene->setSceneRect(QRectF(pixmap.rect())); QPixmap pixmapEmpty; pixmapItem_2->setPixmap(pixmapEmpty); scene_2->setSceneRect(QRectF(pixmapEmpty.rect())); calcHist(pixmap, hist, maxLevel); drawHist(pixmapItem_3, hist, maxLevel); hist_2.assign(256, 0); drawHist(pixmapItem_4, hist_2, maxLevel_2); } else ui->statusBar->showMessage(tr("File loading error"), 3000); }
bool MainWindow::eventFilter(QObject *object, QEvent *event) { if (ui->checkBox->isChecked() && object == ui->graphicsView && event->type() == QEvent::Paint) ui->graphicsView->fitInView(pixmapItem, Qt::KeepAspectRatio); if (ui->checkBox->isChecked() && object == ui->graphicsView_2 && event->type() == QEvent::Paint) ui->graphicsView_2->fitInView(pixmapItem_2, Qt::KeepAspectRatio); if (object == ui->graphicsView_3 && event->type() == QEvent::Paint) drawHist(pixmapItem_3, hist, maxLevel); if (object == ui->graphicsView_4 && event->type() == QEvent::Paint) drawHist(pixmapItem_4, hist_2, maxLevel_2); if (object == ui->graphicsView_2 && event->type() == QEvent::MouseButtonPress) { ++picturesRind; int curInd = picturesRind % picturesR.size(); pixmapItem_2->setPixmap(picturesR[curInd]); scene_2->setSceneRect(QRectF(picturesR[curInd].rect())); } return false; }
void MainWindow::on_actionBase_color_correction_triggered() { QPixmap pixmap = pixmapItem->pixmap().copy(); QImage image = pixmap.toImage(); int width = image.width(); int height = image.height(); if (width == 0 || height == 0) { ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 ); return; } DialogBaseColorCorrection dialog; dialog.setPixmap(pixmap); if (dialog.exec() == QDialog::Rejected) return; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { QRgb oldColor = image.pixel(x, y); double red = qRed(oldColor); double green = qGreen(oldColor); double blue = qBlue(oldColor); QColor dst = dialog.destinationColor(); QColor src = dialog.sourceColor(); red *= (double) dst.red() / src.red(); green *= (double) dst.green() / src.green(); blue *= (double) dst.blue() / src.blue(); if (red < 0) red = 0; if (red > 255) red = 255; if (green < 0) green = 0; if (green > 255) green = 255; if (blue < 0) blue = 0; if (blue > 255) blue = 255; image.setPixel(x, y, qRgb(red, green, blue)); } pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }
void MainWindow::on_actionBrightness_normalization_triggered() { QPixmap pixmap = pixmapItem->pixmap().copy(); QImage image = pixmap.toImage(); int width = image.width(); int height = image.height(); if (width == 0 || height == 0) { ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 ); return; } int minV = 256; int maxV = -1; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { QColor oldColor(image.pixel(x, y)); int v = oldColor.value(); if (v < minV) minV = v; if (v > maxV) maxV = v; } for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { QColor oldColor(image.pixel(x, y)); int v = ( oldColor.value() - minV) * 255 / (maxV - minV); if (v < 0) v = 0; if (v > 255) v = 255; QColor newColor; newColor.setHsv(oldColor.hue(), oldColor.saturation(), v); image.setPixel(x, y, newColor.rgb()); } pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }
void RDK2AnalysisPlotter::drawPlotComp(CoDet detType, PlotVarType plotVarType) { gROOT->cd(); TString histName; TH1** expHists=new TH1*[numExp]; TH1** mcHists=new TH1*[numMC]; int start=plotHists.size(); //We will use these hists straight off for (int i = 0;i< numExp;i++) { histName="hist"+int2str(plotHists.size()); expHists[i]=(TH1*) (getExpHist( i, detType, plotVarType)->Clone(histName)); plotHists.push_back(expHists[i]); setDisplayQuantitiesForHist(i,1,expHists[i],detType,PLOT_COMP,plotVarType); } for (int i = 0;i< numMC;i++) { histName="hist"+int2str(plotHists.size()); mcHists[i]=(TH1*) (getMCHist( i, detType, plotVarType)->Clone(histName)); plotHists.push_back(mcHists[i]); setDisplayQuantitiesForHist(-i-1,1,mcHists[i],detType,PLOT_COMP,plotVarType); if(detType==DET_EP && numExp>0)//Scale MC hists to first Exp Integral { scaleHistogramsTogether(expHists[0],mcHists[i],1,expHists[0]->GetNbinsX()); } } double max=0; for (int i = start;i< start+numExp+numMC;i++) { if(plotHists[i]->GetMaximum() > max) max=plotHists[i]->GetMaximum()+plotHists[i]->GetBinError(plotHists[i]->GetMaximumBin()); } for (int i = start;i< start+numExp+numMC;i++) { plotHists[i]->GetYaxis()->SetRangeUser(0,1.01*max); } drawHist(numExp, expHists, numMC, mcHists); delete[] expHists; delete[] mcHists; }
void MainWindow::on_actionOtsu_global_triggered() { QPixmap pixmap = pixmapItem->pixmap().copy(); QImage image = pixmap.toImage(); int width = image.width(); int height = image.height(); if (width == 0 || height == 0) { ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 ); return; } std::vector<int> grays(width * height, 0); int finalThreshold = otsu(image, grays, 0, 0, width, height); QRgb black = qRgb(0,0,0); QRgb white = qRgb(255,255,255); QRgb newColor; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { int gray = grays[x + y * width]; if ( gray < finalThreshold ) newColor = black; else newColor = white; image.setPixel(x, y, newColor); } pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }
void MainWindow::on_actionHistogram_equalization_triggered() { QPixmap pixmap = pixmapItem->pixmap().copy(); QImage image = pixmap.toImage(); int width = image.width(); int height = image.height(); if (width == 0 || height == 0) { ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 ); return; } DialogHistogramEqualization dialog; if (dialog.exec() == QDialog::Rejected) return; int equalizationType = dialog.getEqualizationType(); if (equalizationType == 1) RGB_equalization(image); else if (equalizationType == 2) V_equalization(image); else if (equalizationType == 3) Grayscale_equalization(image); pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }
void MainWindow::on_actionBrightness_gradient_triggered() { QPixmap pixmap = pixmapItem->pixmap().copy(); QImage image = pixmap.toImage(); int width = image.width(); int height = image.height(); if (width == 0 || height == 0) { ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 ); return; } std::vector< std::vector<int> > grays( width, std::vector<int>(height) ); for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { QRgb oldColor = image.pixel(x, y); int gray = qPow( 0.2126 * qPow(qRed(oldColor), 2.2) + 0.7152 * qPow(qGreen(oldColor), 2.2) + 0.0722 * qPow(qBlue(oldColor), 2.2), 1/2.2 ); grays[x][y] = gray; } int G_x; int G_y; int G; unsigned long int dividend = 0; unsigned int divisor = 0; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { if (x == 0) G_x = grays[x+1][y]; else if (x == width - 1) G_x = grays[x-1][y]; else G_x = grays[x+1][y] - grays[x-1][y]; if (y == 0) G_y = grays[x][y+1]; else if (y == height - 1) G_y = grays[x][y-1]; else G_y = grays[x][y+1] - grays[x][y-1]; G = qMax( qAbs(G_x), qAbs(G_y) ); dividend += grays[x][y] * G; divisor += G; } int threshold = dividend / divisor; if (0 <= threshold && threshold <= 255) { QRgb black = qRgb(0,0,0); QRgb white = qRgb(255,255,255); QRgb newColor; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { int gray = grays[x][y]; if ( gray < threshold ) newColor = black; else newColor = white; image.setPixel(x, y, newColor); } } else ui->statusBar->showMessage(tr("Error. Invalid threshold"), 3000); pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }
int main() { cv::VideoCapture camera(0); assert( camera.isOpened() ); cv::CascadeClassifier faceCascade; assert( faceCascade.load("haarcascades/haarcascade_frontalface_alt.xml") ); cv::CascadeClassifier eyeCascade; assert( eyeCascade.load("haarcascades/haarcascade_mcs_eyepair_big.xml") ); cv::Mat frame, image, faceImage, eyeImage, rightEyeImage, leftEyeImage; cv::namedWindow( WINDOW_NAME, 1 ); std::vector<cv::Rect> objects; IntVec vHist, hHist, rightHorizHist, rightVertHist, leftHorizHist, leftVertHist; cv::Rect faceRect, eyeRect, leftEye, rightEye; float faceModX, faceModY, eyeModX, eyeModY; int eyeCut; camera >> frame; faceModX = frame.cols / FACE_SEARCH_WIDTH; faceModY = frame.rows / FACE_SEARCH_HEIGHT; do { camera >> frame; cv::resize(frame, image, cv::Size(FACE_SEARCH_WIDTH, FACE_SEARCH_HEIGHT)); faceCascade.detectMultiScale(image, objects); if ( objects.size() ) { faceRect = objects[0]; faceRect.x *= faceModX; faceRect.y *= faceModY; faceRect.height *= faceModY; faceRect.width *= faceModX; cv::rectangle(frame, faceRect, CV_RGB(255, 0, 0)); rectSubImg(frame, faceImage, faceRect); cv::resize(faceImage, faceImage, cv::Size(faceRect.width / 2, faceRect.height / 2)); eyeCascade.detectMultiScale(faceImage, objects); if ( objects.size() ) { eyeRect = objects[0]; eyeRect.x *= 2; eyeRect.y *= 2; eyeRect.height *= 2; eyeRect.width *= 2; eyeRect.x += faceRect.x; eyeRect.y += faceRect.y; splitEyeRect(eyeRect, leftEye, rightEye); cv::rectangle(frame, leftEye, CV_RGB(255, 255, 0)); cv::rectangle(frame, rightEye, CV_RGB(255, 255, 0)); rectSubImg(frame, rightEyeImage, rightEye); rectSubImg(frame, leftEyeImage, leftEye); imgHist(rightEyeImage, rightHorizHist, rightVertHist); imgHist(leftEyeImage, leftHorizHist, leftVertHist); smoothHist(rightHorizHist, 50); smoothHist(rightVertHist, 50); smoothHist(leftHorizHist, 50); smoothHist(leftVertHist, 50); drawHist(frame, rightHorizHist, cv::Point(rightEye.x, rightEye.y), RIGHT, UP, 50); drawHist(frame, rightVertHist, cv::Point(rightEye.x + rightEye.width, rightEye.y), DOWN, RIGHT, 50); drawHist(frame, leftHorizHist, cv::Point(leftEye.x, leftEye.y), RIGHT, UP, 50); drawHist(frame, leftVertHist, cv::Point(leftEye.x, leftEye.y), DOWN, LEFT, 50); //FIXME move to functions for(int i = 1; i < rightHorizHist.size() - 1; i ++) { if (rightHorizHist[i] <= rightHorizHist[i-1] && rightHorizHist[i] <= rightHorizHist[i+1]) { cv::line(frame, cv::Point(rightEye.x + i, rightEye.y), cv::Point(rightEye.x + i, rightEye.y + rightEye.height), CV_RGB(255, 0, 0)); } } for(int i = 1; i < leftHorizHist.size() - 1; i ++) { if (leftHorizHist[i] <= leftHorizHist[i-1] && leftHorizHist[i] <= leftHorizHist[i+1]) { cv::line(frame, cv::Point(leftEye.x + i, leftEye.y), cv::Point(leftEye.x + i, leftEye.y + leftEye.height), CV_RGB(255, 0, 0)); } } for(int i = 1; i < rightVertHist.size() - 1; i ++) { if (rightVertHist[i] <= rightVertHist[i-1] && rightVertHist[i] <= rightVertHist[i+1]) { cv::line(frame, cv::Point(rightEye.x, rightEye.y + i), cv::Point(rightEye.x + rightEye.width, rightEye.y + i), CV_RGB(255, 0, 0)); } } for(int i = 1; i < leftVertHist.size() - 1; i ++) { if (leftVertHist[i] <= leftVertHist[i-1] && leftVertHist[i] <= leftVertHist[i+1]) { cv::line(frame, cv::Point(leftEye.x, leftEye.y + i), cv::Point(leftEye.x + leftEye.width, leftEye.y + i), CV_RGB(255, 0, 0)); } } } } cv::imshow( WINDOW_NAME, frame); } while (cv::waitKey(10) != 27); return 0; }
void MainWindow::on_actionLinear_triggered() { QPixmap pixmap = pixmapItem->pixmap().copy(); QImage image = pixmap.toImage(); int width = image.width(); int height = image.height(); if (width == 0 || height == 0) { ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 ); return; } int minR = 256; int maxR = -1; int minG = 256; int maxG = -1; int minB = 256; int maxB = -1; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { QRgb oldColor = image.pixel(x, y); int red = qRed(oldColor); int green = qGreen(oldColor); int blue = qBlue(oldColor); if (red < minR) minR = red; if (red > maxR) maxR = red; if (green < minG) minG = green; if (green > maxG) maxG = green; if (blue < minB) minB = blue; if (blue > maxB) maxB = blue; } for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { QRgb oldColor = image.pixel(x, y); int red = ( qRed(oldColor) - minR) * 255 / (maxR - minR); int green = ( qGreen(oldColor) - minG) * 255 / (maxG - minG); int blue = ( qBlue(oldColor) - minB) * 255 / (maxB - minB); if (red < 0) red = 0; if (red > 255) red = 255; if (green < 0) green = 0; if (green > 255) green = 255; if (blue < 0) blue = 0; if (blue > 255) blue = 255; image.setPixel(x, y, qRgb(red, green, blue)); } pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }
void MainWindow::on_actionGamma_correction_triggered() { QPixmap pixmap = pixmapItem->pixmap().copy(); QImage image = pixmap.toImage(); int width = image.width(); int height = image.height(); if (width == 0 || height == 0) { ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 ); return; } DialogGammaCorrection dialog; if (dialog.exec() == QDialog::Rejected) return; int maxR = -1; int maxG = -1; int maxB = -1; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { QRgb oldColor = image.pixel(x, y); int red = qRed(oldColor); int green = qGreen(oldColor); int blue = qBlue(oldColor); if (red > maxR) maxR = red; if (green > maxG) maxG = green; if (blue > maxB) maxB = blue; } double gamma = dialog.getGamma(); double cR = 255 / qPow(maxR, gamma); double cG = 255 / qPow(maxG, gamma); double cB = 255 / qPow(maxB, gamma); for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { QRgb oldColor = image.pixel(x, y); int red = cR * qPow(qRed(oldColor), gamma); int green = cG * qPow(qGreen(oldColor), gamma); int blue = cB * qPow(qBlue(oldColor), gamma); if (red < 0) red = 0; if (red > 255) red = 255; if (green < 0) green = 0; if (green > 255) green = 255; if (blue < 0) blue = 0; if (blue > 255) blue = 255; image.setPixel(x, y, qRgb(red, green, blue)); } pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }
void MainWindow::on_actionPiecewise_linear_triggered() { QPixmap pixmap = pixmapItem->pixmap().copy(); QImage image = pixmap.toImage(); int width = image.width(); int height = image.height(); if (width == 0 || height == 0) { ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 ); return; } DialogPiecewiseLinear dialog; dialog.setText(pieceWiseLinearText); if (dialog.exec() == QDialog::Rejected) return; std::vector<double> nums = dialog.getNums(); pieceWiseLinearText = dialog.getString(); bool normalize = dialog.isNormalize(); std::vector<double> csR(nums.size() / 4); std::vector<double> csG(nums.size() / 4); std::vector<double> csB(nums.size() / 4); if (normalize) { int maxR = -1; int maxG = -1; int maxB = -1; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { QRgb oldColor = image.pixel(x, y); int red = qRed(oldColor); int green = qGreen(oldColor); int blue = qBlue(oldColor); if (red > maxR) maxR = red; if (green > maxG) maxG = green; if (blue > maxB) maxB = blue; } for (unsigned int i = 0; i < nums.size(); i += 4) { csR[i/4] = 255 / (nums[i] * maxR + nums[i+1]); csG[i/4] = 255 / (nums[i] * maxG + nums[i+1]); csB[i/4] = 255 / (nums[i] * maxB + nums[i+1]); } } for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { QRgb oldColor = image.pixel(x, y); int red = qRed(oldColor); int green = qGreen(oldColor); int blue = qBlue(oldColor); double cR = 1.0; double cG = 1.0; double cB = 1.0; for (unsigned int i = 0; i < nums.size(); i += 4) { double k = nums[i]; double b = nums[i+1]; int left = qFloor(nums[i+2]); int right = qFloor(nums[i+3]); if (left <= red && red <= right) { if (normalize) cR = csR[i/4]; red = cR * (k * red + b); if (red < 0) red = 0; if (red > 255) red = 255; } if (left <= green && green <= right) { if (normalize) cG = csG[i/4]; green = cG * (k * green + b); if (green < 0) green = 0; if (green > 255) green = 255; } if (left <= blue && blue <= right) { if (normalize) cB = csB[i/4]; blue = cB * (k * blue + b); if (blue < 0) blue = 0; if (blue > 255) blue = 255; } } image.setPixel(x, y, qRgb(red, green, blue)); } pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }
void MainWindow::on_actionGray_world_triggered() { QPixmap pixmap = pixmapItem->pixmap().copy(); QImage image = pixmap.toImage(); int width = image.width(); int height = image.height(); if (width == 0 || height == 0) { ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 ); return; } double avgRed = 0.0; double avgGreen = 0.0; double avgBlue = 0.0; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { QRgb oldColor = image.pixel(x, y); avgRed += qRed(oldColor); avgGreen += qGreen(oldColor); avgBlue += qBlue(oldColor); } int length = width * height; avgRed /= length; avgGreen /= length; avgBlue /= length; double avg = (avgRed + avgGreen + avgBlue) / 3; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { QRgb oldColor = image.pixel(x, y); double red = qRed(oldColor) * avg / avgRed; double green = qGreen(oldColor) * avg / avgGreen; double blue = qBlue(oldColor) * avg / avgBlue; if (red < 0) red = 0; if (red > 255) red = 255; if (green < 0) green = 0; if (green > 255) green = 255; if (blue < 0) blue = 0; if (blue > 255) blue = 255; image.setPixel(x, y, qRgb(red, green, blue)); } pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }
void MainWindow::on_actionBrightness_quantization_triggered() { QPixmap pixmap = pixmapItem->pixmap().copy(); QImage image = pixmap.toImage(); int width = image.width(); int height = image.height(); if (width == 0 || height == 0) { ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 ); return; } std::vector<int> grays(width * height); for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { QRgb oldColor = image.pixel(x, y); int gray = qPow( 0.2126 * qPow(qRed(oldColor), 2.2) + 0.7152 * qPow(qGreen(oldColor), 2.2) + 0.0722 * qPow(qBlue(oldColor), 2.2), 1/2.2 ); grays[x + y * width] = gray; } std::vector<unsigned int> Rs(256, 0); std::vector<unsigned int> Gs(256, 0); std::vector<unsigned int> Bs(256, 0); std::vector<int> hist(256, 0); for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { int num = grays[x + y * width]; Rs[num] += qRed( image.pixel(x, y) ); Gs[num] += qGreen( image.pixel(x, y) ); Bs[num] += qBlue( image.pixel(x, y) ); ++hist[num]; } int quantsCountMaximum = 0; std::map<int, QRgb> colors; for (int i = 0; i < 256; ++i) { if (hist[i] == 0) continue; Rs[i] /= hist[i]; Gs[i] /= hist[i]; Bs[i] /= hist[i]; colors[i] = qRgb(Rs[i], Gs[i], Bs[i]); ++quantsCountMaximum; } DialogQuantization dialog; dialog.setQuantCountMaximum(quantsCountMaximum); if (dialog.exec() == QDialog::Rejected) return; int quantsCount = dialog.quantsCount(); double shift = 256 / quantsCount; double cur = 0.0; double next = 0.0; for (int i = 0; i < quantsCount; ++i) { next += shift; int c = qFloor(cur); int n = qFloor(next); int minC = 256; for (std::map<int, QRgb>::iterator it = colors.begin(); it != colors.end(); ++it) if (c <= (it->first) && (it->first) < n) if (it->first < minC) minC = it->first; QRgb newColor = colors[minC]; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { int num = grays[x + y * width]; if (c <= num && num < n) image.setPixel(x, y, newColor); else continue; } cur = next; } pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); //ui->graphicsView_2->fitInView(scene_2->itemsBoundingRect(), Qt::KeepAspectRatio); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }
void MainWindow::on_actionOtsu_local_triggered() { QPixmap pixmap = pixmapItem->pixmap().copy(); QImage image = pixmap.toImage(); int width = image.width(); int height = image.height(); if (width == 0 || height == 0) { ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 ); return; } DialogOtsuLocal dialog; dialog.setSpinBoxes(pixmapItem->pixmap().width(), pixmapItem->pixmap().height()); if (dialog.exec() == QDialog::Rejected) return; std::vector<int> grays(width * height, 0); int countX = dialog.gridX(); int countY = dialog.gridY(); double shiftY = ( (double) height ) / countY; double shiftX = ( (double) width ) / countX; double curX = 0.0; double curY = 0.0; double nextX = 0.0; double nextY = 0.0; int cX; int cY; int nX; int nY; QRgb black = qRgb(0,0,0); QRgb white = qRgb(255,255,255); QRgb newColor; for (int i = 0; i < countY; ++i) { nextY += shiftY; cY = qFloor(curY); nY = qFloor(nextY); curX = 0.0; nextX = 0.0; for (int j = 0; j < countX; ++j) { nextX += shiftX; cX = qFloor(curX); nX = qFloor(nextX); int threshold = otsu(image, grays, cX, cY, nX, nY); for (int y = cY; y < nY; ++y) for (int x = cX; x < nX; ++x) { int gray = grays[x + y * (nX - cX)]; if ( gray < threshold ) newColor = black; else newColor = white; image.setPixel(x, y, newColor); } curX = nextX; } curY = nextY; } pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }
void imhist(const std::string& winname, const cv::Mat img, int channel, const cv::Mat mask, bool uniform, bool accumulate) { cv::Mat hist = calcHistEx(img, channel, mask, uniform, accumulate); cv::Mat histImage = drawHist(hist); cv::imshow(winname, histImage); }
void RDK2AnalysisPlotter::drawPlotResid(CoDet detType, PlotVarType plotVarType,bool normalize) { gROOT->cd(); PlotType plotType; if(normalize) { plotType=PLOT_NORMRESID; } else { plotType=PLOT_RESID; } TString histName; TH1** expHists=new TH1*[numExp]; TH1** mcHists=new TH1*[numMC]; int start=plotHists.size(); //We will use these hists straight off for (int i = 0;i< numExp;i++) { histName="hist"+int2str(plotHists.size()); expHists[i]=(TH1*) (getExpHist( i, detType, plotVarType)->Clone(histName)); plotHists.push_back(expHists[i]); } for (int i = 0;i< numMC;i++) { histName="hist"+int2str(plotHists.size()); mcHists[i]=(TH1*) (getMCHist( i, detType, plotVarType)->Clone(histName)); plotHists.push_back(mcHists[i]); if(detType==DET_EP && numExp>0)//Scale MC hists to first Exp Integral { scaleHistogramsTogether(expHists[0],mcHists[i],1,expHists[0]->GetNbinsX()); } } double origMax=0; for (int i = start;i< start+numExp+numMC;i++) { if(plotHists[i]->GetMaximum() >origMax) origMax=plotHists[i]->GetMaximum(); } for (int i = 0;i< numExp;i++) { setDisplayQuantitiesForHist(i,origMax,expHists[i],detType,plotType,plotVarType); } for (int i = 0;i< numMC;i++) { setDisplayQuantitiesForHist(-i-1,origMax,mcHists[i],detType,plotType,plotVarType); } TH1** residHists; double max=-REALLY_BIG_DBL; double min=REALLY_BIG_DBL; double check; if(numExp==1) { ///Multiple MC residHists=new TH1*[numMC]; for (int i = 0;i< numMC;i++) { histName="hist"+int2str(plotHists.size()); residHists[i]=(TH1*) mcHists[i]->Clone(histName); plotHists.push_back(residHists[i]); residHists[i]->Reset(); residHists[i]->Add(expHists[0],mcHists[i],1,-1); if(normalize) { residHists[i]->Divide(mcHists[i]); } check=GetIdealMaxForPlotting(residHists[i]); if(check > max) max=check; check=GetIdealMinForPlotting(residHists[i]); if(check < min) min=check; } if(normalize) { residHists[0]->GetYaxis()->SetTitle("Normalized Residual"); residHists[0]->SetTitle(TString(plotHists[start]->GetTitle())+" Residuals #frac{Exp - MC}{MC}"); if(detType==DET_EP) { residHists[0]->GetYaxis()->SetRangeUser(-.4,.4); } else { residHists[0]->GetYaxis()->SetRangeUser(-.5,.5); } } else { residHists[0]->SetTitle(TString(plotHists[start]->GetTitle())+" Residuals Exp - MC"); } residHists[0]->GetYaxis()->SetRangeUser(min,max); drawHist(numMC, residHists, 0, nullptr); } else { ///Multiple Exp residHists=new TH1*[numExp]; for (int i = 0;i< numExp;i++) { histName="hist"+int2str(plotHists.size()); residHists[i]=(TH1*) expHists[i]->Clone(histName); plotHists.push_back(residHists[i]); residHists[i]->Reset(); residHists[i]->Add(expHists[i],mcHists[0],1,-1); if(normalize) { residHists[i]->Divide(mcHists[0]); } check=GetIdealMaxForPlotting(residHists[i]); if(check > max) max=check; check=GetIdealMinForPlotting(residHists[i]); if(check < min) min=check; } if(normalize) { residHists[0]->SetTitle(TString(plotHists[start]->GetTitle())+" Residuals #frac{Exp - MC}{MC}"); residHists[0]->GetYaxis()->SetTitle("Normalized Residual"); if(detType==DET_EP) { residHists[0]->GetYaxis()->SetRangeUser(-.4,.4); } else { residHists[0]->GetYaxis()->SetRangeUser(-.5,.5); } } else { residHists[0]->SetTitle(TString(plotHists[start]->GetTitle())+" Residuals Exp - MC"); } residHists[0]->GetYaxis()->SetRangeUser(min,max); drawHist(numExp, residHists, 0, nullptr); } delete[] residHists; delete[] expHists; delete[] mcHists; }
void MainWindow::on_actionZoom_triggered() { QPixmap oldPixmap = pixmapItem->pixmap(); QImage oldImage = oldPixmap.toImage(); int oldWidth = oldImage.width(); int oldHeight = oldImage.height(); if (oldWidth == 0 || oldHeight == 0) { ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 ); return; } DialogZoom dialog; if (dialog.exec() == QDialog::Rejected) return; double value = dialog.getValue(); int choice = dialog.getChoice(); int width = oldWidth * value; int height = oldHeight * value; QImage image(width, height, QImage::Format_ARGB32); image.fill( QColor(255, 255, 255) ); if (choice == 1) { for (int i = 0; i < width; ++i) for (int j = 0; j < height; ++j) { int srcX = i / value; int srcY = j / value; image.setPixel(i, j, oldImage.pixel(srcX, srcY)); } } else if (choice == 2) { int h, w; double t; double u; double tmp; double d1, d2, d3, d4; QRgb p1, p2, p3, p4; int red, green, blue; for (int j = 0; j < height; ++j) { tmp = j / (double) (height - 1) * (oldHeight - 1); h = qFloor(tmp); h = h < 0? 0: (h >= oldHeight - 1? oldHeight - 2: h); u = tmp - h; for (int i = 0; i < width; ++i) { tmp = i / (double) (width - 1) * (oldWidth - 1); w = qFloor(tmp); w = w < 0? 0: (w >= oldWidth - 1? oldWidth - 2: w); t = tmp - w; d1 = (1 - t) * (1 - u); d2 = t * (1 - u); d3 = t * u; d4 = (1 - t) * u; p1 = oldImage.pixel(w, h); p2 = oldImage.pixel(w + 1, h); p3 = oldImage.pixel(w + 1, h + 1); p4 = oldImage.pixel(w, h + 1); red = (int)(qRed(p1) * d1) + (int)(qRed(p2) * d2) + (int)(qRed(p3) * d3) + (int)(qRed(p4) * d4); blue = (int)(qBlue(p1) * d1) + (int)(qBlue(p2) * d2) + (int)(qBlue(p3) * d3) + (int)(qBlue(p4) * d4); green = (int)(qGreen(p1) * d1) + (int)(qGreen(p2) * d2) + (int)(qGreen(p3) * d3) + (int)(qGreen(p4) * d4); image.setPixel(i, j, qRgb(red, green, blue)); } } } else if (choice == 3) { int scale = qCeil(value); for (int j = scale; j < height - 2 * value; ++j) { // int h = qFloor(j / value); // h = h < 0? 0: (h >= oldHeight - 1? oldHeight - 2: h); for (int i = scale; i < width - 2 * value; ++i) { // int w = qFloor(i / value); // w = w < 0? 0: (w >= oldWidth - 1? oldWidth - 2: w); int srcX = qFloor(i / value); int srcY = qFloor(j / value); double relativeX = (i / value) - qFloor((i / value)); double relativeY = (j / value) - qFloor((j / value)); QRgb p00 = oldImage.pixel(srcX - 1, srcY - 1); QRgb p10 = oldImage.pixel(srcX, srcY - 1); QRgb p20 = oldImage.pixel(srcX + 1, srcY - 1); QRgb p30 = oldImage.pixel(srcX + 2, srcY - 1); QRgb p01 = oldImage.pixel(srcX - 1, srcY); QRgb p11 = oldImage.pixel(srcX, srcY); QRgb p21 = oldImage.pixel(srcX + 1, srcY); QRgb p31 = oldImage.pixel(srcX + 2, srcY); QRgb p02 = oldImage.pixel(srcX - 1, srcY + 1); QRgb p12 = oldImage.pixel(srcX, srcY + 1); QRgb p22 = oldImage.pixel(srcX + 1, srcY + 1); QRgb p32 = oldImage.pixel(srcX + 2, srcY + 1); QRgb p03 = oldImage.pixel(srcX - 1, srcY + 2); QRgb p13 = oldImage.pixel(srcX, srcY + 2); QRgb p23 = oldImage.pixel(srcX + 1, srcY + 2); QRgb p33 = oldImage.pixel(srcX + 2, srcY + 2); double r0 = CubicInterpolation( relativeX, qRed(p00), qRed(p10), qRed(p20), qRed(p30) ); double r1 = CubicInterpolation( relativeX, qRed(p01), qRed(p11), qRed(p21), qRed(p31) ); double r2 = CubicInterpolation( relativeX, qRed(p02), qRed(p12), qRed(p22), qRed(p32) ); double r3 = CubicInterpolation( relativeX, qRed(p03), qRed(p13), qRed(p23), qRed(p33) ); int r = qMax(0.0, qMin(255.0, CubicInterpolation(relativeY, r0, r1, r2, r3))); double g0 = CubicInterpolation( relativeX, qGreen(p00), qGreen(p10), qGreen(p20), qGreen(p30) ); double g1 = CubicInterpolation( relativeX, qGreen(p01), qGreen(p11), qGreen(p21), qGreen(p31) ); double g2 = CubicInterpolation( relativeX, qGreen(p02), qGreen(p12), qGreen(p22), qGreen(p32) ); double g3 = CubicInterpolation( relativeX, qGreen(p03), qGreen(p13), qGreen(p23), qGreen(p33) ); int g = qMax(0.0, qMin(255.0, CubicInterpolation(relativeY, g0, g1, g2, g3))); double b0 = CubicInterpolation( relativeX, qBlue(p00), qBlue(p10), qBlue(p20), qBlue(p30) ); double b1 = CubicInterpolation( relativeX, qBlue(p01), qBlue(p11), qBlue(p21), qBlue(p31) ); double b2 = CubicInterpolation( relativeX, qBlue(p02), qBlue(p12), qBlue(p22), qBlue(p32) ); double b3 = CubicInterpolation( relativeX, qBlue(p03), qBlue(p13), qBlue(p23), qBlue(p33) ); int b = qMax(0.0, qMin(255.0, CubicInterpolation(relativeY, b0, b1, b2, b3))); image.setPixel(i, j, qRgb(r, g, b)); } } } QPixmap pixmap; pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }
void RDK2AnalysisPlotter::drawPlotDets(CoDet detType, PlotVarType plotVarType) { gROOT->cd(); int numDets; TString histTitleString; if(detType == DET_EPG) { numDets=12; histTitleString="Individual BGO Detectors;Detector Number;% Difference From Mean"; } else { numDets=3; histTitleString="Individual BAPD Detectors;Detector Number;% Difference From Mean"; } const int numHists=numExp+numMC; TH1* tempHist; double integral; double error; TH1** detsHists=new TH1*[numHists]; TString histName; double max=-REALLY_BIG_DBL; double min=REALLY_BIG_DBL; for (int i = 0;i< numHists;i++) //Set loop (either exp or mc) { histName="hist"+int2str(plotHists.size()); detsHists[i]=new TH1D(histName,histTitleString,numDets,.5,numDets+.5); detsHists[i]->Sumw2(); plotHists.push_back(detsHists[i]); for (int j = 0;j< numDets;j++) { if(i<numExp) { tempHist=getExpHist( i, detType, plotVarType,j+1); } else { tempHist=getMCHist( i-numExp, detType, plotVarType,j+1); } if(tempHist != nullptr) { integral = tempHist->IntegralAndError(1,tempHist->GetNbinsX(),error); detsHists[i]->SetBinContent(j+1,integral); detsHists[i]->SetBinError(j+1,error); } } if(i<numExp) setDisplayQuantitiesForHist(i,1,detsHists[i],detType,PLOT_DETS,plotVarType); else setDisplayQuantitiesForHist(-(i-numExp)-1,1,detsHists[i],detType,PLOT_DETS,plotVarType); double mean=detsHists[i]->Integral()/numDets; // Mean for the set detsHists[i]->Scale(100./mean); for (int j = 0;j< numDets;j++) { detsHists[i]->SetBinContent(j+1,detsHists[i]->GetBinContent(j+1)-100. ); } if(detsHists[i]->GetMaximum() > max) max=detsHists[i]->GetMaximum()+detsHists[i]->GetBinError(detsHists[i]->GetMaximumBin()); if(detsHists[i]->GetMinimum() < min) min=detsHists[i]->GetMinimum()-detsHists[i]->GetBinError(detsHists[i]->GetMinimumBin()); } detsHists[0]->GetYaxis()->SetRangeUser(min-.05*abs(min),max+.05*abs(max)); drawHist(numHists, detsHists, 0, nullptr); delete[] detsHists; }
RImageDock::RImageDock(OGLWidget* newOGLWidget, QWidget *parent) :QWidget(parent) { widgetTitle = QString(""); frameIndex = 0; this->oglWidget = newOGLWidget; matImage = newOGLWidget->matImageListRGB.at(frameIndex); naxis1 = matImage.cols; naxis2 = matImage.rows; bscale = newOGLWidget->rMatImageList.at(0).getBscale(); qDebug() << "RImageDock::matImage.channels()" << matImage.channels(); // Convert to gray before getting the Max and Min cvtColor(matImage, matImageGray, CV_RGB2GRAY); dataMin = 0; dataMax = 0; cv::minMaxLoc(matImageGray, &dataMin, &dataMax); dataRange = dataMax - dataMin; qDebug() << "rImageDock::dataMin =" << dataMin; qDebug() << "rImageDock::dataMax =" << dataMax; gamma = 1; // String number format parameters if (dataRange < 0.1) { format = 'g'; precision = 2; } else if (dataRange < 10) { format = 'f'; precision = 3; } else { format = 'f'; precision = 0; } newMin = dataMin; newMax = dataMax; // Set the slider steps // We need to differiente between scientific calibrated data values and // uncalibrated, unphysical values scaled only within [0-65535] // We know this from the bscale values. // We deal typically with uncalibrated 8 bits [0-256], 16 bits [0=65535] // or calibrated 32 bits data, whose unit will depend on bscale. // if bscale = 1, we stick to a 16 bits range. This includes the 8-bits case (maybe this will change) colorRange = 65536.0f; sliderMin = 1; sliderMax = sliderMin + colorRange -1; if (bscale == 1) { sliderScaleStep = 1.0f; qDebug() << "rImageDock:: sliderScaleStep =" << sliderScaleStep; // Set initial constrast stretching factors alpha = 1.0f / colorRange; beta = 0.0f; } else // Stretch the data into their physical range at 16-bits precision. { sliderScaleStep = dataRange/colorRange; // Set initial constrast stretching factors alpha = (float) (1.0f / dataRange); beta = (float) (-newMin / dataRange); } oglWidget->setAlpha(alpha); oglWidget->setBeta(beta); // Create the Sliders and Layout of the dock widget. //QLabels setup QLabel *labelHigh = new QLabel("High"); QLabel *labelLow = new QLabel("Low"); QLabel *labelGamma = new QLabel("Gamma"); //QSliders setup sliderHigh = new QSlider(Qt::Horizontal); sliderLow = new QSlider(Qt::Horizontal); sliderGamma = new QSlider(Qt::Horizontal); float gammaRange = 40; maxGamma = 2.1; minGamma = 0.1; sliderGammaStep = (maxGamma - minGamma)/gammaRange; // set sliders range sliderHigh->setRange((int)sliderMin, (int)sliderMax); sliderHigh->setSingleStep(1); sliderLow->setRange((int)sliderMin, (int)sliderMax); sliderLow->setSingleStep(1); sliderGamma->setRange(1, (int) gammaRange); sliderLow->setSingleStep(1); // set sliders value sliderHigh->setValue(sliderMax); sliderLow->setValue(sliderMin); sliderGamma->setValue(convertGammaToSlider(QString::number(gamma))); //QLineEdit setup valueHighLineEdit = new QLineEdit(QString::number(dataMax, format, precision)); valueLowLineEdit = new QLineEdit(QString::number(dataMin, format, precision)); valueGammaLineEdit = new QLineEdit(QString::number(gamma)); int editMinimumWidth = 20; int editMaximumWidth = 60; valueHighLineEdit->setMinimumWidth(editMinimumWidth); valueHighLineEdit->setMaximumWidth(editMaximumWidth); valueLowLineEdit->setMinimumWidth(editMinimumWidth); valueLowLineEdit->setMaximumWidth(editMaximumWidth); valueGammaLineEdit->setMinimumWidth(editMinimumWidth); valueGammaLineEdit->setMaximumWidth(editMaximumWidth); // QGridLayout setup QGridLayout *sliderLayout = new QGridLayout(); // Add the labels sliderLayout->addWidget(labelHigh, 0, 0); sliderLayout->addWidget(labelLow, 1, 0); sliderLayout->addWidget(labelGamma, 2, 0); // Add the sliders sliderLayout->addWidget(sliderHigh, 0, 1); sliderLayout->addWidget(sliderLow, 1, 1); sliderLayout->addWidget(sliderGamma, 2, 1); // Add the line edits. sliderLayout->addWidget(valueHighLineEdit, 0, 2); sliderLayout->addWidget(valueLowLineEdit, 1, 2); sliderLayout->addWidget(valueGammaLineEdit, 2, 2); // Define the minimum spacing between sliders. This may need some adjusting. int vSpacing = 0; int hSpacing = 10; //QMargins margins(10, 10, 5, 5); //sliderLayout->setContentsMargins(margins); sliderLayout->setVerticalSpacing(vSpacing); sliderLayout->setHorizontalSpacing(hSpacing); // Set the minimum column widths of the layout, int sliderWidth = 350; int lineEditWidth = 20; sliderLayout->setColumnMinimumWidth(1, sliderWidth); sliderLayout->setColumnMinimumWidth(2, lineEditWidth); sliderLayout->setMargin(0); QWidget *sliderWidget = new QWidget(); sliderWidget->setLayout(sliderLayout); sliderWidget->setMinimumHeight(60); // Calibration type QWidget *calibrationTypeWidget = new QWidget(); light = new QCheckBox(QString("Light")); bias = new QCheckBox(QString("Bias")); dark = new QCheckBox(QString("Dark")); flat = new QCheckBox(QString("Flat")); // Histrogram button QPushButton *histButton = new QPushButton("Histogram"); QGridLayout *grid = new QGridLayout(); grid->addWidget(light,0,0); grid->addWidget(bias,0,1); grid->addWidget(dark,1,0); grid->addWidget(flat,1,1); grid->addWidget(histButton, 2, 0, 1, 2); grid->setMargin(0); calibrationTypeWidget->setLayout(grid); calibrationTypeWidget->setMinimumHeight(60); QHBoxLayout *hBox = new QHBoxLayout(); hBox->addWidget(sliderWidget); hBox->addWidget(calibrationTypeWidget); // Set the above layout in this QWidget setLayout(hBox); setMinimumWidth(600); //setMaximumWidth(800); setMaximumHeight(80); // Connect the change of the slider position with the QLineEdit QObject::connect(sliderHigh, SIGNAL(valueChanged(int)), this, SLOT(updateQLineEditSlot(int))); QObject::connect(sliderLow, SIGNAL(valueChanged(int)), this, SLOT(updateQLineEditSlot(int))); QObject::connect(sliderGamma, SIGNAL(valueChanged(int)), this, SLOT(updateQLineEditSlot(int))); QObject::connect(valueHighLineEdit, SIGNAL( returnPressed()), this, SLOT(setSliderValueSlot())); QObject::connect(valueLowLineEdit, SIGNAL( returnPressed()), this, SLOT(setSliderValueSlot())); QObject::connect(valueGammaLineEdit, SIGNAL( returnPressed()), this, SLOT(setSliderValueSlot())); //Connect the slider value changed with the Image display. QObject::connect(sliderHigh, SIGNAL(valueChanged(int)), this, SLOT(scaleImageSlot(int))); QObject::connect(sliderLow, SIGNAL(valueChanged(int)), this, SLOT(scaleImageSlot(int))); QObject::connect(sliderGamma, SIGNAL(valueChanged(int)), this, SLOT(gammaScaleImageSlot(int))); QObject::connect(histButton, SIGNAL(released()), this, SLOT(drawHist())); // Connect mouse events with OGLWidget QObject::connect(newOGLWidget, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater())); qRegisterMetaType<QVector<int> >("QVector<int>"); qRegisterMetaType<QVector<QString> >("QVector<QString>"); // Get initial tatistics calcStats(); autoScale(); }