/* Code from http://www.dewtell.com/code/cpp/sobel.htm Given image in source place Sobel edges in dest. Grayscale sort of, with (255,255,255) as brightest edge. sobelDestination should be same size and depth as source. */ QImage BlurDetect::sobelEdgeDetect(const QImage& source) { QImage sobelEdges(source.size(), source.format()); int GX[3][3]; int GY[3][3]; /* 3x3 GX Sobel mask. Ref: www.cee.hw.ac.uk/hipr/html/sobel.html */ GX[0][0] = -1; GX[0][1] = 0; GX[0][2] = 1; GX[1][0] = -2; GX[1][1] = 0; GX[1][2] = 2; GX[2][0] = -1; GX[2][1] = 0; GX[2][2] = 1; /* 3x3 GY Sobel mask. Ref: www.cee.hw.ac.uk/hipr/html/sobel.html */ GY[0][0] = 1; GY[0][1] = 2; GY[0][2] = 1; GY[1][0] = 0; GY[1][1] = 0; GY[1][2] = 0; GY[2][0] = -1; GY[2][1] = -2; GY[2][2] = -1; int width = source.width(); int height = source.height(); int I, J; long sumX, sumY; int SUM; QRgb color; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { if ( y == 0 || y >= height-1 || x == 0 || x >= width-1 ) { SUM = 0; } else { sumX = 0; sumY = 0; /*-------X and Y GRADIENT APPROXIMATION------*/ for(I=-1; I<=1; I++) { for(J=-1; J<=1; J++) { color = source.pixel(x+I, y+J); sumX += qGray(color) * GX[I+1][J+1]; sumY += qGray(color) * GY[I+1][J+1]; } } SUM = abs(sumX) + abs(sumY); /*---GRADIENT MAGNITUDE APPROXIMATION (Myler p.218)----*/ if (SUM > 255) { SUM = 255; } } sobelEdges.setPixel(x,y,qRgb(SUM, SUM, SUM)); } } return sobelEdges; }
MainWindow::MainWindow() { openAction = new QAction(tr("&Open"), this); saveAction = new QAction(tr("&Save"), this); exitAction = new QAction(tr("E&xit"), this); equalAction = new QAction(tr("&Equalization"), this); otsuAction = new QAction(tr("&otsu"), this); isodataAction = new QAction(tr("&Isodata"), this); manualAction = new QAction(tr("&Manual"), this); gammaAction = new QAction(tr("&Gamma"), this); stretchingAction = new QAction(tr("&Stretching"), this); sigmaAction = new QAction(tr("&Sigma"), this); medianAction = new QAction(tr("&Median"), this); lineAction = new QAction(tr("&Lines"), this); pixelAction = new QAction(tr("&Pixels"), this); gaussianAction = new QAction(tr("&Gaussian"), this); sobelAction = new QAction(tr("&Sobel"), this); horizontalAction = new QAction(tr("&Line Intensity"), this); cannyAction = new QAction(tr("&Canny"),this); sumAction = new QAction(tr("&Add"),this); resAction = new QAction(tr("&Substract"),this); multAction = new QAction(tr("&Multiply"),this); divAction = new QAction(tr("&Divide"),this); avgAction = new QAction(tr("A&verage"),this); andAction = new QAction(tr("&And"),this); orAction = new QAction(tr("&Or"),this); xorAction = new QAction(tr("&Xor"),this); notAction = new QAction(tr("&Not"),this); minAction = new QAction(tr("M&in"),this); maxAction = new QAction(tr("M&ax"),this); kmeansAction = new QAction(tr("&Kmeans"),this); saveAction->setEnabled(false); connect(openAction, SIGNAL(triggered()), this, SLOT(open())); connect(saveAction, SIGNAL(triggered()), this, SLOT(save())); connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(equalAction, SIGNAL(triggered()), this, SLOT(equalization())); connect(otsuAction, SIGNAL(triggered()), this, SLOT(otsuThresh())); connect(isodataAction, SIGNAL(triggered()), this, SLOT(isodataSlot())); connect(manualAction, SIGNAL(triggered()), this, SLOT(manual())); connect(gammaAction,SIGNAL(triggered()),this,SLOT(gamma())); connect(stretchingAction,SIGNAL(triggered()),this,SLOT(stretching())); connect(sigmaAction, SIGNAL(triggered()), this, SLOT(sigma())); connect(medianAction, SIGNAL(triggered()), this, SLOT(median())); connect(lineAction, SIGNAL(triggered()), this, SLOT(line())); connect(pixelAction, SIGNAL(triggered()), this, SLOT(pixel())); connect(gaussianAction, SIGNAL(triggered()), this, SLOT(gaussian())); connect(sobelAction, SIGNAL(triggered()), this, SLOT(sobelEdges())); connect(horizontalAction,SIGNAL(triggered()),this,SLOT(horizontal())); connect(cannyAction,SIGNAL(triggered()),this,SLOT(cannySlot())); connect(sumAction,SIGNAL(triggered()),this,SLOT(sum())); connect(resAction,SIGNAL(triggered()),this,SLOT(res())); connect(multAction,SIGNAL(triggered()),this,SLOT(mult())); connect(divAction,SIGNAL(triggered()),this,SLOT(div())); connect(avgAction,SIGNAL(triggered()),this,SLOT(avg())); connect(andAction,SIGNAL(triggered()),this,SLOT(andSlot())); connect(orAction,SIGNAL(triggered()),this,SLOT(orSlot())); connect(xorAction,SIGNAL(triggered()),this,SLOT(xorSlot())); connect(notAction,SIGNAL(triggered()),this,SLOT(notSlot())); connect(minAction,SIGNAL(triggered()),this,SLOT(minSlot())); connect(maxAction,SIGNAL(triggered()),this,SLOT(maxSlot())); connect(kmeansAction,SIGNAL(triggered()),this,SLOT(kmeansSlot())); fileMenu = menuBar()->addMenu(tr("&File")); equalizationMenu = menuBar()->addMenu(tr("&Equalization")); thresholdMenu = menuBar()->addMenu(tr("&Thresholding")); contrastMenu = menuBar()->addMenu(tr("&Contrast")); noiseMenu = menuBar()->addMenu(tr("&Noise")); edgeMenu = menuBar()->addMenu(tr("E&dge")); operationMenu = menuBar()->addMenu(tr("&Operation")); boolMenu = operationMenu->addMenu(tr("&Boolean")); arithMenu = operationMenu->addMenu(tr("&Arithmetic")); relMenu = operationMenu->addMenu(tr("&Relational")); segmentationMenu = menuBar()->addMenu(tr("&Segmentation")); equalizationMenu->setEnabled(false); thresholdMenu->setEnabled(false); contrastMenu->setEnabled(false); noiseMenu->setEnabled(false); edgeMenu->setEnabled(false); operationMenu->setEnabled(false); segmentationMenu->setEnabled(false); fileMenu->addAction(openAction); fileMenu->addAction(saveAction); fileMenu->addSeparator(); fileMenu->addAction(exitAction); equalizationMenu->addAction(equalAction); thresholdMenu->addAction(otsuAction); thresholdMenu->addAction(isodataAction); thresholdMenu->addAction(manualAction); contrastMenu->addAction(gammaAction); contrastMenu->addAction(stretchingAction); noiseMenu->addAction(sigmaAction); noiseMenu->addAction(medianAction); noiseMenu->addAction(lineAction); noiseMenu->addAction(pixelAction); noiseMenu->addAction(gaussianAction); edgeMenu->addAction(sobelAction); edgeMenu->addAction(horizontalAction); edgeMenu->addAction(cannyAction); boolMenu->addAction(andAction); boolMenu->addAction(orAction); boolMenu->addAction(xorAction); boolMenu->addAction(notAction); arithMenu->addAction(sumAction); arithMenu->addAction(resAction); arithMenu->addAction(multAction); arithMenu->addAction(divAction); arithMenu->addAction(avgAction); relMenu->addAction(minAction); relMenu->addAction(maxAction); segmentationMenu->addAction(kmeansAction); //----- viewer = new ImageViewer(this); QScrollArea * scrollArea = new QScrollArea; scrollArea->setWidget(viewer); scrollArea->setFixedWidth(600); scrollArea->setWidgetResizable(true); boxW = new QSpinBox(); boxW->setEnabled(false); boxW->setMaximum(65535); boxC = new QSpinBox(); boxC->setEnabled(false); boxC->setMaximum(65535); histoViewer = new ImageViewer(this); QScrollArea * histoArea = new QScrollArea; histoArea->setWidget(histoViewer); histoArea->setFixedSize(268,278); histoArea->setWidgetResizable(false); QVBoxLayout * rightLayout = new QVBoxLayout; rightLayout->addWidget(new QLabel("Window:",this)); rightLayout->addWidget(boxW); rightLayout->addWidget(new QLabel("Level:",this)); rightLayout->addWidget(boxC); rightLayout->addWidget(histoArea); connect(boxW,SIGNAL(valueChanged(int)),this,SLOT(changeW(int))); connect(boxC,SIGNAL(valueChanged(int)),this,SLOT(changeC(int))); QWidget * rightSide = new QWidget; rightSide->setLayout(rightLayout); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(scrollArea); mainLayout->addWidget(rightSide); QWidget * centralWidget = new QWidget(); centralWidget->setLayout(mainLayout); setCentralWidget(centralWidget); setWindowTitle(tr("DICOM Image Processor")); setFixedSize(QSize(900,600)); }