Zadanie 6

This commit is contained in:
Sebastian Spaloniak 2020-05-12 00:36:00 +02:00
parent 633adec165
commit 3e1c4e8a00
5 changed files with 141 additions and 21 deletions

View File

@ -19,13 +19,17 @@ PNM* BinarizationManual::transform()
PNM* newImage = new PNM(width, height, QImage::Format_Mono);
for (int i=0; i<width; i++) {
for (int j=0; j<height; j++) {
for (int i=0; i<width; i++)
{
for (int j=0; j<height; j++)
{
int l = qGray(image->pixel(i,j));
if (l < threshold) {
if (l < threshold)
{
newImage->setPixel(i, j, Qt::color0);
} else {
} else
{
newImage->setPixel(i, j, Qt::color1);
}
}

View File

@ -10,9 +10,19 @@ NoiseBilateral::NoiseBilateral(PNM* img, ImageViewer* iv) :
{
}
int NoiseBilateral::trim(int value) {
if (value > 255){
value = 255;
}
else if (value < 0) {
value = 0;
}
return value;
}
PNM* NoiseBilateral::transform()
{
int width = image->width();
int width = image->width();
int height = image->height();
PNM* newImage = new PNM(width, height, image->format());
@ -20,29 +30,86 @@ PNM* NoiseBilateral::transform()
sigma_d = getParameter("sigma_d").toInt();
sigma_r = getParameter("sigma_r").toInt();
radius = sigma_d;
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
Mode mode = RepeatEdge;
QRgb pixel;
for (int x = 0; x<width; x++)
{
for (int y = 0; y<height; y++)
{
if (image->format() == QImage::Format_RGB32)
{
pixel = getPixel(x, y, mode);
int r = trim(calcVal(x, y, RChannel));
int g = trim(calcVal(x, y, GChannel));
int b = trim(calcVal(x, y, BChannel));
QColor newPixel = QColor(r, g, b);
newImage->setPixel(x, y, newPixel.rgb());
}
if (image->format() == QImage::Format_Indexed8)
{
int temp = calcVal(x, y, LChannel);
newImage->setPixel(x, y, temp);
}
}
}
return newImage;
}
int NoiseBilateral::calcVal(int x, int y, Channel channel)
{
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
int pix = image->pixel(x, y);
int size = radius * 2 + 1;
int pixv = 0;
math::matrix<float> win = getWindow(x, y, size, channel, Transformation::RepeatEdge);
if (channel == Channel::LChannel)
{
pixv = qGray(pix);
}
else if (channel == Channel::RChannel)
{
pixv = qRed(pix);
}
else if (channel == Channel::GChannel)
{
pixv = qGreen(pix);
}
else if (channel == Channel::BChannel)
{
pixv = qBlue(pix);
}
return 0;
double valc;
double vals;
double mucl;
double licz = 0;
double mian = 0;
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
valc = colorCloseness((int)win(i, j), pixv);
vals = spatialCloseness(QPoint(x - radius, y - radius), QPoint(x, y));
mucl = valc * vals;
licz += (win(i, j) *mucl);
mian += mucl;
}
}
int return_val = 0;
if (mian != 0){
return_val = (int)(licz / mian);
}
return return_val;
}
float NoiseBilateral::colorCloseness(int val1, int val2)
{
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return 0;
float E = 2.718281828459;
return (float)(E - ((pow((double)(val1 - val2), 2.0)) / (2.0 * pow((double)sigma_r, 2.0))));
}
float NoiseBilateral::spatialCloseness(QPoint point1, QPoint point2)
{
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return 0;
float E = 2.718281828459;
return (float)(E - ((pow(point1.x() - point2.x(), 2.0) + pow((point1.y() - point2.y()), 2.0)) / (2.0 * pow(sigma_d, 2.0))));
}

View File

@ -15,7 +15,7 @@ private:
int calcVal(int, int, Channel);
float colorCloseness(int, int);
float spatialCloseness(QPoint, QPoint);
int trim(int);
int sigma_d;
int sigma_r;
int radius;

View File

@ -10,23 +10,71 @@ NoiseMedian::NoiseMedian(PNM* img, ImageViewer* iv) :
{
}
int NoiseMedian::trim(int value) {
if (value > 255){
value = 255;
}
else if (value < 0) {
value = 0;
}
return value;
}
PNM* NoiseMedian::transform()
{
int width = image->width();
int width = image->width();
int height = image->height();
PNM* newImage = new PNM(width, height, image->format());
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
if (image->format() == QImage::Format_RGB32) {
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
QRgb pixel = getPixel(x, y, RepeatEdge);
int r = trim(getMedian(x, y, RChannel));
int g = trim(getMedian(x, y, GChannel));
int b = trim(getMedian(x, y, BChannel));
QColor newPixel = QColor(r, g, b);
newImage->setPixel(x, y, newPixel.rgb());
}
}
}
else if (image->format() == QImage::Format_Mono)
{
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
QRgb pixel = image->pixel(x, y);
int v = qGray(pixel);
v = trim(getMedian(x, y, LChannel));
newImage->setPixel(x, y, v);
}
}
}
return newImage;
}
int NoiseMedian::getMedian(int x, int y, Channel channel)
{
int radius = getParameter("radius").toInt();
radius = radius * 2 + 1;
math::matrix<float> window = getWindow(x, y, radius, channel, RepeatEdge);
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
QVector<double> values;
for (int i = 0; i < window.colno(); i++)
{
for (int j = 0; j < window.rowno(); j++)
{
values.append(window(i, j));
}
}
return 0;
qSort(values);
return values.takeAt(values.size() / 2);
}

View File

@ -13,6 +13,7 @@ public:
private:
int getMedian(int, int, Channel);
int trim(int);
};
#endif // NOISE_MEDIAN_H