zadanie-7
This commit is contained in:
parent
6bd761d4f1
commit
41f0bcd76c
@ -13,8 +13,14 @@ MorphDilate::MorphDilate(PNM* img, ImageViewer* iv) :
|
||||
const int MorphDilate::morph(math::matrix<float> window, math::matrix<bool> se)
|
||||
{
|
||||
float min = PIXEL_VAL_MAX+1;
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return 0;
|
||||
for (unsigned int i=0;i<window.colno();++i) {
|
||||
for (unsigned int j=0;j<window.colsize();++j) {
|
||||
if (se[i][j] == true) {
|
||||
if (min > window[i][j]) {
|
||||
min = window[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return window.min();
|
||||
}
|
||||
|
@ -14,7 +14,14 @@ const int MorphErode::morph(math::matrix<float> window, math::matrix<bool> se)
|
||||
{
|
||||
float max=0.0;
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return 0;
|
||||
for (unsigned int i=0;i<window.colno();++i) {
|
||||
for (unsigned int j=0;j<window.colsize();++j) {
|
||||
if (se[i][j] == true) {
|
||||
if (max < window[i][j]) {
|
||||
max = window[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return window.max();
|
||||
}
|
||||
|
@ -19,9 +19,15 @@ PNM* MorphOpenClose::transform()
|
||||
SE shape = (SE) getParameter("shape").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)
|
||||
|
@ -34,7 +34,11 @@ math::matrix<bool> MorphologicalOperator::seSquare(int 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;
|
||||
}
|
||||
@ -43,16 +47,33 @@ math::matrix<bool> MorphologicalOperator::seCross(int 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) {
|
||||
if (x/2 == size/2 || y/2 == size/2) {
|
||||
ret[x][y] = true;
|
||||
} else {
|
||||
ret[x][y] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
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!";
|
||||
int x = 0, y = 0;
|
||||
for (int i=0;i<size;++i) {
|
||||
ret[x++][y++] = true;
|
||||
}
|
||||
|
||||
x = 0;
|
||||
y = size - 1;
|
||||
for (int i=0;i<size;++i) {
|
||||
ret[x++][y--] = true;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -61,7 +82,15 @@ math::matrix<bool> MorphologicalOperator::seVLine(int 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) {
|
||||
if (x/2 == size/2) {
|
||||
ret[x][y] = true;
|
||||
} else {
|
||||
ret[x][y] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -70,7 +99,15 @@ math::matrix<bool> MorphologicalOperator::seHLine(int 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) {
|
||||
if (y/2 == size/2) {
|
||||
ret[x][y] = true;
|
||||
} else {
|
||||
ret[x][y] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -82,7 +119,18 @@ PNM* MorphologicalOperator::transform()
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user