#include #include #include //#include "filters.h" #define M_PI 3.1416; void gaussiano1(unsigned char* img_in, unsigned char* img_out, int width, int height) { int i, j, k, index, gauss; for(i=1; i 255) gauss = 255; img_out[index] = gauss; } } void gaussiano2(unsigned char* img_in, unsigned char* img_out, int width, int height) { int i, j, k, index, gauss; for(i=2; i 255) gauss = 255; img_out[index] = gauss; } } void gaussiano3(unsigned char* img_in, unsigned char* img_out, int width, int height) { int i, j, k, index, gauss; for(i=3; i 255) gauss = 255; img_out[index] = gauss; } } void blackAndWhite(unsigned char* img_in, unsigned char* img_out, int width, int height) { int i, j, index; double bw; unsigned char baw; for(i=0; i 255) grad = 255; img_out[index] = grad; } } void prewitt(unsigned char* img_in, unsigned char* img_out, int width, int height) { int i, j, k, index, grad, gradX, gradY; for(i=1; i 255) grad = 255; img_out[index] = grad; } } void sobel(unsigned char* img_in, unsigned char* img_out, int width, int height) { int i, j, k, index, grad, gradX, gradY; for(i=1; i 255) grad = 255; img_out[index] = grad; } } void laplaciano(unsigned char* img_in, unsigned char* img_out, int width, int height) { int i, j, k, index, laplace; for(i=1; i 255) laplace = 255; img_out[index] = (unsigned char)laplace; } } void makeMask(unsigned char* img_in, unsigned char* img_out, int threshold, int width, int height) { int i, j, index, sum; unsigned char res; for(i=0; i threshold) res = 255; else res = 0; img_out[index ] = res; img_out[index+1] = res; img_out[index+2] = res; } } void dilatation(unsigned char* img_in, unsigned char* img_out, int width, int height) { int i, j, index, count; unsigned char res; for(i=1; i 0) { img_out[index ] = 255; img_out[index+1] = 255; img_out[index+2] = 255; continue; } count = 0; if(img_in[index+3] > 0) count++; if(img_in[index-3] > 0) count++; if(img_in[index+width*3+3] > 0) count++; if(img_in[index+width*3] > 0) count++; if(img_in[index+width*3-3] > 0) count++; if(img_in[index-width*3+3] > 0) count++; if(img_in[index-width*3] > 0) count++; if(img_in[index-width*3-3] > 0) count++; if(count>0) res = 255; else res = 0; img_out[index ] = res; img_out[index+1] = res; img_out[index+2] = res; } } void erosion(unsigned char* img_in, unsigned char* img_out, int width, int height) { int i, j, index, count; unsigned char res; for(i=1; i 0) count++; if(img_in[index-3] > 0) count++; if(img_in[index+width*3+3] > 0) count++; if(img_in[index+width*3] > 0) count++; if(img_in[index+width*3-3] > 0) count++; if(img_in[index-width*3+3] > 0) count++; if(img_in[index-width*3] > 0) count++; if(img_in[index-width*3-3] > 0) count++; if(count>7) res = 255; else res = 0; img_out[index ] = res; img_out[index+1] = res; img_out[index+2] = res; } } void gradienteCanny(unsigned char* img_in, unsigned char* img_out, int width, int height) { int i, j, index, grad, gradX, gradY; for(i=1; i 255) grad = 255; img_out[index ] = grad; img_out[index+1] = grad; img_out[index+2] = grad; } } void canny(unsigned char* img_in, unsigned char* img_out, unsigned char* img_aux, int width, int height) { int i, j, index, grad, gradX, gradY; unsigned char direction, left, right, res; unsigned char highThreshold = 120; unsigned char lowThreshold = 40; unsigned char P1, P2, P3, P4, P5, P6, P7, P8; double orientation; gradienteCanny(img_in, img_aux, width, height); for(i=0; i=width-3)||(j>=height-3)) { img_out[index ] = 0; img_out[index+1] = 0; img_out[index+2] = 0; continue; } gradX = img_in[index+width*3+3] - img_in[index+width*3-3]; gradX += img_in[index-width*3+3] - img_in[index-width*3-3]; gradX += 2*(img_in[index+3] - img_in[index-3]); gradY = img_in[index-width*3-3] - img_in[index+width*3-3]; gradY += img_in[index-width*3+3] - img_in[index+width*3+3]; gradY += 2*(img_in[index-width*3] - img_in[index+width*3]); grad = abs(gradX) + abs(gradY); if(grad>255) grad = 255; if(gradX == 0) { if(gradY==0) orientation = 0.0; else if(gradY<0) { gradY = -gradY; orientation = 90.0; } else orientation = 90.0; } /* Can't take invtan of angle in 2nd Quad */ else if(gradX<0 && gradY>0) { gradX = -gradX; orientation = 180.0 - ((atan((double)(gradY)/(double)(gradX))) * (180.0/3.1416)); } /* Can't take invtan of angle in 4th Quad */ else if(gradX>0 && gradY<0) { gradY = -gradY; orientation = 180.0 - ((atan((double)(gradY)/(double)(gradX))) * (180.0/3.1416)); } /* else angle is in 1st or 3rd Quad */ else orientation = (atan((double)(gradY)/(double)(gradX))) * (180.0/3.1416); if(orientation < 22.5) direction = 0; else if(orientation < 67.5) direction = 45; else if(orientation < 112.5) direction = 90; else if(orientation < 157.5) direction = 135; else direction = 0; if(direction == 0) { left = img_aux[index-3]; right = img_aux[index+3]; } else if(direction == 45) { left = img_aux[index+width*3-3]; right = img_aux[index-width*3+3]; } else if(direction == 90) { left = img_aux[index-width*3]; right = img_aux[index+width*3]; } else { left = img_aux[index-width*3-3]; right = img_aux[index+width*3+3]; } if((grad= highThreshold) res = 255; /* edge */ else if(grad < lowThreshold) res = 0; /* nonedge */ /* SUM is between T1 & T2 */ else { /* Determine values of neighboring pixels */ P1 = img_in[index-width*3-3]; P2 = img_in[index-width*3 ]; P3 = img_in[index-width*3+3]; P4 = img_in[index-3]; P5 = img_in[index+3]; P6 = img_in[index+width*3-3]; P7 = img_in[index+width*3 ]; P8 = img_in[index+width*3+3]; /* Check to see if neighboring pixel values are edges */ if((P1>highThreshold) || (P2>highThreshold) || (P3>highThreshold) || (P4>highThreshold) || (P5>highThreshold) || (P6>highThreshold) || (P7>highThreshold) || (P8>highThreshold)) res = 255; /* make edge */ else res = 0; /* make nonedge */ } } img_out[index ] = res; img_out[index+1] = res; img_out[index+2] = res; } } void findMaskCorners(unsigned char* img_in, unsigned char* img_mask, unsigned char* img_out, unsigned char* img_aux1, unsigned char* img_aux2, int width, int height) { unsigned char* gradX = img_aux1; unsigned char* gradY = img_aux2; int i, j, index, grad_x, grad_y; int k = 2; //Tamanho do quadrado int ki, kj, kindex; double a, b, c, d, av1, av2, delta; int count = 0; double max1 = 0; double min1 = 999999999; double avg1 = 0; double max2 = 0; double min2 = 999999999; double avg2 = 0; for(i=1; i 255) grad_x = 255; if(grad_y > 255) grad_y = 255; gradX[index ] = grad_x; gradX[index+1] = grad_x; gradX[index+2] = grad_x; gradY[index ] = grad_y; gradY[index+1] = grad_y; gradY[index+2] = grad_y; } for(i=1+k; imax1) max1 = av1; if(av1max2) max2 = av2; if(av2