MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); connect(ui->openButton, SIGNAL(clicked()), this, SLOT(OpenImage())); connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(SaveImage())); connect(ui->saveDisplayButton, SIGNAL(clicked()), this, SLOT(SaveDisplayImage())); connect(ui->resetButton, SIGNAL(clicked()), this, SLOT(ResetImage())); connect(ui->toggleButton, SIGNAL(pressed()), this, SLOT(ToggleImage())); connect(ui->toggleButton, SIGNAL(released()), this, SLOT(ToggleImage())); connect(ui->bwButton, SIGNAL(clicked()), this, SLOT(BlackWhiteImage())); connect(ui->noiseButton, SIGNAL(clicked()), this, SLOT(AddNoise())); connect(ui->meanButton, SIGNAL(clicked()), this, SLOT(MeanBlurImage())); connect(ui->medianButton, SIGNAL(clicked()), this, SLOT(MedianImage())); connect(ui->gaussianBlurButton, SIGNAL(clicked()), this, SLOT(GaussianBlurImage())); connect(ui->firstDerivButton, SIGNAL(clicked()), this, SLOT(FirstDerivImage())); connect(ui->secondDerivButton, SIGNAL(clicked()), this, SLOT(SecondDerivImage())); connect(ui->sharpenButton, SIGNAL(clicked()), this, SLOT(SharpenImage())); connect(ui->sobelButton, SIGNAL(clicked()), this, SLOT(SobelImage())); connect(ui->bilateralButton, SIGNAL(clicked()), this, SLOT(BilateralImage())); connect(ui->halfButton, SIGNAL(clicked()), this, SLOT(HalfImage())); connect(ui->rotateButton, SIGNAL(clicked()), this, SLOT(RotateImage())); connect(ui->peaksButton, SIGNAL(clicked()), this, SLOT(FindPeaksImage())); connect(ui->houghButton, SIGNAL(clicked()), this, SLOT(HoughImage())); connect(ui->crazyButton, SIGNAL(clicked()), this, SLOT(CrazyImage())); connect(ui->randomButton, SIGNAL(clicked()), this, SLOT(RandomSeedImage())); connect(ui->pixelButton, SIGNAL(clicked()), this, SLOT(PixelSeedImage())); connect(ui->histogramButton, SIGNAL(clicked()), this, SLOT(HistogramSeedImage())); connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(OpenImage())); connect(ui->zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(Zoom(int))); connect(ui->brightnessSlider, SIGNAL(valueChanged(int)), this, SLOT(Brightness(int))); connect(ui->verticalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(Scroll(int))); connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(Scroll(int))); ui->meanBox->setValue(2); ui->medianBox->setValue(2); ui->blurSpinBox->setValue(2.0); ui->firstDerivSpinBox->setValue(2.0); ui->secondDerivSpinBox->setValue(2.0); ui->sharpenSigmaSpinBox->setValue(2.0); ui->sharpenMagSpinBox->setValue(1.0); ui->bilateralSigmaSSpinBox->setValue(2.0); ui->bilateralSigmaISpinBox->setValue(20.0); ui->noiseSpinBox->setValue(10.0); ui->orientationSpinBox->setValue(10.0); ui->peakThresholdSpinBox->setValue(10.0); ui->colorNoiseCheckBox->setChecked(true); ui->zoomSlider->setValue(0); ui->brightnessSlider->setValue(0); ui->clusterBox->setValue(4); displayImage = QImage(ui->ImgDisplay->width(), ui->ImgDisplay->height(), QImage::Format_RGB32); }
void MainWindow::GaussianBlurImage() { double sigma = ui->blurSpinBox->value(); if(ui->separableCheckBox->isChecked()) SeparableGaussianBlurImage(&outImage, sigma); else GaussianBlurImage(&outImage, sigma); DrawDisplayImage(); }
void MainWindow::FirstDerivImage(QImage *image, double sigma) { // For image derivatives really is (pixel - next pixel) / 1 // [-1 0 1] is the filter int r, c; QRgb pixel; QImage buffer; int w = image->width(); int h = image->height(); // Copy image buffer = image->copy(-1, -1, w + 2, h + 2); for(r = 0; r < h; r++) { for(c = 0; c < w; c++) { // Calibrate for negative value double rgb[3] = {128, 128, 128}; pixel = buffer.pixel(c, r); rgb[0] -= (double) qRed(pixel); rgb[1] -= (double) qGreen(pixel); rgb[2] -= (double) qBlue(pixel); pixel = buffer.pixel(c + 2, r); rgb[0] += (double) qRed(pixel); rgb[1] += (double) qGreen(pixel); rgb[2] += (double) qBlue(pixel); // Adjust the rgb value rgb[0] = min(255.0, max(0.0, rgb[0])); rgb[1] = min(255.0, max(0.0, rgb[1])); rgb[2] = min(255.0, max(0.0, rgb[2])); // Store convolved pixel in the image to be returned. image->setPixel(c, r, qRgb((int) floor(rgb[0] + 0.5), (int) floor(rgb[1] + 0.5), (int) floor(rgb[2] + 0.5))); } } // Gaussian Blur GaussianBlurImage(image, sigma); }
void MainWindow::SecondDerivImage(QImage *image, double sigma) { // Again, derivative is really the difference // This time is all neighbors - center, [1 -2 1] is the 1d filter int r, c; QRgb pixel; QImage buffer; int w = image->width(); int h = image->height(); // Copy image buffer = image->copy(-1, -1, w + 2, h + 2); for(r = 0; r < h; r++) { for(c = 0; c < w; c++) { // Calibrate for negative value double rgb[3] = {128, 128, 128}; // Subtract itself pixel = buffer.pixel(c + 1, r + 1); rgb[0] -= 4 * (double) qRed(pixel); rgb[1] -= 4 * (double) qGreen(pixel); rgb[2] -= 4 * (double) qBlue(pixel); // Add neighbors pixel = buffer.pixel(c, r + 1); rgb[0] += (double) qRed(pixel); rgb[1] += (double) qGreen(pixel); rgb[2] += (double) qBlue(pixel); pixel = buffer.pixel(c + 2, r + 1); rgb[0] += (double) qRed(pixel); rgb[1] += (double) qGreen(pixel); rgb[2] += (double) qBlue(pixel); pixel = buffer.pixel(c + 1, r); rgb[0] += (double) qRed(pixel); rgb[1] += (double) qGreen(pixel); rgb[2] += (double) qBlue(pixel); pixel = buffer.pixel(c + 1, r + 2); rgb[0] += (double) qRed(pixel); rgb[1] += (double) qGreen(pixel); rgb[2] += (double) qBlue(pixel); // Adjust the rgb value rgb[0] = min(255.0, max(0.0, rgb[0])); rgb[1] = min(255.0, max(0.0, rgb[1])); rgb[2] = min(255.0, max(0.0, rgb[2])); // Store convolved pixel in the image to be returned. image->setPixel(c, r, qRgb((int) floor(rgb[0] + 0.5), (int) floor(rgb[1] + 0.5), (int) floor(rgb[2] + 0.5))); } } // Gaussian Blur GaussianBlurImage(image, sigma); }