示例#1
0
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);
}
示例#2
0
void MainWindow::BlackWhiteImage()
{
    BlackWhiteImage(&outImage);

    DrawDisplayImage();
}
示例#3
0
void MainWindow::FindPeaksImage(QImage *image, double thres)
{
    // First compute edge magnitude and orientation for the image with sobel operator

    int r, c, rd, cd;

    QRgb pixel;

    // Graytones first
    BlackWhiteImage(image);

    QImage buffer;

    // store pixel magnitude
    QImage magnitude = image->copy();

    // store pixel orientation
    QImage orientation = image->copy();

    int w = image->width();
    int h = image->height();

    double gx[9] = {1, 0, -1, 2, 0, -2, 1, 0, -1};
    double gy[9] = {-1, -2, -1, 0, 0, 0, 1, 2, 1};

    buffer = image->copy(-1, -1, w + 2, h + 2);

    for(r = 0; r < h; r++) {
        for(c = 0; c < w; c++) {
            double magX = 0.0;
            double magY = 0.0;

            for(rd = -1; rd <= 1; rd++) {
                for(cd = -1; cd <= 1; cd++) {
                    pixel = buffer.pixel(c + cd + 1, r + rd + 1);

                    // Get the value of the kernel
                    double weightX = gx[(rd + 1) * 3 + cd + 1];
                    double weightY = gy[(rd + 1) * 3 + cd + 1];

                    magX += weightX * (double) qRed(pixel);
                    magY += weightY * (double) qRed(pixel);
                }
            }

            magX /= 8.0;
            magY /= 8.0;

            double mag = sqrt(magX * magX + magY * magY); // magnitude
            magnitude.setPixel(c, r, qRgb(0, (int)mag, 0));

            double orien = atan2(magY, magX); // orientation

            double red = sin(orien);
            double green = cos(orien);

            orientation.setPixel(c, r, qRgb((int)red, (int)green, 0));

        }
    }

    pixel = qRgb(0, 0, 0);
    // zero out the image
    image->fill(pixel);


    // Compare edge magnitude
    for(r = 0; r < h; r++) {
        for(c = 0; c < w; c++) {
            pixel = magnitude.pixel(c, r);
            double mag0 = (double)qGreen(pixel);

            if(mag0 > thres) {
                pixel = orientation.pixel(c, r);
                double dsin = (double)qRed(pixel);
                double dcos = (double)qGreen(pixel);

                // pixel perpendicular
                double x1, y1;

                double e0[3];

                x1 = dcos + c;
                y1 = dsin + r;

                BilinearInterpolation(&magnitude, x1, y1, e0);

                // pixel perpendicular
                double x2, y2;

                double e1[3];

                x2 = -dcos + c;
                y2 = -dsin + r;

                BilinearInterpolation(&magnitude, x2, y2, e1);

                if(mag0 >= e0[1] && mag0 >= e1[1]) {
                    image->setPixel(c, r, qRgb(255, 255, 255));
                }

            }

        }
    }

}
示例#4
0
void MainWindow::SobelImage(QImage *image)
{
    // Graytones then convolve with kernel
    int r, c, rd, cd;

    QRgb pixel;

    // Graytones first
    BlackWhiteImage(image);

    QImage buffer;
    int w = image->width();
    int h = image->height();

    double gx[9] = {1, 0, -1, 2, 0, -2, 1, 0, -1};
    double gy[9] = {-1, -2, -1, 0, 0, 0, 1, 2, 1};

    buffer = image->copy(-1, -1, w + 2, h + 2);

    for(r = 0; r < h; r++) {
        for(c = 0; c < w; c++) {
            double magX = 0.0;
            double magY = 0.0;

            for(rd = -1; rd <= 1; rd++) {
                for(cd = -1; cd <= 1; cd++) {
                    pixel = buffer.pixel(c + cd + 1, r + rd + 1);

                    // Get the value of the kernel
                    double weightX = gx[(rd + 1) * 3 + cd + 1];
                    double weightY = gy[(rd + 1) * 3 + cd + 1];

                    magX += weightX * (double) qRed(pixel);
                    magY += weightY * (double) qRed(pixel);
                }
            }

            magX /= 8.0;
            magY /= 8.0;

            double mag = sqrt(magX * magX + magY * magY); // magnitude
            double orien = atan2(magY, magX); // orientation

            double red = (sin(orien) + 1.0) / 2.0;
            double green = (cos(orien) + 1.0) / 2.0;
            double blue = 1.0 - red - green;

            red *= mag * 4.0;
            green *= mag * 4.0;
            blue *= mag * 4.0;

            // Make sure the pixel values range from 0 to 255
            red = min(255.0, max(0.0, red));
            green = min(255.0, max(0.0, green));
            blue = min(255.0, max(0.0, blue));

            // Store convolved pixel in the image to be returned.
            image->setPixel(c, r, qRgb((int)red, (int)green, (int)blue));
        }
    }

}