Compare commits

..

No commits in common. "master" and "Zadanie_03_Dawid" have entirely different histories.

26 changed files with 80 additions and 998 deletions

View File

@ -17,42 +17,8 @@ PNM* BinarizationGradient::transform()
PNM* newImage = new PNM(width, height, QImage::Format_Mono);
int Gmax = 0;
int numerator = 0;
int denominator = 0;
for(int x=1; x<width-1; x++){
for(int y=1; y<height-1; y++){
int t = (qRed(image->pixel(x,y)) + qGreen(image->pixel(x,y)) + qBlue(image->pixel(x,y))) / 3;
int Gxa = (qRed(image->pixel(x-1,y)) + qGreen(image->pixel(x-1,y)) + qBlue(image->pixel(x-1,y))) / 3;
int Gxb = (qRed(image->pixel(x+1,y)) + qGreen(image->pixel(x+1,y)) + qBlue(image->pixel(x+1,y))) / 3;
int Gya = (qRed(image->pixel(x,y+1)) + qGreen(image->pixel(x,y+1)) + qBlue(image->pixel(x,y+1))) / 3;
int Gyb= (qRed(image->pixel(x,y-1)) + qGreen(image->pixel(x,y-1)) + qBlue(image->pixel(x,y-1))) / 3;
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
int Gx = Gxa - Gxb;
int Gy = Gya - Gyb;
if (Gx > Gy) Gmax = Gx;
else Gmax = Gy;
numerator += t * Gmax;
denominator += Gmax;
}
}
int T = numerator/denominator;
// create new image
for(int i=0; i<width; i++){
for(int j=0; j<height; j++){
QRgb pixel = image->pixel(i,j);
int tempValue = (qRed(pixel) + qGreen(pixel) + qBlue(pixel)) / 3;
if ( tempValue > T ){
newImage->setPixel(i, j, Qt::color1);
}
else {
newImage->setPixel(i, j, Qt::color0);
}
}
}
return newImage;
}

View File

@ -18,31 +18,22 @@ PNM* BlurGaussian::transform()
radius = (size/2)+1;
sigma = getParameter("sigma").toDouble();
return convolute(getMask(size, Normalize), CyclicEdge);
return convolute(getMask(size, Normalize), RepeatEdge);
}
math::matrix<float> BlurGaussian::getMask(int size, Mode)
{
math::matrix<float> mask(size, size);
if(size%2!=0) radius=size/2;
for(int i=-radius;i<=radius;i++)
{
for(int j=-radius;j<=radius;j++)
{
mask[i+radius][j+radius]=getGauss(i,j,sigma);
}
}
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return mask;
}
float BlurGaussian::getGauss(int x, int y, float sigma)
{
{
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
float gauss= exp(-(x*x+y*y)/(2*sigma*sigma))/(2*M_PI*sigma*sigma);
return gauss;
return 0;
}

View File

@ -13,29 +13,12 @@ BlurLinear::BlurLinear(PNM* img, ImageViewer* iv) :
PNM* BlurLinear::transform()
{
int maskSize = getParameter("size").toInt();
QList<QVariant> tmpMask = getParameter("mask").toList();
bool normalize = getParameter("normalize").toBool();
QList<QVariant> tmpMask = getParameter("mask").toList();
bool normalize = getParameter("normalize").toBool();
math::matrix<float> mask(maskSize, maskSize);
math::matrix<float> mask(maskSize, maskSize);
int index = 0;
float sum = 0;
for (int x = 0; x < maskSize; x++) {
for (int y = 0; y < maskSize; y++) {
mask[x][y] = tmpMask.at(index).toDouble();
index++;
sum = sum + mask[x][y];
}
}
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
if(normalize == true && sum != 0.0 ){
for (int x = 0; x < maskSize; x++) {
for (int y = 0; y < maskSize; y++) {
mask[x][y] = mask[x][y] / sum;
}
}
}
return convolute(mask, CyclicEdge);
return convolute(mask, RepeatEdge);
}

View File

@ -14,15 +14,7 @@ math::matrix<float> BlurUniform::getMask(int size, Mode)
{
math::matrix<float> mask(size, size);
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
mask[i][j]=1.00;
}
}
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return mask;
}

View File

@ -22,111 +22,24 @@ math::matrix<float> Convolution::getMask(int size, Mode mode = Normalize)
{
math::matrix<float> mask(size, size);
for (int x=0; x<size; x++)
for (int y=0; y<size; y++)
{
mask[x][y] = 0;
}
int half=size/2;
mask[half][half]=1;
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return mask;
}
/** Does the convolution process for all pixels using the given mask. */
PNM* Convolution::convolute(math::matrix<float> mask, Mode mode = CyclicEdge)
PNM* Convolution::convolute(math::matrix<float> mask, Mode mode = RepeatEdge)
{
int width = image->width(),
height = image->height();
int size=mask.rowno();
PNM* newImage = new PNM(width, height, image->format());
math::matrix<float> red_window(size, size);
math::matrix<float> blue_window(size, size);
math::matrix<float> gray_window(size, size);
math::matrix<float> green_window(size, size);
float mask_weight=sum(mask);
float red_sum;
float green_sum;
float blue_sum;
float gray_sum;
for (int x=0; x<width; x++)
for (int y=0; y<height; y++)
{
if (image->format() == QImage::Format_Indexed8)
gray_window=getWindow(x,y,size,LChannel,mode);
else{
red_window=getWindow(x,y,size,RChannel,mode);
blue_window=getWindow(x,y,size,BChannel,mode);
green_window=getWindow(x,y,size,GChannel,mode);
}
if (image->format() == QImage::Format_Indexed8){
gray_window=join(gray_window,mask);
}else{
red_window=join(red_window,mask);
blue_window=join(blue_window,mask);
green_window=join(green_window,mask);
}
if (image->format() == QImage::Format_Indexed8){
gray_sum=sum(gray_window);
}else{
red_sum=sum(red_window);
green_sum=sum(green_window);
blue_sum=sum(blue_window);
}
if(mask_weight>0)
{
if (image->format() == QImage::Format_Indexed8){
gray_sum=gray_sum/mask_weight;
}
else{
red_sum=red_sum/mask_weight;
blue_sum=blue_sum/mask_weight;
green_sum=green_sum/mask_weight;
}
}
if (image->format() == QImage::Format_Indexed8) {
newImage->setPixel(x, y, validateValue(gray_sum));
}
else {
newImage->setPixel(x,y, QColor(validateValue(red_sum),validateValue(green_sum),validateValue(blue_sum)).rgb());
}
}
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return newImage;
}
int Convolution::validateValue(int value){
if (value > 255) {
return 255;
}
else if (value < 0) {
return 0;
}
return value;
}
/** Joins to matrices by multiplying the A[i,j] with B[i,j].
* Warning! Both Matrices must be squares with the same size!
*/
@ -135,12 +48,7 @@ const math::matrix<float> Convolution::join(math::matrix<float> A, math::matrix<
int size = A.rowno();
math::matrix<float> C(size, size);
for (int x=0; x<size; x++)
for (int y=0; y<size; y++)
{
C[x][y]=A[x][y]*B[x][y];
}
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return C;
}
@ -150,15 +58,10 @@ const float Convolution::sum(const math::matrix<float> A)
{
float sum = 0.0;
for (int x=0; x<A.rowno(); x++)
for (int y=0; y<A.colno(); y++)
{
sum=sum+A[x][y];
}
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return sum;
}
@ -167,19 +70,8 @@ const math::matrix<float> Convolution::reflection(const math::matrix<float> A)
{
int size = A.rowno();
math::matrix<float> C(size, size);
int counter_i=0;
int counter_j=0;
for (int x = 0; x < size; x++)
{
for (int y = 0; y < size; y++)
{
C(size - x, size - y) = A(x, y);
}
}
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return C;
}

View File

@ -18,7 +18,6 @@ protected:
const math::matrix<float> join(math::matrix<float>, math::matrix<float>);
const float sum(math::matrix<float>);
const math::matrix<float> reflection(math::matrix<float>);
int validateValue(int);
};
#endif // CONVOLUTION_H

View File

@ -24,115 +24,9 @@ PNM* CornerHarris::transform()
int width = image->width(),
height = image->height();
//Krok1 Zdef i wypelij zerami
math::matrix<float> Ixx(width, height);
math::matrix<float> Iyy(width, height);
math::matrix<float> Ixy(width, height);
math::matrix<float> CC(width, height);
math::matrix<float> CNS(width, height);
for (int x=0; x<width; x++)
for (int y=0; y<height; y++)
{
Ixx[x][y]=0;
Iyy[x][y]=0;
Ixy[x][y]=0;
CC[x][y]=0;
CNS[x][y]=0;
}
//Krok 2 skala szarosci
ConversionGrayscale cg(image);
PNM* gray_image=cg.transform();
//Krok 3 rozmyj
BlurGaussian bg(gray_image);
bg.setParameter("size",3);
bg.setParameter("sigma",1.6);
PNM* blur_image=bg.transform();
//Krok 4 sobel
EdgeSobel es(blur_image);
math::matrix<float> *Gx=es.rawHorizontalDetection();
math::matrix<float> *Gy=es.rawVerticalDetection();
//Krok 5 wzorek
for (int x=0; x<width; x++)
for (int y=0; y<height; y++)
{
Ixx[x][y]=(*Gx)[x][y] * (*Gx)[x][y];
Iyy[x][y]=(*Gy)[x][y] * (*Gy)[x][y];
Ixy[x][y]=(*Gx)[x][y] * (*Gy)[x][y];
}
//Krok 6 wzorek
for (int x=1; x<width-1; x++)
for (int y=1; y<height-1; y++)
{
float Sxx=0;
float Syy=0;
float Sxy=0;
math::matrix<float> H(2, 2);
for(int z=-1;z<=1;z++) //Znacznik sumy
for(int a=-1;a<=1;a++)
{
Sxx+=Ixx[x+z][y+a]*BlurGaussian::getGauss(z,a,sigma);
Syy+=Iyy[x+z][y+a]*BlurGaussian::getGauss(z,a,sigma);
Sxy+=Ixy[x+z][y+a]*BlurGaussian::getGauss(z,a,sigma);
}
Sxx=Sxx/sigma_weight;
Syy=Syy/sigma_weight;
Sxy=Sxy/sigma_weight;
H[0][0]=Sxx;
H[0][1]=Sxy;
H[1][0]=Sxy;
H[1][1]=Syy;
float detH=H[0][0]*H[1][1]-H[0][1]*H[1][0];
//Wyznaczkik + suma po przekatnej kwadratowej
float r = detH - k_param * pow(H[0][0] + H[1][1], 2);
if(r>threshold) CC[x][y]=r;
}
bool search=1;
//Krok 8
while(search==1)
{
search=0;
for (int x=1; x<width-1; x++)
for (int y=1; y<height-1; y++)
{
float max=CC[x][y];
if(max > CC[x][y-1] && max > CC[x][y+1] && max > CC[x+1][y-1] && max > CC[x+1][y] && max > CC[x+1][y+1] && max > CC[x-1][y-1] && max > CC[x-1][y] && max > CC[x-1][y+1])
CNS[x][y]=CC[x][y];
else {
if(CC[x][y]>0)
{
CNS[x][y]=0;
search=1;
}
}
}
CC=CNS;
}
PNM* newImage = new PNM(width, height, QImage::Format_Mono);
//Krok 9
for (int x=1; x<width-1; x++)
for (int y=1; y<height-1; y++)
{
if(CC[x][y]==0) newImage->setPixel(x,y,0);
else newImage->setPixel(x,y,1);
}
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return newImage;
}

View File

@ -23,192 +23,8 @@ PNM* EdgeCanny::transform()
lower_thresh = getParameter("lower_threshold").toInt();
PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
QPoint point_vector[7] = {
QPoint(-1, 0),
QPoint(-1, 1),
QPoint(0, -1),
QPoint(0, 1),
QPoint(1, -1),
QPoint(1, 0),
QPoint(1, 1),
};
// step 1
PNM* tmpImage = new PNM(width, height, QImage::Format_Indexed8);
tmpImage = ConversionGrayscale(image).transform();
// step 2
BlurGaussian gaus(tmpImage);
gaus.setParameter("sigma", 1.6);
gaus.setParameter("size", 3);
tmpImage = gaus.transform();
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
// step 3
EdgeSobel sobel(tmpImage);
math::matrix<float>* Gx = sobel.rawHorizontalDetection();
math::matrix<float>* Gy = sobel.rawVerticalDetection();
//step 4
math::matrix<float> direction = math::matrix<float>(width, height);
math::matrix<float> power = math::matrix<float>(width, height);
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
newImage->setPixel(i, j, PIXEL_VAL_MIN);
power(i, j) = sqrt(pow((*Gx)(i, j), 2) + pow((*Gy)(i, j), 2));
direction(i, j) = (int)((atan2 ((*Gy)(i, j), (*Gx)(i, j)) / (3.142)) * 180 + 360) % 360;
}
}
//step 5
std::list<QPoint> initialPoints;
for (int i = 1; i < width - 1; i++)
{
for (int j = 1; j < height - 1; j++)
{
int pos = direction(i, j);
QPoint point1;
QPoint point2;
if (getOrient(pos) == 0)
{
point1 = QPoint(0, -1);
point2 = QPoint(0, 1);
}
else if (getOrient(pos) == 1)
{
point1 = QPoint(1, -1);
point2 = QPoint(-1, 1);
}
else if (getOrient(pos) == 2)
{
point1 = QPoint(-1, 0);
point2 = QPoint(1, 0);
}
else if (getOrient(pos) == 3)
{
point1 = QPoint(-1, -1);
point2 = QPoint(1, 1);
}
double temp1 = power(i + point1.x(), j + point1.y());
double temp2= power(i + point2.x(), j + point2.y());
if (power(i, j) > temp1 && power(i, j) > temp2 &&power(i, j) > upper_thresh)
{
newImage->setPixel(i, j, PIXEL_VAL_MAX);
initialPoints.push_back(QPoint(i, j));
}
}
}
//step 6
while (!initialPoints.empty())
{
QPoint point = initialPoints.back();
initialPoints.pop_back();
int pos = direction(point.x(), point.y());
for (int i = 1; i <= 2; i++)
{
int x,y;
if ( i == 1)
{
if (getOrient(pos) == 0)
{
x= 0;
y= -1;
}
else if (getOrient(pos) == 1)
{
x= 1;
y= -1;
}
else if (getOrient(pos) == 2)
{
x= -1;
y= 1;
}
else if (getOrient(pos) == 3)
{
x= -1;
y= -1;
}
}
else
{
if (getOrient(pos) == 0)
{
x= 0;
y= 1;
}
else if (getOrient(pos) == 1)
{
x= -1;
y= 1;
}
else if (getOrient(pos) == 2)
{
x= 1;
y= 0;
}
else if (getOrient(pos) == 3)
{
x= 1;
y= 1;
}
}
QPoint cPoint = point;
while (true)
{
QPoint point_ = QPoint(cPoint.x() + x, cPoint.y() + y);
if (point_.x() == width - 1 || point_.x() == 0 || point_.y() == height - 1 || point_.y() == 0) break;
if (newImage->pixel(point_.x(), point_.y()) == PIXEL_VAL_MAX) break;
if (power(point_.x(), point_.y()) < lower_thresh) break;
if (getOrient((int)direction(point_.x(), point_.y())) != getOrient(pos)) break;
bool flag = true;
for (int i = 0; i < 7; i++)
{
QPoint point(point_.x() + point_vector[i].x(), point_.y() + point_vector[i].y());
if (point.x() == cPoint.x() && point.y() == cPoint.y()) continue;
if (getOrient((int)direction(point.x(), point.y())) != getOrient(pos)) continue;
if (power(point.x(), point.y()) >= power(point_.x(), point_.y()))
{
flag= false;
break;
}
}
if (!flag) break;
newImage->setPixel(point_.x(), point_.y(), PIXEL_VAL_MAX);
cPoint = point_;
}
}
}
return newImage;
}
int EdgeCanny::getOrient(int currentDirection){
if ((currentDirection >= 0 && currentDirection < 23) || (currentDirection >= 158 && currentDirection < 203) || (currentDirection >= 338 && currentDirection < 361))
{
return 0;
}
if ((currentDirection >= 23 && currentDirection < 68) || (currentDirection >= 203 && currentDirection < 248))
{
return 1;
}
if ((currentDirection >= 68 && currentDirection < 113) || (currentDirection >= 248 && currentDirection < 293))
{
return 2;
}
if ((currentDirection >= 113 && currentDirection < 158) || (currentDirection >= 293 && currentDirection < 338))
{
return 3;
}
return -1;
}

View File

@ -8,14 +8,12 @@ class EdgeCanny : public Convolution
public:
EdgeCanny(PNM*);
EdgeCanny(PNM*, ImageViewer*);
int getOrient(int);
virtual PNM* transform();
private:
};
#endif // EDGECANNY_H

View File

@ -22,43 +22,10 @@ PNM* EdgeGradient::horizontalDetection()
PNM* EdgeGradient::transform()
{
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!";
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;
return newImage;
}
float EdgeGradient::getEdgeValue(int x, int y)
{
return sqrt(pow(x,2)+pow(y,2));
}

View File

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

View File

@ -10,22 +10,12 @@ EdgeLaplacian::EdgeLaplacian(PNM* img, ImageViewer* iv) :
{
}
math::matrix<float> EdgeLaplacian::getMask(int size , Mode)
math::matrix<float> EdgeLaplacian::getMask(int, Mode)
{
if( getParameter("size").toInt() > size )
size =getParameter("size").toInt();
int size = getParameter("size").toInt();
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;
}

View File

@ -12,33 +12,23 @@ EdgeLaplaceOfGauss::EdgeLaplaceOfGauss(PNM* img, ImageViewer* iv) :
{
}
math::matrix<float> EdgeLaplaceOfGauss::getMask(int size, Mode)
math::matrix<float> EdgeLaplaceOfGauss::getMask(int, Mode)
{
if( getParameter("size").toInt() > size )
size =getParameter("size").toInt();
size = getParameter("size").toInt();
double sigma = getParameter("sigma").toDouble();
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;
}
float EdgeLaplaceOfGauss::getLoG(int x, int y, float s)
{
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
float results;
results=(((pow(x,2)+pow(y,2))-2)/pow(s,2))*BlurGaussian::getGauss(x,y,s);
return results;
return 0;
}
int EdgeLaplaceOfGauss::getSize()

View File

@ -14,36 +14,6 @@ EdgePrewitt::EdgePrewitt(PNM*img, ImageViewer* iv) :
void EdgePrewitt::prepareMatrices()
{
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;
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
}

View File

@ -14,23 +14,5 @@ EdgeRoberts::EdgeRoberts(PNM* img, ImageViewer* iv) :
void EdgeRoberts::prepareMatrices()
{
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;
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
}

View File

@ -14,67 +14,23 @@ EdgeSobel::EdgeSobel(PNM* img) :
void EdgeSobel::prepareMatrices()
{
int size = 3;
g_x = math::matrix<float>(size,size);
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) = -2;
g_x(1, 1) = 0;
g_x(1, 2) = 2;
g_x(2, 0) = -1;
g_x(2, 1) = 0;
g_x(2, 2) = 1;
g_y(0, 0) = -1;
g_y(0, 1) = -2;
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) = 2;
g_y(2, 2) = 1;
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
}
math::matrix<float>* EdgeSobel::rawHorizontalDetection()
{
math::matrix<float>* x_gradient = new math::matrix<float>(this->image->width(), this->image->height());
int width = x_gradient->rowno();
int height = x_gradient->colno();
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
math::matrix<float> temp = getWindow(x, y, 3, LChannel, NullEdge);
(*x_gradient)(x, y) = Convolution::sum(Convolution::join(g_x, temp));
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
}
}
return x_gradient;
return x_gradient;
}
math::matrix<float>* EdgeSobel::rawVerticalDetection()
{
math::matrix<float>* y_gradient = new math::matrix<float>(this->image->width(), this->image->height());
int width = y_gradient->rowno();
int height = y_gradient->colno();
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
math::matrix<float> temp = getWindow(x, y, 3, LChannel, NullEdge);
(*y_gradient)(x, y) = Convolution::sum(Convolution::join(g_x, temp));
}
}
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return y_gradient;
}

View File

@ -20,66 +20,11 @@ PNM* EdgeZeroCrossing::transform()
int size = getParameter("size").toInt();
double sigma = getParameter("sigma").toDouble();
int t = getParameter("threshold").toInt();
int v = 128;
int r=size/2;
PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
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);
}
}
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
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,8 +10,6 @@ public:
EdgeZeroCrossing(PNM*, ImageViewer*);
virtual PNM* transform();
float maxValue(math::matrix<float> mask, int size);
float minValue(math::matrix<float> mask, int size);
};
#endif // EDGE_ZERO_H

View File

@ -17,50 +17,7 @@ PNM* Hough::transform()
{
int thetaDensity = getParameter("theta_density").toInt();
int width = image->width();
int height = image->height();
PNM* tempImage = new PNM(width, height, QImage::Format_Indexed8);
tempImage = ConversionGrayscale(image).transform();
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
if (!getParameter("skip_edge_detection").toBool()) {
tempImage = EdgeLaplacian(tempImage).transform();
}
int pmax =int(sqrt(height*height + width*width));
int thetaSize= 180 * thetaDensity;
int lenght = pmax * 2 + 1;
double theta, p;
int max = 0;
math::matrix<int> hough(thetaSize,lenght);
for (int i = 0; i < thetaSize; i++) {
for (int j = 0 ; j < lenght ; j++) {
hough[i][j] = 0;
}
}
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
if (qGray(tempImage->pixel(i, j)) > 0) {
for (int k = 0; k < thetaSize; k++) {
theta = (k * 3.14) / (180 * thetaDensity);
p = i*cos(theta) + j*sin(theta);
hough[k][p+pmax]++;
if (hough[k][p+pmax] > max) {
max = hough[k][p+pmax];
}
}
}
}
}
PNM* newImage = new PNM(thetaSize,lenght, QImage::Format_Grayscale8);
for (int i = 0; i < thetaSize; i++) {
for (int j = 0; j < lenght; j++) {
int value = int(((hough[i][j] * 255)/ max));
newImage->setPixel(i, j, QColor(value,value,value).rgb());
}
}
return newImage;
return 0;
}

View File

@ -24,34 +24,7 @@ PNM* HoughLines::transform()
PNM* newImage = new PNM(image->copy());
// step 1
EdgeLaplacian* edgeLA = new EdgeLaplacian(image);
edgeLA->setParameter("size", 3);
PNM* tempImage = edgeLA->transform();
// step 2
BinarizationGradient* binarizationGradient = new BinarizationGradient(tempImage);
PNM* binImage = binarizationGradient->transform();
// step 3
Hough* hough = new Hough(binImage);
hough->setParameter("theta_density", 3);
hough->setParameter("skip_edge_detection", true);
tempImage = hough->transform();
// step 4
QPainter p(newImage);
p.setPen(Qt::red);
for(int i=0; i < tempImage->width(); i++) {
for(int j=0; j < tempImage->height(); j++) {
if(qGray(tempImage->pixel(i, j)) > threshold) {
double rtheta = ((double)i/3.0)*M_PI/180.0;
int rrho = j - tempImage->height()/2;
p.drawLine(0, round(rrho/sin(rtheta)), newImage->width()-1, round((rrho - (newImage->width()-1)*cos(rtheta))/sin(rtheta)));
}
if (!drawWholeLines == true){
if (qRed(binImage->pixel(i, j)) == 0){
newImage->setPixel(i, j, image->pixel(i, j));
}
}
}
}
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return newImage;
}

View File

@ -1,6 +1,5 @@
#include "map_height.h"
#include "conversion_grayscale.h"
\
MapHeight::MapHeight(PNM* img) :
Transformation(img)
{
@ -16,8 +15,9 @@ PNM* MapHeight::transform()
int width = image->width(),
height = image->height();
ConversionGrayscale *conv = new ConversionGrayscale(image);
PNM* img = conv->transform();
PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
return img ;
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return newImage;
}

View File

@ -34,33 +34,8 @@ PNM* MapHorizon::transform()
}
PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
PNM* mapHeight = MapHeight(image).transform();
for (int x = 0; x<width; x++){
for (int y = 0; y<height; y++){
float alfa = 0.0;
int redValue = qRed(mapHeight->pixel(x, y));
for (int n = x + dx; n < width; n = n + dx){
for (int m = y+ dy ; m < height; m = m+dy) {
if(m >= 0 && n >=0 && n < width && m < height ){
int redTempValue = qRed(mapHeight->pixel(n, m));
if (redValue < redTempValue){
float dis = sqrt(pow(n - x, 2) + pow(m - y, 2)) * scale;
float ra = atan((redTempValue - redValue) / dis) * 180 / 3.14;
if (ra > alfa){
alfa = ra;
}
}
}
}
}
float delta = alfa - sun_alpha;
if (delta <= 0){
newImage->setPixel(x, y, 255);
}
else{
newImage->setPixel(x, y, cos(delta * 3.14 / 180) * 255);
}
}
}
return newImage;
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return newImage;
}

View File

@ -21,31 +21,8 @@ PNM* MapNormal::transform()
double strength = getParameter("strength").toDouble();
PNM* newImage = new PNM(width, height, image->format());
PNM* tempImage = MapHeight(image).transform();
EdgeSobel edgeSobel(tempImage);
math::matrix<float>* gx = edgeSobel.rawHorizontalDetection();
math::matrix<float>* gy = edgeSobel.rawVerticalDetection();
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
newImage = new PNM(width, height, QImage::Format_RGB32);
float dx = 0, dy= 0, dz = 0, length = 0;
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
dx = (*gx)(x, y) / 255;
dy = (*gy)(x, y) / 255;
dz = (float)(1.0 / strength);
length = sqrt(pow(dx, 2.0) + pow(dy, 2.0) + pow(dz, 2.0));
dx = dx/length;
dy = dy/length;
dz = dz/length;
dx = (dx + 1) * (255 / 2);
dy = (dy + 1) * (255 / 2);
dz = (dz + 1) * (255 / 2);
newImage->setPixel(x, y, qRgb(dx, dy, dz));
}
}
return newImage;
}

View File

@ -21,73 +21,28 @@ PNM* NoiseBilateral::transform()
sigma_r = getParameter("sigma_r").toInt();
radius = sigma_d;
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());
}
}
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return newImage;
}
int NoiseBilateral::calcVal(int x, int y, Channel channel)
{
double sumNumerator = 0;
double sumDenominator = 0;
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
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;
return 0;
}
float NoiseBilateral::colorCloseness(int val1, int val2)
{
return exp(-(((val1-val2)^2)/(2*sigma_r^2)));
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return 0;
}
float NoiseBilateral::spatialCloseness(QPoint point1, QPoint point2)
{
return exp(-((point1.x() - point2.x())^2 + ( point1.y() - point2.y())^2)/(2*sigma_d^2));
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return 0;
}

View File

@ -17,57 +17,16 @@ PNM* NoiseMedian::transform()
PNM* newImage = new PNM(width, height, image->format());
for(int x = 0 ; x < width; x++){
for (int y = 0 ; y < height; y++) {
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
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;
}
int NoiseMedian::getMedian(int x, int y, Channel channel)
{
int radius = getParameter("radius").toInt();
QSet<int> set;
QList<int> list = QList<int>::fromSet(set);
std::sort(list.begin(), list.end());
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
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;
return 0;
}

View File

@ -99,59 +99,34 @@ QRgb Transformation::getPixel(int x, int y, Mode mode)
}
/** Returns a pixel using the Cyclic mode:
*
* pixel(x,y) = pixel(x%width, y%width);
*/
QRgb Transformation::getPixelCyclic(int x, int y)
{
int height=image->height();
int width=image->width();
/*
if(x>width) x=x%width;
if(y>height) y=y%height;
if(x<0) x=width-x;
if(y<0) y=height-y;
*/
x=(width+(x%width))%width;
y=(height+(y%height))%height;
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return image->pixel(x,y);
}
/**
* Returns a given pixel
* If the pixel is out of image boundaries Black is returned;
*/
QRgb Transformation::getPixelNull(int x, int y)
{
int height=image->height();
int width=image->width();
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
QRgb pixel = image->pixel(x,y);
if(x>width || x<0 || y>height || y<0)
{
int v=PIXEL_VAL_MAX;
image->setPixel(x,y, QColor(v,v,v).rgb());
}
return pixel;
return image->pixel(x,y);
}
/**
* Returns given pixel.
* If the pixel is out of image boundaries
* the nearest edge pixel is given
*/
QRgb Transformation::getPixelRepeat(int x, int y)
{
int height=image->height();
int width=image->width();
if(x>width) x=width;
if(y>height) y=height;
if(x<0) x=0;
if(y<0) y=0;
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return image->pixel(x,y);
}
@ -161,26 +136,9 @@ math::matrix<float> Transformation::getWindow(int x, int y, int size,
Channel channel,
Mode mode = RepeatEdge)
{
math::matrix<float> window(size,size);
int temp,r;
r=size/2;
for(int i=-r;i<=r;i++)
{
for(int j=-r;j<=r;j++)
{
if(channel==RChannel) temp = qRed(getPixel(x+i,y+j, CyclicEdge));
if(channel==GChannel) temp = qGreen (getPixel(x+i,y+j, CyclicEdge));
if(channel==BChannel) temp = qBlue(getPixel(x+i,y+j, CyclicEdge));
//if(channel==LChannel) temp= qGray(getPixel(i,j, mode));
window[i+r][j+r]=temp;
}
}
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return window;
}