1
0

Zadanie 12 - fixes

This commit is contained in:
Jarosław Wieczorek 2021-05-20 17:40:36 +02:00
parent d264b6070d
commit be58a899a8
12 changed files with 88 additions and 21 deletions

View File

@ -97,7 +97,7 @@ PNM* BinarizationOtsu::transform()
bcv[t]= W_b * W_f * pow(u_b - u_f, 2); bcv[t]= W_b * W_f * pow(u_b - u_f, 2);
} }
int T = 0; T = 0;
for (int j=0; j< 255;j++) for (int j=0; j< 255;j++)
{ {
if (bcv[j] > bcv[T]) if (bcv[j] > bcv[T])
@ -119,7 +119,6 @@ PNM* BinarizationOtsu::transform()
} }
} }
return newImage; return newImage;
} }

View File

@ -8,7 +8,7 @@ class BinarizationOtsu : public Transformation
public: public:
BinarizationOtsu(PNM*); BinarizationOtsu(PNM*);
BinarizationOtsu(PNM*, ImageViewer*); BinarizationOtsu(PNM*, ImageViewer*);
int T = 0;
virtual PNM* transform(); virtual PNM* transform();
}; };

View File

@ -3,6 +3,7 @@
#include "blur_gaussian.h" #include "blur_gaussian.h"
#include "conversion_grayscale.h" #include "conversion_grayscale.h"
#include "edge_sobel.h" #include "edge_sobel.h"
#include <iostream>
CornerHarris::CornerHarris(PNM* img) : CornerHarris::CornerHarris(PNM* img) :
Convolution(img) Convolution(img)
@ -24,13 +25,14 @@ PNM* CornerHarris::transform()
int width = image->width(); int width = image->width();
int height = image->height(); int height = image->height();
PNM* newImage = new PNM(width, height, QImage::Format_Mono); PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
math::matrix<float> Ixx(width, height); math::matrix<float> Ixx(width, height);
math::matrix<float> Iyy(width, height); math::matrix<float> Iyy(width, height);
math::matrix<float> Ixy(width, height); math::matrix<float> Ixy(width, height);
math::matrix<float> corner_candidates(width, height);
math::matrix<float> corner_nonmax_suppress(width, height); this->corner_candidates = new math::matrix<float>(width, height);
this->corner_nonmax_suppress = new math::matrix<float>(width, height);
ConversionGrayscale* conversion_grayscale = new ConversionGrayscale(image); ConversionGrayscale* conversion_grayscale = new ConversionGrayscale(image);
PNM* gray_image = conversion_grayscale->transform(); PNM* gray_image = conversion_grayscale->transform();
@ -52,8 +54,8 @@ PNM* CornerHarris::transform()
Ixy[i][j] = (*Gx)[i][j] * (*Gy)[i][j]; Ixy[i][j] = (*Gx)[i][j] * (*Gy)[i][j];
Iyy[i][j] = (*Gy)[i][j] * (*Gy)[i][j]; Iyy[i][j] = (*Gy)[i][j] * (*Gy)[i][j];
corner_candidates[i][j] = 0; (*corner_candidates)[i][j] = 0;
corner_nonmax_suppress[i][j] = 0; (*corner_nonmax_suppress)[i][j] = 0;
} }
} }
@ -92,7 +94,7 @@ PNM* CornerHarris::transform()
if (r > threshold) if (r > threshold)
{ {
corner_candidates[i][j] = r; (*corner_candidates)[i][j] = r;
} }
} }
} }
@ -106,31 +108,31 @@ PNM* CornerHarris::transform()
{ {
for (int j = 1; j <height - 1; j++) for (int j = 1; j <height - 1; j++)
{ {
float max = corner_candidates[i][j]; float max = (*corner_candidates)[i][j];
for (int k = -1; k <= 1; k++) for (int k = -1; k <= 1; k++)
{ {
for (int l = -1; l <= 1; l++) for (int l = -1; l <= 1; l++)
{ {
if (max < corner_candidates[i+k][j+l]) if (max < (*corner_candidates)[i+k][j+l])
{ {
max = corner_candidates[i+k][j+l]; max = (*corner_candidates)[i+k][j+l];
} }
} }
} }
if (corner_candidates[i][j] == max) if ((*corner_candidates)[i][j] == max)
{ {
corner_nonmax_suppress[i][j] = corner_candidates[i][j]; (*corner_nonmax_suppress)[i][j] = (*corner_candidates)[i][j];
} }
else else
{ {
if (corner_candidates[i][j] > 0) if ((*corner_candidates)[i][j] > 0)
{ {
search = true; search = true;
} }
corner_nonmax_suppress[i][j] = 0; (*corner_nonmax_suppress)[i][j] = 0;
} }
} }
@ -142,13 +144,15 @@ PNM* CornerHarris::transform()
{ {
for (int j = 0; j < height; j++) for (int j = 0; j < height; j++)
{ {
if (corner_candidates[i][j] == 0) if ((*corner_candidates)[i][j] == 0)
{ {
newImage->setPixel(i, j, Qt::color0);
newImage->setPixel(i, j, QColor(0, 0, 0).rgb());
} }
else else
{ {
newImage->setPixel(i, j, Qt::color1); // std::cout << "White corner" << std::endl;
newImage->setPixel(i, j, QColor(255, 255, 255).rgb());
} }
} }
} }

View File

@ -8,7 +8,8 @@ class CornerHarris : public Convolution
public: public:
CornerHarris(PNM*); CornerHarris(PNM*);
CornerHarris(PNM*, ImageViewer*); CornerHarris(PNM*, ImageViewer*);
math::matrix<float>* corner_candidates;
math::matrix<float>* corner_nonmax_suppress;
PNM* transform(); PNM* transform();
}; };

View File

@ -51,7 +51,7 @@ PNM* HoughLines::transform()
int height = image_bin->height(); int height = image_bin->height();
QPainter qPainter (newImage); QPainter qPainter (newImage);
qPainter.setPen(Qt::red); qPainter.setPen(Qt::yellow);
for (int theta = 0; theta < hough_width; theta++) for (int theta = 0; theta < hough_width; theta++)
{ {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

5
images/blue_square.pnm Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long