zadania 6 i 7

This commit is contained in:
BohdanBakhlul 2021-05-29 02:01:46 +02:00
parent 701ce8d44b
commit b20080e25e
6 changed files with 101 additions and 18 deletions

View File

@ -15,9 +15,33 @@ PNM* BinarizationGradient::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_RGB32);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; float a = 0;
float b = 0;
for (int x = 0; x<width; x++)
for (int y = 0; y<height; y++){
int Gx = qGray(getPixel(x + 1, y, RepeatEdge)) - qGray(getPixel(x - 1, y, RepeatEdge));
int Gy = qGray(getPixel(x, y + 1, RepeatEdge)) - qGray(getPixel(x, y - 1, RepeatEdge));
a += Gx > Gy ? Gx : Gy * qGray(getPixel(x, y, RepeatEdge));
b += Gx > Gy ? Gx : Gy;
}
int threshold = a / b;
for (int x = 0; x<width; x++)
for (int y = 0; y<height; y++) {
QRgb pixel = image->pixel(x,y);
int v = 0;
if (qGray(pixel) >= threshold) v = 255;
newImage->setPixel(x,y, QColor(v,v,v).rgb());
}
return newImage; return newImage;
} }

View File

@ -17,9 +17,18 @@ PNM* BinarizationManual::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_RGB32);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; for (int x=0; x<width; x++)
for (int y=0; y<height; y++)
{
QRgb pixel = image->pixel(x,y);
int v = 0;
if (qGray(pixel) >= threshold) v = 255;
newImage->setPixel(x,y, QColor(v,v,v).rgb());
}
return newImage; return newImage;
} }

View File

@ -14,7 +14,14 @@ const int MorphDilate::morph(math::matrix<float> window, math::matrix<bool> se)
{ {
float min = PIXEL_VAL_MAX+1; float min = PIXEL_VAL_MAX+1;
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; for (int i=0;i<window.colno();++i) {
for (int j=0;j<window.colsize();++j) {
return 0; if (se[i][j] == true) {
if (min > window[i][j]) {
min = window[i][j];
}
}
}
}
return min;
} }

View File

@ -14,7 +14,15 @@ const int MorphErode::morph(math::matrix<float> window, math::matrix<bool> se)
{ {
float max=0.0; float max=0.0;
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; for (int i=0;i<window.colno();++i) {
for (int j=0;j<window.colsize();++j) {
if (se[i][j] == true) {
if (max < window[i][j]) {
max = window[i][j];
}
}
}
}
return 0; return max;
} }

View File

@ -19,9 +19,15 @@ PNM* MorphOpenClose::transform()
SE shape = (SE) getParameter("shape").toInt(); SE shape = (SE) getParameter("shape").toInt();
m_type = (Type) getParameter("type").toInt(); m_type = (Type) getParameter("type").toInt();
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; if (m_type == Close) {
image = erode(image, size, shape);
image = dilate(image, size, shape);
} else if (m_type == Open) {
image = dilate(image, size, shape);
image = erode(image, size, shape);
}
return 0; return image;
} }
PNM* MorphOpenClose::erode(PNM* image, int size, SE shape) PNM* MorphOpenClose::erode(PNM* image, int size, SE shape)

View File

@ -34,7 +34,7 @@ math::matrix<bool> MorphologicalOperator::seSquare(int size)
{ {
math::matrix<bool> ret(size, size); math::matrix<bool> ret(size, size);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; for (int x=0;x<size;++x) for (int y=0;y<size;++y) ret[x][y] = true;
return ret; return ret;
} }
@ -43,16 +43,23 @@ math::matrix<bool> MorphologicalOperator::seCross(int size)
{ {
math::matrix<bool> ret(size, size); math::matrix<bool> ret(size, size);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; for (int x=0;x<size;++x) {
for (int y=0;y<size;++y) {
ret[x][y] = (x/2 == size/2 || y/2 == size/2) ? true : false;
}
}
return ret; return ret;
} }
math::matrix<bool> MorphologicalOperator::seXCross(int size) math::matrix<bool> MorphologicalOperator::seXCross(int size)
{ {
math::matrix<bool> ret(size, size); math::matrix<bool> ret(size, size, false);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; for (int i=0;i<size;++i) {
ret[i][i] = true;
ret[1][size-1-i] = true;
}
return ret; return ret;
} }
@ -61,7 +68,11 @@ math::matrix<bool> MorphologicalOperator::seVLine(int size)
{ {
math::matrix<bool> ret(size, size); math::matrix<bool> ret(size, size);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; for (int x=0;x<size;++x) {
for (int y=0;y<size;++y) {
ret[x][y] = (x/2 == size/2) ? true : false;
}
}
return ret; return ret;
} }
@ -70,7 +81,11 @@ math::matrix<bool> MorphologicalOperator::seHLine(int size)
{ {
math::matrix<bool> ret(size, size); math::matrix<bool> ret(size, size);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; for (int x=0;x<size;++x) {
for (int y=0;y<size;++y) {
ret[x][y] = (y/2 == size/2) ? true : false;
}
}
return ret; return ret;
} }
@ -82,7 +97,21 @@ PNM* MorphologicalOperator::transform()
PNM* newImage = new PNM(image->width(), image->height(), QImage::Format_RGB32); PNM* newImage = new PNM(image->width(), image->height(), QImage::Format_RGB32);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; for (int x=0;x<image->width();++x) {
for (int y=0;y<image->height();++y) {
math::matrix<float> windowR = getWindow(x, y, size, RChannel, RepeatEdge);
int newR = morph(windowR, getSE(size, shape));
math::matrix<float> windowG = getWindow(x, y, size, GChannel, RepeatEdge);
int newG = morph(windowG, getSE(size, shape));
math::matrix<float> windowB = getWindow(x, y, size, BChannel, RepeatEdge);
int newB = morph(windowB, getSE(size, shape));
newImage->setPixel(x,y, QColor(newR, newG, newB).rgb());
}
}
return newImage; return newImage;
} }