Zadanie 8

This commit is contained in:
Sebastian Spaloniak 2020-05-12 10:51:05 +02:00
parent 3e1c4e8a00
commit 1139cf8f8b
6 changed files with 185 additions and 19 deletions

View File

@ -24,8 +24,43 @@ PNM* EdgeGradient::transform()
{ {
PNM* newImage = new PNM(image->width(), image->height(), image->format()); PNM* newImage = new PNM(image->width(), image->height(), image->format());
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; int width = image->width();
int height = image->height();
return newImage; PNM* imageX = horizontalDetection();
PNM* imageY = verticalDetection();
if (image->format() == QImage::Format_Indexed8)
{
int q;
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
QRgb xPixel = imageX->pixel(x, y);
QRgb yPixel = imageY->pixel(x, y);
q = (int)sqrt(pow(qGray(xPixel), 2.0) + pow(qGray(yPixel), 2.0));
newImage->setPixel(x, y, q);
}
}
}
else
{
int r, g, b;
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
QRgb xPixel = imageX->pixel(x, y);
QRgb yPixel = imageY->pixel(x, y);
r = (int)sqrt(pow(qRed(xPixel), 2.0) + pow(qRed(yPixel), 2.0));
g = (int)sqrt(pow(qGreen(xPixel), 2.0) + pow(qGreen(yPixel), 2.0));
b = (int)sqrt(pow(qBlue(xPixel), 2.0) + pow(qBlue(yPixel), 2.0));
newImage->setPixel(x, y, QColor(r, g, b).rgb());
}
}
}
return newImage;
} }

View File

@ -10,13 +10,25 @@ EdgeLaplacian::EdgeLaplacian(PNM* img, ImageViewer* iv) :
{ {
} }
math::matrix<float> EdgeLaplacian::getMask(int, Mode) math::matrix<float> EdgeLaplacian::getMask(int size, Mode)
{ {
int size = getParameter("size").toInt(); if (getParameter("size").toInt() > size) {
math::matrix<float> mask(size, size); size = getParameter("size").toInt();
}
//int
math::matrix<float> mask(size, size);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; for (int x = 0; x < size; x++)
{
for (int y = 0; y < size; y++)
{
mask(x, y) = -1;
}
}
return mask; int halfsize = size / 2;
mask(halfsize, halfsize) = ((float)pow(size, 2.0)) - 1.0;
return mask;
} }

View File

@ -18,17 +18,18 @@ math::matrix<float> EdgeLaplaceOfGauss::getMask(int, Mode)
double sigma = getParameter("sigma").toDouble(); double sigma = getParameter("sigma").toDouble();
math::matrix<float> mask(size, size); math::matrix<float> mask(size, size);
for (int x = 0; x < size; x++){
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; for (int y = 0; y < size; y++){
mask(x, y) = getLoG(x - size / 2, y - size / 2, sigma);
}
}
return mask; return mask;
} }
float EdgeLaplaceOfGauss::getLoG(int x, int y, float s) float EdgeLaplaceOfGauss::getLoG(int x, int y, float s)
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; float a = ((pow(x, 2) + pow(y, 2)) / pow(s, 2) - 2 / pow(s, 2))*BlurGaussian::getGauss(x, y, s);
return a;
return 0;
} }
int EdgeLaplaceOfGauss::getSize() int EdgeLaplaceOfGauss::getSize()

View File

@ -14,6 +14,30 @@ EdgePrewitt::EdgePrewitt(PNM*img, ImageViewer* iv) :
void EdgePrewitt::prepareMatrices() void EdgePrewitt::prepareMatrices()
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; math::matrix<float> gx(3, 3);
math::matrix<float> gy(3, 3);
g_x = gx;
g_y = gy;
g_x(0, 0) = -1;
g_x(0, 1) = 0;
g_x(0, 2) = 1;
g_x(1, 0) = -1;
g_x(1, 1) = 0;
g_x(1, 2) = 1;
g_x(2, 0) = -1;
g_x(2, 1) = 0;
g_x(2, 2) = 1;
g_y(0, 0) = -1;
g_y(0, 1) = -1;
g_y(0, 2) = -1;
g_y(1, 0) = 0;
g_y(1, 1) = 0;
g_y(1, 2) = 0;
g_y(2, 0) = 1;
g_y(2, 1) = 1;
g_y(2, 2) = 1;
} }

View File

@ -14,5 +14,19 @@ EdgeRoberts::EdgeRoberts(PNM* img, ImageViewer* iv) :
void EdgeRoberts::prepareMatrices() void EdgeRoberts::prepareMatrices()
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; math::matrix<float> gx(2, 2);
math::matrix<float> gy(2, 2);
g_x = gx;
g_y = gy;
g_x(0, 0) = 1;
g_x(1, 0) = 0;
g_x(0, 1) = 0;
g_x(1, 1) = -1;
g_y(0, 0) = 0;
g_y(1, 0) = -1;
g_y(0, 1) = 1;
g_y(1, 1) = 0;
} }

View File

@ -17,14 +17,94 @@ PNM* EdgeZeroCrossing::transform()
int width = image->width(), int width = image->width(),
height = image->height(); height = image->height();
int size = getParameter("size").toInt(); int size = getParameter("size").toInt();
double sigma = getParameter("sigma").toDouble(); double sigma = getParameter("sigma").toDouble();
int t = getParameter("threshold").toInt(); int t = getParameter("threshold").toInt();
PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8); PNM* newImage = new PNM(width, height, QImage::Format_Indexed8);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; EdgeLaplaceOfGauss elof(image, getSupervisor());
elof.setParameter("size", size);
elof.setParameter("sigma", sigma);
PNM* lof = elof.transform();
int v = 128;
if (image->format() == QImage::Format_Indexed8){
for (int x = 0; x < width; x++){
for (int y = 0; y < height; y++){
math::matrix<float> mask = elof.getWindow(x, y, size, Transformation::LChannel, Transformation::RepeatEdge);
float minimum = 255.0, maximum = 0;
for (int i = 0; i < size; i++){
for (int j = 0; j < size; j++){
if (mask(i, j) < minimum){
minimum = mask(i, j);
}
if (mask(i, j) > maximum){
maximum = mask(i, j);
}
}
}
if (minimum<v - t && maximum>v + t){
newImage->setPixel(x, y, qGray(lof->pixel(x, y)));
}
else {
newImage->setPixel(x, y, 0);
}
}
}
}
else{
for (int x = 0; x < width; x++){
for (int y = 0; y < height; y++){
math::matrix<float> maskR = elof.getWindow(x, y, size, Transformation::RChannel, Transformation::RepeatEdge);
math::matrix<float> maskG = elof.getWindow(x, y, size, Transformation::GChannel, Transformation::RepeatEdge);
math::matrix<float> maskB = elof.getWindow(x, y, size, Transformation::BChannel, Transformation::RepeatEdge);
float minimumR = 255.0, maximumR = 0, minimumG = 255.0, maximumG = 0, minimumB = 255.0, maximumB = 0;
for (int i = 0; i < size; i++){
for (int j = 0; j < size; j++){
if (maskR(i, j) < minimumR){
minimumR = maskR(i, j);
}
if (maskR(i, j) > maximumR){
maximumR = maskR(i, j);
}
}
}
for (int i = 0; i < size; i++){
for (int j = 0; j < size; j++){
if (maskG(i, j) < minimumG){
minimumG = maskG(i, j);
}
if (maskG(i, j) > maximumG){
maximumG = maskG(i, j);
}
}
}
for (int i = 0; i < size; i++){
for (int j = 0; j < size; j++){
if (maskB(i, j) < minimumB){
minimumB = maskB(i, j);
}
if (maskB(i, j) > maximumB){
maximumB = maskB(i, j);
}
}
}
if (minimumR<v - t && maximumR>v + t){
newImage->setPixel(x, y, maskR(size / 2, size / 2));
}
else if (minimumG<v - t && maximumG>v + t){
newImage->setPixel(x, y, maskG(size / 2, size / 2));
}
else if (minimumB<v - t && maximumB>v + t){
newImage->setPixel(x, y, maskB(size / 2, size / 2));
}
else {
newImage->setPixel(x, y, 0);
}
}
}
}
return newImage; return newImage;
} }