Compare commits

..

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

21 changed files with 90 additions and 742 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

@ -41,8 +41,9 @@ math::matrix<float> BlurGaussian::getMask(int size, Mode)
}
float BlurGaussian::getGauss(int x, int y, float sigma)
{
{
float gauss= exp(-(x*x+y*y)/(2*sigma*sigma))/(2*M_PI*sigma*sigma);
return gauss;
}

View File

@ -55,78 +55,69 @@ PNM* Convolution::convolute(math::matrix<float> mask, Mode mode = CyclicEdge)
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);
}
//gray_window=getWindow(x,y,size,LChannel,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);
}
//gray_window=join(gray_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);
}
red_sum=sum(red_window);
green_sum=sum(green_window);
blue_sum=sum(blue_window);
//gray_sum=sum(gray_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;
}
red_sum=red_sum/mask_weight;
blue_sum=blue_sum/mask_weight;
green_sum=green_sum/mask_weight;
//gray_sum=gray_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());
}
if(red_sum>=0 && red_sum<=255 && green_sum>=0 && green_sum<=255 && blue_sum>=0 && blue_sum<=255)
{
newImage->setPixel(x,y, QColor(red_sum,green_sum,blue_sum).rgb());
}
else if (red_sum>=0 && red_sum<=255 && green_sum>=0 && green_sum<=255)
{
int old_blue = qBlue(newImage->pixel(x,y));
newImage->setPixel(x,y, QColor(red_sum,green_sum,old_blue).rgb());
}
else if (blue_sum>=0 && blue_sum<=255 && green_sum>=0 && green_sum<=255)
{
int old_red = qRed(newImage->pixel(x,y));
newImage->setPixel(x,y, QColor(old_red,green_sum,blue_sum).rgb());
}
else if (blue_sum>=0 && blue_sum<=255 && red_sum>=0 && red_sum<=255)
{
int old_green = qGreen(newImage->pixel(x,y));
newImage->setPixel(x,y, QColor(red_sum,old_green,blue_sum).rgb());
}
}
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!
*/
@ -137,7 +128,7 @@ const math::matrix<float> Convolution::join(math::matrix<float> A, math::matrix<
for (int x=0; x<size; x++)
for (int y=0; y<size; y++)
{
{
C[x][y]=A[x][y]*B[x][y];
}
@ -150,15 +141,18 @@ const float Convolution::sum(const math::matrix<float> A)
{
float sum = 0.0;
int size=A.rowno();
for (int x=0; x<A.rowno(); x++)
for (int y=0; y<A.colno(); y++)
for (int x=0; x<size; x++)
for (int y=0; y<size; y++)
{
sum=sum+A[x][y];
}
return sum;
}
@ -171,15 +165,16 @@ const math::matrix<float> Convolution::reflection(const math::matrix<float> A)
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);
}
for (int x=size-1; x>=0; x--)
{
for (int y=size-1; y>=0; y--)
{
C[x][y]=A[counter_i][counter_j];
counter_j++;
}
counter_i++;
}
}
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;
}