fix merge

This commit is contained in:
Dawid_Kreft 2020-05-06 22:22:49 +02:00
commit 844acfab2a
12 changed files with 260 additions and 23 deletions

View File

@ -22,10 +22,43 @@ PNM* EdgeGradient::horizontalDetection()
PNM* EdgeGradient::transform() PNM* EdgeGradient::transform()
{ {
PNM* newImage = new PNM(image->width(), image->height(), image->format()); PNM* newImage = new PNM(image->width(), image->height(), image->format());
PNM* imageX;
imageX=verticalDetection();
PNM* imageY;
imageY=horizontalDetection();
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return newImage;
for(int i=0;i<image->width();i++)
{
for(int j=0;j<image->height();j++)
{
float imageX_red = qRed(imageX->pixel(i,j));
float imageX_green = qGreen(imageX->pixel(i,j));
float imageX_blue = qBlue(imageX->pixel(i,j));
float imageY_red = qRed(imageY->pixel(i,j));
float imageY_green = qGreen(imageY->pixel(i,j));
float imageY_blue = qBlue(imageY->pixel(i,j));
float ImageNew_red=getEdgeValue(imageX_red, imageY_red);
float ImageNew_green=getEdgeValue(imageX_green, imageY_green);
float ImageNew_blue=getEdgeValue(imageX_blue, imageY_blue);
newImage->setPixel(i,j, QColor(ImageNew_red, ImageNew_green, ImageNew_blue).rgb());
}
}
return newImage;
} }
float EdgeGradient::getEdgeValue(int x, int y)
{
return sqrt(pow(x,2)+pow(y,2));
}

View File

@ -10,6 +10,7 @@ public:
EdgeGradient(PNM*, ImageViewer*); EdgeGradient(PNM*, ImageViewer*);
virtual PNM* transform(); virtual PNM* transform();
static float getEdgeValue(int, int);
PNM* verticalDetection(); PNM* verticalDetection();
PNM* horizontalDetection(); PNM* horizontalDetection();

View File

@ -14,8 +14,15 @@ math::matrix<float> EdgeLaplacian::getMask(int, Mode)
{ {
int size = getParameter("size").toInt(); int size = getParameter("size").toInt();
math::matrix<float> mask(size, size); math::matrix<float> mask(size, size);
int r=size/2;
for (int x=0; x<size; x++)
for (int y=0; y<size; y++)
mask[x][y]=-1;
mask[r][r]=(size*size)-1;
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return mask; return mask;
} }

View File

@ -18,17 +18,24 @@ math::matrix<float> EdgeLaplaceOfGauss::getMask(int, Mode)
double sigma = getParameter("sigma").toDouble(); double sigma = getParameter("sigma").toDouble();
math::matrix<float> mask(size, size); math::matrix<float> mask(size, size);
int r=size/2;
for(int i=0;i<size;i++)
for(int j=0;j<size;j++)
mask[i][j]=getLoG(i-r, j-r, sigma);
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return mask; return mask;
} }
float EdgeLaplaceOfGauss::getLoG(int x, int y, float s) float EdgeLaplaceOfGauss::getLoG(int x, int y, float s)
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return 0; float results;
results=(((pow(x,2)+pow(y,2))-2)/pow(s,2))*BlurGaussian::getGauss(x,y,s);
return results;
} }
int EdgeLaplaceOfGauss::getSize() int EdgeLaplaceOfGauss::getSize()

View File

@ -14,6 +14,36 @@ EdgePrewitt::EdgePrewitt(PNM*img, ImageViewer* iv) :
void EdgePrewitt::prepareMatrices() void EdgePrewitt::prepareMatrices()
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; int size = 3;
this->g_x = math::matrix<float>(size,size);
this->g_y = math::matrix<float>(size,size);
g_x[0][0]=-1;
g_x[0][1]=0;
g_x[0][2]=1;
g_x[1][0]=-1;
g_x[1][1]=0;
g_x[1][2]=1;
g_x[2][0]=-1;
g_x[2][1]=-0;
g_x[2][2]=1;
g_y[0][0]=-1;
g_y[0][1]=-1;
g_y[0][2]=-1;
g_y[1][0]=0;
g_y[1][1]=0;
g_y[1][2]=0;
g_y[2][0]=1;
g_y[2][1]=1;
g_y[2][2]=1;
} }

View File

@ -15,6 +15,22 @@ EdgeRoberts::EdgeRoberts(PNM* img, ImageViewer* iv) :
void EdgeRoberts::prepareMatrices() void EdgeRoberts::prepareMatrices()
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; int size = 2;
this->g_x = math::matrix<float>(size,size);
this->g_y = math::matrix<float>(size,size);
g_x[0][0]=1;
g_x[0][1]=0;
g_x[1][0]=0;
g_x[1][1]=-1;
g_y[0][0]=0;
g_y[0][1]=1;
g_y[1][0]=-1;
g_y[1][1]=0;
} }

View File

@ -14,7 +14,6 @@ EdgeSobel::EdgeSobel(PNM* img) :
void EdgeSobel::prepareMatrices() void EdgeSobel::prepareMatrices()
{ {
qDebug() << Q_FUNC_INFO << "Preparing matrix";
int size = 3; int size = 3;
g_x = math::matrix<float>(size,size); g_x = math::matrix<float>(size,size);
g_y = math::matrix<float>(size,size); g_y = math::matrix<float>(size,size);
@ -38,6 +37,7 @@ void EdgeSobel::prepareMatrices()
g_y(2, 0) = 1; g_y(2, 0) = 1;
g_y(2, 1) = 2; g_y(2, 1) = 2;
g_y(2, 2) = 1; g_y(2, 2) = 1;
} }
math::matrix<float>* EdgeSobel::rawHorizontalDetection() math::matrix<float>* EdgeSobel::rawHorizontalDetection()

View File

@ -20,11 +20,66 @@ PNM* EdgeZeroCrossing::transform()
int size = getParameter("size").toInt(); int size = getParameter("size").toInt();
double sigma = getParameter("sigma").toDouble(); double sigma = getParameter("sigma").toDouble();
int t = getParameter("threshold").toInt(); int t = getParameter("threshold").toInt();
int v = 128;
int r=size/2;
PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8); PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; EdgeLaplaceOfGauss * gaussImage = new EdgeLaplaceOfGauss(image);
for (int x=0; x<width; x++)
for (int y=0; y<height; y++)
{
math::matrix<float> wR = gaussImage->getWindow(x,y,size,RChannel,CyclicEdge);
math::matrix<float> wB = gaussImage->getWindow(x,y,size,BChannel,CyclicEdge);
math::matrix<float> wG = gaussImage->getWindow(x,y,size,GChannel,CyclicEdge);
float maxR=maxValue(wR,size);
float maxG=maxValue(wG,size);
float maxB=maxValue(wB,size);
float minR=minValue(wR,size);
float minG=minValue(wG,size);
float minB=minValue(wB,size);
if (minR < v-t && maxR > v+t)
newImage->setPixel(x, y,gaussImage->getPixel(x,y,CyclicEdge));
else if (minG < v-t && maxG>v+t)
newImage->setPixel(x, y, gaussImage->getPixel(x,y,CyclicEdge));
else if (minB < v-t && maxB > v+t)
newImage->setPixel(x, y, gaussImage->getPixel(x,y,CyclicEdge));
else
{
newImage->setPixel(x, y, 0);
}
}
return newImage; return newImage;
} }
float EdgeZeroCrossing::maxValue(math::matrix<float> mask, int size)
{
float max=mask[0][0];
for (int x=0; x<size; x++)
for (int y=0; y<size; y++)
if (mask[x][y] > max)
max=mask[x][y];
return max;
}
float EdgeZeroCrossing::minValue(math::matrix<float> mask, int size)
{
float min=mask[0][0];
for (int x=0; x<size; x++)
for (int y=0; y<size; y++)
if (mask[x][y] < min)
min=mask[x][y];
return min;
}

View File

@ -10,6 +10,8 @@ public:
EdgeZeroCrossing(PNM*, ImageViewer*); EdgeZeroCrossing(PNM*, ImageViewer*);
virtual PNM* transform(); virtual PNM* transform();
float maxValue(math::matrix<float> mask, int size);
float minValue(math::matrix<float> mask, int size);
}; };
#endif // EDGE_ZERO_H #endif // EDGE_ZERO_H

View File

@ -21,28 +21,73 @@ PNM* NoiseBilateral::transform()
sigma_r = getParameter("sigma_r").toInt(); sigma_r = getParameter("sigma_r").toInt();
radius = sigma_d; radius = sigma_d;
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; for(int x = 0 ; x < width; x++){
for (int y = 0 ; y < height; y++) {
int g = calcVal(x,y, GChannel);
int r = calcVal(x,y, RChannel);
int b = calcVal(x,y, BChannel);
newImage->setPixel(x,y,QColor(r,g,b).rgba());
}
}
return newImage; return newImage;
} }
int NoiseBilateral::calcVal(int x, int y, Channel channel) int NoiseBilateral::calcVal(int x, int y, Channel channel)
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; double sumNumerator = 0;
double sumDenominator = 0;
return 0; double colorClosenes = 0;
double spatialClosennes = 0;
int colorValue;
int colorValueRef;
for ( int i = x- radius ; i <= x+radius ; i++) {
for ( int j = y- radius ; j <= y+radius ; j++) {
if ( i+radius >= image->width() ||
i-radius < 0 ||
j+radius >= image->height() ||
j-radius < 0 ) {
continue;
}
if (channel==LChannel){
colorValue = qAlpha(image->pixel(i,j));
colorValueRef = qAlpha(image->pixel(x,y));
}
if (channel==RChannel){
colorValue = (qRed(image->pixel(i,j)));
colorValueRef = qRed(image->pixel(x,y));
}
if (channel==GChannel){
colorValueRef = qGreen(image->pixel(x,y));
colorValue = (qGreen(image->pixel(i,j)));
}
if (channel==BChannel){
colorValueRef = qBlue(image->pixel(x,y));
colorValue = ( qBlue(image->pixel(i,j)));
}
colorClosenes = colorCloseness(colorValue,colorValueRef);
spatialClosennes = spatialCloseness( QPoint(i,j),QPoint(x,y));
sumNumerator = sumNumerator +( colorValue* colorClosenes * spatialClosennes);
sumDenominator =sumDenominator + ( colorClosenes * spatialClosennes);
}
}
return sumNumerator/sumDenominator;
} }
float NoiseBilateral::colorCloseness(int val1, int val2) float NoiseBilateral::colorCloseness(int val1, int val2)
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; return exp(-(((val1-val2)^2)/(2*sigma_r^2)));
return 0;
} }
float NoiseBilateral::spatialCloseness(QPoint point1, QPoint point2) float NoiseBilateral::spatialCloseness(QPoint point1, QPoint point2)
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; return exp(-((point1.x() - point2.x())^2 + ( point1.y() - point2.y())^2)/(2*sigma_d^2));
return 0;
} }

View File

@ -17,16 +17,57 @@ PNM* NoiseMedian::transform()
PNM* newImage = new PNM(width, height, image->format()); PNM* newImage = new PNM(width, height, image->format());
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; for(int x = 0 ; x < width; x++){
for (int y = 0 ; y < height; y++) {
int g = getMedian(x,y, GChannel);
int r = getMedian(x,y, RChannel);
int b = getMedian(x,y, BChannel);
newImage->setPixel(x,y,QColor(r,g,b).rgba());
}
}
return newImage; return newImage;
} }
int NoiseMedian::getMedian(int x, int y, Channel channel) int NoiseMedian::getMedian(int x, int y, Channel channel)
{ {
int radius = getParameter("radius").toInt(); int radius = getParameter("radius").toInt();
QSet<int> set;
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; QList<int> list = QList<int>::fromSet(set);
std::sort(list.begin(), list.end());
return 0;
for ( int i = x- radius ; i <= x+radius ; i++) {
for ( int j = y- radius ; j <= y+radius ; j++) {
if ( i+radius >= image->width() ||
i-radius < 0 ||
j+radius >= image->height() ||
j-radius < 0 ) {
continue;
}
if (channel==LChannel) set.insert(qAlpha(image->pixel(i,j)));
if (channel==RChannel) set.insert(qRed(image->pixel(i,j)));
if (channel==GChannel) set.insert(qGreen(image->pixel(i,j)));
if (channel==BChannel) set.insert( qBlue(image->pixel(i,j)));
}
}
QList<int> data = QList<int>::fromSet(set);
std::sort(data.begin(), data.end());
int result =0 ;
if( data.size() %2 == 1){
result = data.at(data.size()/2);
}else if(data.size()>3){
int first_med = data.at((data.size()/2 )-1);
int sec_dem = data.at((data.size()/2 ));
result = (first_med+sec_dem)/2;
}
data.clear();
set.clear();
return result;
} }