Skip to content

Commit

Permalink
0.2024.05.11: output: compact list of filters
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed May 11, 2024
1 parent 12742a3 commit 51b8f42
Show file tree
Hide file tree
Showing 25 changed files with 567 additions and 696 deletions.
32 changes: 20 additions & 12 deletions src/imageproc/ColorFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,22 @@ void wienerFilterInPlace(
}

QImage wienerColorFilter(
QImage const& image, QSize const& window_size, float const coef)
QImage const& image, int const f_size, float const coef)
{
QImage dst(image);
wienerColorFilterInPlace(dst, window_size, coef);
wienerColorFilterInPlace(dst, f_size, coef);
return dst;
}

void wienerColorFilterInPlace(
QImage& image, QSize const& window_size, float const coef)
QImage& image, int const f_size, float const coef)
{
if (image.isNull())
{
return;
}
int const ff_size = f_size + f_size + 1;
QSize const& window_size = QSize(ff_size, ff_size);
if (window_size.isEmpty())
{
throw std::invalid_argument("wienerFilter: empty window_size");
Expand Down Expand Up @@ -396,16 +398,18 @@ void colorDespeckleFilterInPlace(
}

QImage blurFilter(
QImage const& image, QSize const& window_size, float const coef)
QImage const& image, int const f_size, float const coef)
{
QImage dst(image);
blurFilterInPlace(dst, window_size, coef);
blurFilterInPlace(dst, f_size, coef);
return dst;
}

void blurFilterInPlace(
QImage& image, QSize const& window_size, float const coef)
QImage& image, int const f_size, float const coef)
{
int const ff_size = f_size + f_size + 1;
QSize const& window_size = QSize(ff_size, ff_size);
if (window_size.isEmpty())
{
throw std::invalid_argument("blurFilter: empty window_size");
Expand Down Expand Up @@ -464,20 +468,22 @@ void blurFilterInPlace(
}

QImage screenFilter(
QImage const& image, QSize const& window_size, float const coef)
QImage const& image, int const f_size, float const coef)
{
QImage dst(image);
screenFilterInPlace(dst, window_size, coef);
screenFilterInPlace(dst, f_size, coef);
return dst;
}

void screenFilterInPlace(
QImage& image, QSize const& window_size, float const coef)
QImage& image, int const f_size, float const coef)
{
if (image.isNull())
{
return;
}
int const ff_size = f_size + f_size + 1;
QSize const& window_size = QSize(ff_size, ff_size);
if (window_size.isEmpty())
{
throw std::invalid_argument("screenFilter: empty window_size");
Expand Down Expand Up @@ -2053,16 +2059,18 @@ void unPaperFilterInPlace(


QImage gravureFilter(
QImage const& image, QSize const& window_size, float const coef)
QImage const& image, int const f_size, float const coef)
{
QImage dst(image);
gravureFilterInPlace(dst, window_size, coef);
gravureFilterInPlace(dst, f_size, coef);
return dst;
}

void gravureFilterInPlace(
QImage& image, QSize const& window_size, float const coef)
QImage& image, int const f_size, float const coef)
{
int const ff_size = f_size + f_size + 1;
QSize const& window_size = QSize(ff_size, ff_size);
if (window_size.isEmpty())
{
throw std::invalid_argument("gravureFilter: empty window_size");
Expand Down
58 changes: 29 additions & 29 deletions src/imageproc/ColorFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,41 @@ IMAGEPROC_EXPORT GrayImage wienerFilter(
IMAGEPROC_EXPORT void wienerFilterInPlace(
GrayImage& image, QSize const& window_size, float noise_sigma);

IMAGEPROC_EXPORT QImage colorCurveFilter(
QImage& image, float coef = 0.5f);

IMAGEPROC_EXPORT void colorCurveFilterInPlace(
QImage& image, float coef = 0.5f);

IMAGEPROC_EXPORT QImage colorSqrFilter(
QImage& image, float coef = 0.0f);

IMAGEPROC_EXPORT void colorSqrFilterInPlace(
QImage& image, float coef = 0.0f);

IMAGEPROC_EXPORT QImage wienerColorFilter(
QImage const& image, QSize const& window_size, float coef = 0.0f);
QImage const& image, int f_size = 2, float coef = 0.0f);

IMAGEPROC_EXPORT void wienerColorFilterInPlace(
QImage& image, QSize const& window_size, float coef = 0.0f);
QImage& image, int f_size = 2, float coef = 0.0f);

IMAGEPROC_EXPORT QImage knnDenoiserFilter(
QImage const& image, int radius = 1, float coef = 0.0f);
QImage const& image, int radius = 2, float coef = 0.0f);

IMAGEPROC_EXPORT void knnDenoiserFilterInPlace(
QImage& image, int radius = 1, float coef = 0.0f);
QImage& image, int radius = 2, float coef = 0.0f);

IMAGEPROC_EXPORT QImage colorDespeckleFilter(
QImage const& image, int radius = 1, float coef = 0.0f);
QImage const& image, int radius = 2, float coef = 0.0f);

IMAGEPROC_EXPORT void colorDespeckleFilterInPlace(
QImage& image, int radius = 1, float coef = 0.0f);

IMAGEPROC_EXPORT QImage blurFilter(
QImage const& image, QSize const& window_size, float coef = 0.0f);
QImage const& image, int f_size = 2, float coef = 0.0f);

IMAGEPROC_EXPORT void blurFilterInPlace(
QImage& image, QSize const& window_size, float coef = 0.0f);
QImage& image, int f_size = 2, float coef = 0.0f);

/**
* @brief Applies the Screen filter to a image.
Expand All @@ -80,26 +92,26 @@ IMAGEPROC_EXPORT void blurFilterInPlace(
* @return The filtered image.
*/
IMAGEPROC_EXPORT QImage screenFilter(
QImage const& image, QSize const& window_size, float coef = 0.0f);
QImage const& image, int f_size = 5, float coef = 0.0f);

/**
* @brief An in-place version of screenFilter().
* @see screenFilter()
*/
IMAGEPROC_EXPORT void screenFilterInPlace(
QImage& image, QSize const& window_size, float coef = 0.0f);
QImage& image, int f_size = 5, float coef = 0.0f);

IMAGEPROC_EXPORT QImage colorCurveFilter(
QImage& image, float coef = 0.5f);
IMAGEPROC_EXPORT QImage unPaperFilter(
QImage const& image, unsigned int const iters, float coef = 0.0f);

IMAGEPROC_EXPORT void colorCurveFilterInPlace(
QImage& image, float coef = 0.5f);
IMAGEPROC_EXPORT void unPaperFilterInPlace(
QImage& image, unsigned int const iters, float coef = 0.0f);

IMAGEPROC_EXPORT QImage colorSqrFilter(
QImage& image, float coef = 0.0f);
IMAGEPROC_EXPORT void gravureFilterInPlace(
QImage& image, int f_size = 5, float coef = 0.0f);

IMAGEPROC_EXPORT void colorSqrFilterInPlace(
QImage& image, float coef = 0.0f);
IMAGEPROC_EXPORT QImage gravureFilter(
QImage& image, int f_size = 5, float coef = 0.0f);

IMAGEPROC_EXPORT GrayImage coloredSignificanceFilter(
QImage const& image, float coef = 0.0f);
Expand Down Expand Up @@ -172,18 +184,6 @@ IMAGEPROC_EXPORT void maskMorphologicalClose(
IMAGEPROC_EXPORT void maskMorphological(
QImage& image, BinaryImage const& mask, int radius = 0);

IMAGEPROC_EXPORT QImage unPaperFilter(
QImage const& image, unsigned int const iters, float coef = 0.0f);

IMAGEPROC_EXPORT void unPaperFilterInPlace(
QImage& image, unsigned int const iters, float coef = 0.0f);

IMAGEPROC_EXPORT void gravureFilterInPlace(
QImage& image, QSize const& window_size, float coef = 0.0f);

IMAGEPROC_EXPORT QImage gravureFilter(
QImage& image, float coef = 0.0f);

} // namespace imageproc

#endif
88 changes: 44 additions & 44 deletions src/stages/output/ColorGrayscaleOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,90 +25,90 @@ namespace output
{

ColorGrayscaleOptions::ColorGrayscaleOptions(QDomElement const& el)
: m_wienerCoef(el.attribute("wienerCoef").toDouble()),
m_wienerWindowSize(el.attribute("wienerWinSize").toInt()),
m_knndCoef(el.attribute("knnDenoiser").toDouble()),
: m_curveCoef(el.attribute("curveCoef").toDouble()),
m_sqrCoef(el.attribute("sqrCoef").toDouble()),
m_wienerSize(el.attribute("wienerSize").toInt()),
m_wienerCoef(el.attribute("wienerCoef").toDouble()),
m_knndRadius(el.attribute("knnDRadius").toInt()),
m_cdespeckleCoef(el.attribute("cdespeckle").toDouble()),
m_knndCoef(el.attribute("knnDenoiser").toDouble()),
m_cdespeckleRadius(el.attribute("cdespeckleRadius").toInt()),
m_cdespeckleCoef(el.attribute("cdespeckle").toDouble()),
m_blurSize(el.attribute("blurSize").toInt()),
m_blurCoef(el.attribute("blurCoef").toDouble()),
m_blurWindowSize(el.attribute("blurWinSize").toInt()),
m_screenSize(el.attribute("screenSize").toInt()),
m_screenCoef(el.attribute("screenCoef").toDouble()),
m_screenWindowSize(el.attribute("screenWinSize").toInt()),
m_curveCoef(el.attribute("curveCoef").toDouble()),
m_sqrCoef(el.attribute("sqrCoef").toDouble()),
m_gravureSize(el.attribute("gravureSize").toInt()),
m_gravureCoef(el.attribute("gravureCoef").toDouble()),
m_gravureWindowSize(el.attribute("gravureWinSize").toInt()),
m_unPaperCoef(el.attribute("unPaper").toDouble()),
m_unPaperIters(el.attribute("unPaperIters").toInt()),
m_unPaperCoef(el.attribute("unPaper").toDouble()),
m_normalizeCoef(el.attribute("normalizeCoef").toDouble()),
m_whiteMargins(el.attribute("whiteMargins") == "1"),
m_grayScale(el.attribute("grayScale") == "1")
{
if (m_curveCoef < -1.0 || m_curveCoef > 1.0)
{
m_curveCoef = 0.0;
}
if (m_sqrCoef < -1.0 || m_sqrCoef > 1.0)
{
m_sqrCoef = 0.0;
}
if (m_wienerSize < 1)
{
m_wienerSize = 2;
}
if (m_wienerCoef < 0.0 || m_wienerCoef > 1.0)
{
m_wienerCoef = 0.0;
}
if (m_wienerWindowSize < 3)
if (m_knndRadius < 1)
{
m_wienerWindowSize = 5;
m_knndRadius = 5;
}
if (m_knndCoef < 0.0 || m_knndCoef > 1.0)
{
m_knndCoef = 0.0;
}
if (m_knndRadius < 1)
if (m_cdespeckleRadius < 1)
{
m_knndRadius = 5;
m_cdespeckleRadius = 2;
}
if (m_cdespeckleCoef < -1.0 || m_cdespeckleCoef > 1.0)
{
m_cdespeckleCoef = 0.0;
}
if (m_cdespeckleRadius < 1)
if (m_blurSize < 1)
{
m_cdespeckleRadius = 5;
m_blurSize = 2;
}
if (m_blurCoef < -2.0 || m_blurCoef > 1.0)
{
m_blurCoef = 0.0;
}
if (m_blurWindowSize < 3)
if (m_screenSize < 1)
{
m_blurWindowSize = 5;
m_screenSize = 5;
}
if (m_screenCoef < -1.0 || m_screenCoef > 1.0)
{
m_screenCoef = 0.0;
}
if (m_screenWindowSize < 3)
{
m_screenWindowSize = 10;
}
if (m_curveCoef < -1.0 || m_curveCoef > 1.0)
if (m_gravureSize < 1)
{
m_curveCoef = 0.0;
}
if (m_sqrCoef < -1.0 || m_sqrCoef > 1.0)
{
m_sqrCoef = 0.0;
m_gravureSize = 5;
}
if (m_gravureCoef < -1.0 || m_gravureCoef > 1.0)
{
m_gravureCoef = 0.0;
}
if (m_gravureWindowSize < 3)
if (m_unPaperIters < 1)
{
m_gravureWindowSize = 10;
m_unPaperIters = 5;
}
if (m_unPaperCoef < 0.0 || m_unPaperCoef > 1.0)
{
m_unPaperCoef = 0.0;
}
if (m_unPaperIters < 1)
{
m_unPaperIters = 5;
}
if (m_normalizeCoef < 0.0 || m_normalizeCoef > 1.0)
{
m_normalizeCoef = 0.0;
Expand All @@ -119,20 +119,20 @@ QDomElement
ColorGrayscaleOptions::toXml(QDomDocument& doc, QString const& name) const
{
QDomElement el(doc.createElement(name));
el.setAttribute("curveCoef", m_curveCoef);
el.setAttribute("sqrCoef", m_sqrCoef);
el.setAttribute("wienerSize", m_wienerSize);
el.setAttribute("wienerCoef", m_wienerCoef);
el.setAttribute("wienerWinSize", m_wienerWindowSize);
el.setAttribute("knnDenoiser", m_knndCoef);
el.setAttribute("knnDRadius", m_knndRadius);
el.setAttribute("cdespeckle", m_cdespeckleCoef);
el.setAttribute("cdespeckleRadius", m_cdespeckleRadius);
el.setAttribute("blurSize", m_blurSize);
el.setAttribute("blurCoef", m_blurCoef);
el.setAttribute("blurWinSize", m_blurWindowSize);
el.setAttribute("screenSize", m_screenSize);
el.setAttribute("screenCoef", m_screenCoef);
el.setAttribute("screenWinSize", m_screenWindowSize);
el.setAttribute("curveCoef", m_curveCoef);
el.setAttribute("sqrCoef", m_sqrCoef);
el.setAttribute("gravureSize", m_screenSize);
el.setAttribute("gravureCoef", m_screenCoef);
el.setAttribute("gravureWinSize", m_screenWindowSize);
el.setAttribute("unPaper", m_unPaperCoef);
el.setAttribute("unPaperIters", m_unPaperIters);
el.setAttribute("normalizeCoef", m_normalizeCoef);
Expand All @@ -144,7 +144,7 @@ ColorGrayscaleOptions::toXml(QDomDocument& doc, QString const& name) const
bool
ColorGrayscaleOptions::operator==(ColorGrayscaleOptions const& other) const
{
if ((m_wienerCoef != other.m_wienerCoef) || (m_wienerWindowSize != other.m_wienerWindowSize))
if ((m_wienerCoef != other.m_wienerCoef) || (m_wienerSize != other.m_wienerSize))
{
return false;
}
Expand All @@ -156,11 +156,11 @@ ColorGrayscaleOptions::operator==(ColorGrayscaleOptions const& other) const
{
return false;
}
if ((m_blurCoef != other.m_blurCoef) || (m_blurWindowSize != other.m_blurWindowSize))
if ((m_blurCoef != other.m_blurCoef) || (m_blurSize != other.m_blurSize))
{
return false;
}
if ((m_screenCoef != other.m_screenCoef) || (m_screenWindowSize != other.m_screenWindowSize))
if ((m_screenCoef != other.m_screenCoef) || (m_screenSize != other.m_screenSize))
{
return false;
}
Expand All @@ -172,7 +172,7 @@ ColorGrayscaleOptions::operator==(ColorGrayscaleOptions const& other) const
{
return false;
}
if ((m_gravureCoef != other.m_gravureCoef) || (m_gravureWindowSize != other.m_gravureWindowSize))
if ((m_gravureCoef != other.m_gravureCoef) || (m_gravureSize != other.m_gravureSize))
{
return false;
}
Expand Down
Loading

1 comment on commit 51b8f42

@zvezdochiot
Copy link
Member Author

@zvezdochiot zvezdochiot commented on 51b8f42 May 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Ну, как говорится, "держи фашист гранату". Галюны гарантированы, зато теперь можно добавлять сколько влезет фильтров. ;)

Please sign in to comment.