diff --git a/preprocessing/preprocessing/Makefile b/preprocessing/preprocessing/Makefile index 10de11e6b..769aa3431 100644 --- a/preprocessing/preprocessing/Makefile +++ b/preprocessing/preprocessing/Makefile @@ -4,7 +4,7 @@ CFLAGS = -Wall -Wextra -O3 `pkg-config --cflags sdl2 SDL2_image` LDFLAGS = LDLIBS = `pkg-config --libs sdl2 SDL2_image` -lm -SRC = main.c rotation.c filter.c gaussian_blur.c utils.c median.c perspective.c dilate.c contrast.c sauvola.c threshold.c otsu.c invert.c adaptive_threshold.c +SRC = main.c filter.c utils.c perspective.c OBJ = ${SRC:.c=.o} DEP = ${SRC:.c=.d} diff --git a/preprocessing/preprocessing/adaptive_threshold.c b/preprocessing/preprocessing/adaptive_threshold.c deleted file mode 100644 index 3bace6f29..000000000 --- a/preprocessing/preprocessing/adaptive_threshold.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "pretreatment.h" - -// Function to get pixel intensity (assuming grayscale image) -Uint8 get_pixel_intensity(SDL_Surface* surface, int x, int y) -{ - Uint32 pixel = ((Uint32*)surface->pixels)[y * surface->w + x]; - Uint8 r, g, b; - SDL_GetRGB(pixel, surface->format, &r, &g, &b); - - // Return the average of RGB channels - return (r + g + b) / 3; -} - -// Function to apply adaptive thresholding -SDL_Surface* adaptive_threshold(SDL_Surface* surface, int neighborhood_size, int C) -{ - // Convert the surface to a new one to avoid modifying the original - SDL_Surface* new_surface = SDL_ConvertSurface(surface, surface->format, 0); - - for (int y = 0; y < new_surface->h; y++) { - for (int x = 0; x < new_surface->w; x++) { - // Calculate local mean - int total = 0; - int count = 0; - for (int i = -neighborhood_size; i <= neighborhood_size; i++) { - for (int j = -neighborhood_size; j <= neighborhood_size; j++) { - int new_x = x + i; - int new_y = y + j; - - // Check if new_x and new_y are inside the surface - if (new_x >= 0 && new_x < new_surface->w && new_y >= 0 && new_y < new_surface->h) { - total += get_pixel_intensity(surface, new_x, new_y); - count++; - } - } - } - - int mean = total / count; - Uint8 intensity = get_pixel_intensity(surface, x, y); - Uint32 new_pixel; - - // Apply thresholding - if (intensity < mean - C) { - new_pixel = SDL_MapRGB(new_surface->format, 0, 0, 0); // black - } else { - new_pixel = SDL_MapRGB(new_surface->format, 255, 255, 255); // white - } - - ((Uint32*)new_surface->pixels)[y * new_surface->w + x] = new_pixel; - } - } - - return new_surface; -} diff --git a/preprocessing/preprocessing/canny.c b/preprocessing/preprocessing/canny.c deleted file mode 100644 index ae754aea1..000000000 --- a/preprocessing/preprocessing/canny.c +++ /dev/null @@ -1,143 +0,0 @@ -#include "pretreatment.h" - -#define PI 3.14159265 -#define HIGH_THRESHOLD 75 -#define LOW_THRESHOLD 30 - -// Calculate Gradient and Direction -void calculateGradientAndDirection(SDL_Surface* grayscaleImage, double** gradient, double** direction) -{ - int sobelX[3][3] = { {-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1} }; - int sobelY[3][3] = { {-1, -2, -1}, {0, 0, 0}, {1, 2, 1} }; - - int width = grayscaleImage->w; - int height = grayscaleImage->h; - - for (int y = 1; y < height - 1; y++) { - for (int x = 1; x < width - 1; x++) { - double dx = 0.0; - double dy = 0.0; - - for (int i = -1; i <= 1; i++) { - for (int j = -1; j <= 1; j++) { - Uint32 pixel = ((Uint32*)grayscaleImage->pixels)[(y + i) * width + (x + j)]; - Uint8 r, g, b; - SDL_GetRGB(pixel, grayscaleImage->format, &r, &g, &b); - dx += (double)r * sobelX[i + 1][j + 1]; - dy += (double)r * sobelY[i + 1][j + 1]; - } - } - - gradient[y][x] = sqrt(dx * dx + dy * dy); - direction[y][x] = atan2(dy, dx) * 180 / PI; - } - } -} - -// Non-Maximum Suppression -void nonMaximumSuppression(SDL_Surface* grayscaleImage, double** gradient, double** direction) -{ - int width = grayscaleImage->w; - int height = grayscaleImage->h; - - for (int y = 1; y < height - 1; y++) { - for (int x = 1; x < width - 1; x++) { - double dir = direction[y][x]; - dir += 180; - dir = fmod(dir, 180); - - if ((dir >= 0 && dir < 22.5) || (dir >= 157.5 && dir < 180)) { - if (gradient[y][x] <= gradient[y][x - 1] || gradient[y][x] <= gradient[y][x + 1]) - gradient[y][x] = 0; - } else if (dir >= 22.5 && dir < 67.5) { - if (gradient[y][x] <= gradient[y - 1][x + 1] || gradient[y][x] <= gradient[y + 1][x - 1]) - gradient[y][x] = 0; - } else if (dir >= 67.5 && dir < 112.5) { - if (gradient[y][x] <= gradient[y - 1][x] || gradient[y][x] <= gradient[y + 1][x]) - gradient[y][x] = 0; - } else if (dir >= 112.5 && dir < 157.5) { - if (gradient[y][x] <= gradient[y - 1][x - 1] || gradient[y][x] <= gradient[y + 1][x + 1]) - gradient[y][x] = 0; - } - } - } -} - -// Double Threshold -void doubleThreshold(SDL_Surface* grayscaleImage, double** gradient) -{ - int width = grayscaleImage->w; - int height = grayscaleImage->h; - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - Uint8 val = (gradient[y][x] > HIGH_THRESHOLD) ? 255 : (gradient[y][x] > LOW_THRESHOLD) ? 125 : 0; - Uint32 newPixel = SDL_MapRGB(grayscaleImage->format, val, val, val); - ((Uint32*)grayscaleImage->pixels)[y * width + x] = newPixel; - } - } -} - -// Edge Tracking by Hysteresis -void edgeTracking(SDL_Surface* grayscaleImage) -{ - int width = grayscaleImage->w; - int height = grayscaleImage->h; - - for (int y = 1; y < height - 1; y++) { - for (int x = 1; x < width - 1; x++) { - Uint32 pixel = ((Uint32*)grayscaleImage->pixels)[y * width + x]; - Uint8 r, g, b; - SDL_GetRGB(pixel, grayscaleImage->format, &r, &g, &b); - - if (r == 125) { - Uint8 val = 0; - for (int i = -1; i <= 1; i++) { - for (int j = -1; j <= 1; j++) { - Uint32 neighborPixel = ((Uint32*)grayscaleImage->pixels)[(y + i) * width + (x + j)]; - Uint8 nr, ng, nb; - SDL_GetRGB(neighborPixel, grayscaleImage->format, &nr, &ng, &nb); - if (nr == 255) { - val = 255; - break; - } - } - if (val == 255) break; - } - - Uint32 newPixel = SDL_MapRGB(grayscaleImage->format, val, val, val); - ((Uint32*)grayscaleImage->pixels)[y * width + x] = newPixel; - } - } - } -} - -// Canny Edge Detection -void canny(SDL_Surface* grayscaleImage) -{ - int width = grayscaleImage->w; - int height = grayscaleImage->h; - - // Initialize gradient and direction matrices - double** gradient = (double**)malloc(height * sizeof(double*)); - double** direction = (double**)malloc(height * sizeof(double*)); - for (int i = 0; i < height; i++) { - gradient[i] = (double*)malloc(width * sizeof(double)); - direction[i] = (double*)malloc(width * sizeof(double)); - } - - calculateGradientAndDirection(grayscaleImage, gradient, direction); - nonMaximumSuppression(grayscaleImage, gradient, direction); - doubleThreshold(grayscaleImage, gradient); - edgeTracking(grayscaleImage); - - // Free the gradient and direction matrices - for (int i = 0; i < height; i++) { - free(gradient[i]); - free(direction[i]); - } - free(gradient); - free(direction); -} - - diff --git a/preprocessing/preprocessing/canny.c~ b/preprocessing/preprocessing/canny.c~ deleted file mode 100644 index 3f0cd5f55..000000000 --- a/preprocessing/preprocessing/canny.c~ +++ /dev/null @@ -1,144 +0,0 @@ -#include "pretreatment.h" - -#define PI 3.14159265 -#define HIGH_THRESHOLD 75 -#define LOW_THRESHOLD 30 - -// Calculate Gradient and Direction -void calculateGradientAndDirection(SDL_Surface* grayscaleImage, double** gradient, double** direction) -{ - int sobelX[3][3] = { {-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1} }; - int sobelY[3][3] = { {-1, -2, -1}, {0, 0, 0}, {1, 2, 1} }; - - int width = grayscaleImage->w; - int height = grayscaleImage->h; - - for (int y = 1; y < height - 1; y++) { - for (int x = 1; x < width - 1; x++) { - double dx = 0.0; - double dy = 0.0; - - for (int i = -1; i <= 1; i++) { - for (int j = -1; j <= 1; j++) { - Uint32 pixel = ((Uint32*)grayscaleImage->pixels)[(y + i) * width + (x + j)]; - Uint8 r, g, b; - SDL_GetRGB(pixel, grayscaleImage->format, &r, &g, &b); - dx += (double)r * sobelX[i + 1][j + 1]; - dy += (double)r * sobelY[i + 1][j + 1]; - } - } - - gradient[y][x] = sqrt(dx * dx + dy * dy); - direction[y][x] = atan2(dy, dx) * 180 / PI; - } - } -} - -// Non-Maximum Suppression -void nonMaximumSuppression(SDL_Surface* grayscaleImage, double** gradient, double** direction) -{ - int width = grayscaleImage->w; - int height = grayscaleImage->h; - - for (int y = 1; y < height - 1; y++) { - for (int x = 1; x < width - 1; x++) { - double dir = direction[y][x]; - dir += 180; - dir = fmod(dir, 180); - - if ((dir >= 0 && dir < 22.5) || (dir >= 157.5 && dir < 180)) { - if (gradient[y][x] <= gradient[y][x - 1] || gradient[y][x] <= gradient[y][x + 1]) - gradient[y][x] = 0; - } else if (dir >= 22.5 && dir < 67.5) { - if (gradient[y][x] <= gradient[y - 1][x + 1] || gradient[y][x] <= gradient[y + 1][x - 1]) - gradient[y][x] = 0; - } else if (dir >= 67.5 && dir < 112.5) { - if (gradient[y][x] <= gradient[y - 1][x] || gradient[y][x] <= gradient[y + 1][x]) - gradient[y][x] = 0; - } else if (dir >= 112.5 && dir < 157.5) { - if (gradient[y][x] <= gradient[y - 1][x - 1] || gradient[y][x] <= gradient[y + 1][x + 1]) - gradient[y][x] = 0; - } - } - } -} - -// Double Threshold -void doubleThreshold(SDL_Surface* grayscaleImage, double** gradient) -{ - int width = grayscaleImage->w; - int height = grayscaleImage->h; - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - Uint8 val = (gradient[y][x] > HIGH_THRESHOLD) ? 255 : (gradient[y][x] > LOW_THRESHOLD) ? 125 : 0; - Uint32 newPixel = SDL_MapRGB(grayscaleImage->format, val, val, val); - ((Uint32*)grayscaleImage->pixels)[y * width + x] = newPixel; - } - } -} - -// Edge Tracking by Hysteresis -void edgeTracking(SDL_Surface* grayscaleImage) -{ - int width = grayscaleImage->w; - int height = grayscaleImage->h; - - for (int y = 1; y < height - 1; y++) { - for (int x = 1; x < width - 1; x++) { - Uint32 pixel = ((Uint32*)grayscaleImage->pixels)[y * width + x]; - Uint8 r, g, b; - SDL_GetRGB(pixel, grayscaleImage->format, &r, &g, &b); - - if (r == 125) { - Uint8 val = 0; - for (int i = -1; i <= 1; i++) { - for (int j = -1; j <= 1; j++) { - Uint32 neighborPixel = ((Uint32*)grayscaleImage->pixels)[(y + i) * width + (x + j)]; - Uint8 nr, ng, nb; - SDL_GetRGB(neighborPixel, grayscaleImage->format, &nr, &ng, &nb); - if (nr == 255) { - val = 255; - break; - } - } - if (val == 255) break; - } - - Uint32 newPixel = SDL_MapRGB(grayscaleImage->format, val, val, val); - ((Uint32*)grayscaleImage->pixels)[y * width + x] = newPixel; - } - } - } -} - -// Canny Edge Detection -void canny(SDL_Surface* grayscaleImage) -{ - int width = grayscaleImage->w; - int height = grayscaleImage->h; - - // Initialize gradient and direction matrices - double** gradient = (double**)malloc(height * sizeof(double*)); - double** direction = (double**)malloc(height * sizeof(double*)); - for (int i = 0; i < height; i++) { - gradient[i] = (double*)malloc(width * sizeof(double)); - direction[i] = (double*)malloc(width * sizeof(double)); - } - - calculateGradientAndDirection(grayscaleImage, gradient, direction); - nonMaximumSuppression(grayscaleImage, gradient, direction); - doubleThreshold(grayscaleImage, gradient); - edgeTracking(grayscaleImage); - - // Free the gradient and direction matrices - for (int i = 0; i < height; i++) { - free(gradient[i]); - free(direction[i]); - } - free(gradient); - free(gradient); - free(direction); -} - - diff --git a/preprocessing/preprocessing/contrast.c b/preprocessing/preprocessing/contrast.c deleted file mode 100644 index f7b401f6e..000000000 --- a/preprocessing/preprocessing/contrast.c +++ /dev/null @@ -1,51 +0,0 @@ -#include "pretreatment.h" - -void enhance_contrast(SDL_Surface *surface) -{ - if (surface == NULL) { - printf("Invalid surface.\n"); - return; - } - - SDL_LockSurface(surface); - - int width = surface->w; - int height = surface->h; - Uint32 *pixels = (Uint32 *)surface->pixels; - Uint8 min_r = 255, min_g = 255, min_b = 255; - Uint8 max_r = 0, max_g = 0, max_b = 0; - - // Find the minimum and maximum pixel values - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - Uint32 pixel = pixels[y * width + x]; - Uint8 r, g, b; - SDL_GetRGB(pixel, surface->format, &r, &g, &b); - - min_r = (r < min_r) ? r : min_r; - min_g = (g < min_g) ? g : min_g; - min_b = (b < min_b) ? b : min_b; - - max_r = (r > max_r) ? r : max_r; - max_g = (g > max_g) ? g : max_g; - max_b = (b > max_b) ? b : max_b; - } - } - - // Apply linear contrast stretching - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - Uint32 pixel = pixels[y * width + x]; - Uint8 r, g, b; - SDL_GetRGB(pixel, surface->format, &r, &g, &b); - - Uint8 new_r = 255 * (r - min_r) / (max_r - min_r); - Uint8 new_g = 255 * (g - min_g) / (max_g - min_g); - Uint8 new_b = 255 * (b - min_b) / (max_b - min_b); - - pixels[y * width + x] = SDL_MapRGB(surface->format, new_r, new_g, new_b); - } - } - - SDL_UnlockSurface(surface); -} diff --git a/preprocessing/preprocessing/dilate.c b/preprocessing/preprocessing/dilate.c deleted file mode 100644 index 351d51ebb..000000000 --- a/preprocessing/preprocessing/dilate.c +++ /dev/null @@ -1,56 +0,0 @@ -#include "pretreatment.h" - -SDL_Surface* dilate(SDL_Surface* input, int kernel_size) { - if (input == NULL) { - printf("Invalid surface.\n"); - return NULL; - } - - int width = input->w; - int height = input->h; - - SDL_Surface* output = SDL_CreateRGBSurface(0, width, height, input->format->BitsPerPixel, input->format->Rmask, input->format->Gmask, input->format->Bmask, input->format->Amask); - - if (output == NULL) { - printf("Failed to create output surface: %s\n", SDL_GetError()); - return NULL; - } - - int k = kernel_size / 2; - - SDL_LockSurface(input); - SDL_LockSurface(output); - - Uint32* input_pixels = (Uint32*)input->pixels; - Uint32* output_pixels = (Uint32*)output->pixels; - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - int is_black = 1; - - for (int dy = -k; dy <= k && is_black; dy++) { - for (int dx = -k; dx <= k && is_black; dx++) { - int nx = x + dx; - int ny = y + dy; - - if (nx >= 0 && nx < width && ny >= 0 && ny < height) { - Uint32 pixel = input_pixels[ny * width + nx]; - Uint8 r, g, b, a; - SDL_GetRGBA(pixel, input->format, &r, &g, &b, &a); - - if (r == 255 && g == 255 && b == 255) { - is_black = 0; - } - } - } - } - - output_pixels[y * width + x] = is_black ? SDL_MapRGBA(output->format, 0, 0, 0, 255) : SDL_MapRGBA(output->format, 255, 255, 255, 255); - } - } - - SDL_UnlockSurface(input); - SDL_UnlockSurface(output); - - return output; -} diff --git a/preprocessing/preprocessing/filter.c b/preprocessing/preprocessing/filter.c index 80b897e74..b430185c4 100644 --- a/preprocessing/preprocessing/filter.c +++ b/preprocessing/preprocessing/filter.c @@ -1,82 +1,61 @@ -#include -#include -#include -#include -#include #include "pretreatment.h" -double sobelx[3][3] = {{-1.0, 0.0, 1.0}, - {-2.0, 0.0, 2.0}, - {-1.0, 0.0, 1.0}}; +void enhance_contrast(SDL_Surface *surface) +{ + if (surface == NULL) + { + printf("Invalid surface.\n"); + return; + } -double sobely[3][3] = {{-1.0, -2.0, -1.0}, - {0.0, 0.0, 0.0}, - {1.0, 2.0, 1.0}}; + SDL_LockSurface(surface); -double gradient(SDL_Surface *surface, double kernel[3][3], int row, int col) -{ - int width = surface->w; - int height = surface->h; - Uint32 *pixels = surface->pixels; - double res = 0; - - for (int i = 0; i < 3; i++) + int width = surface->w; + int height = surface->h; + Uint32 *pixels = (Uint32 *)surface->pixels; + Uint8 min_r = 255, min_g = 255, min_b = 255; + Uint8 max_r = 0, max_g = 0, max_b = 0; + + // Find the minimum and maximum pixel values + for (int y = 0; y < height; y++) { - for (int j = 0; j < 3; j++) - { - int x = i + row; - int y = j + col; - if (x >= 0 && y >= 0 && x < width && y < height) - { - Uint8 r,g,b; - SDL_GetRGB(pixels[y*(width) + x], surface->format, &r,&g,&b); - res += r * kernel[i][j]; - } + for (int x = 0; x < width; x++) + { + Uint32 pixel = pixels[y * width + x]; + Uint8 r, g, b; + SDL_GetRGB(pixel, surface->format, &r, &g, &b); + + min_r = (r < min_r) ? r : min_r; + min_g = (g < min_g) ? g : min_g; + min_b = (b < min_b) ? b : min_b; + + max_r = (r > max_r) ? r : max_r; + max_g = (g > max_g) ? g : max_g; + max_b = (b > max_b) ? b : max_b; } } - - return res; -} - -void sobel_filter(SDL_Surface *surface) -{ - //Lock the surface - SDL_LockSurface(surface); - //Get the width, heigth and pixels of the selected surface - int width = surface->w; - int height = surface->h; - - Uint32 *pixels = surface->pixels; - - //Variable for SobelX -> gx / SobelY gy / SobelX+Y -> gradient - double gx, gy; - double grad; - - //Filter all the pixels one by one - for (int i = 0; i < height; i++) + // Apply linear contrast stretching + for (int y = 0; y < height; y++) { - for (int j = 0; j < width; j++) - { - gx = gradient(surface, sobelx, j, i); - gy = gradient(surface, sobely, j, i); - grad = sqrt(gx * gx + gy * gy); - - if (grad > 128) - { - pixels[i*(width) + j] = SDL_MapRGB(surface->format, 255, 255, 255); - } - else - { - pixels[i*(width) + j] = SDL_MapRGB(surface->format, 0, 0, 0); - } + for (int x = 0; x < width; x++) + { + Uint32 pixel = pixels[y * width + x]; + Uint8 r, g, b; + SDL_GetRGB(pixel, surface->format, &r, &g, &b); + + Uint8 new_r = 255 * (r - min_r) / (max_r - min_r); + Uint8 new_g = 255 * (g - min_g) / (max_g - min_g); + Uint8 new_b = 255 * (b - min_b) / (max_b - min_b); + + pixels[y * width + x] = SDL_MapRGB(surface->format, new_r, new_g, new_b); } } - //Unlock the surface - SDL_UnlockSurface(surface); + SDL_UnlockSurface(surface); } + //Same function from the TP06. Uint32 pixel_to_grayscale(Uint32 pixel_color, SDL_PixelFormat *format) { @@ -114,131 +93,514 @@ void grayscale(SDL_Surface *surface) SDL_UnlockSurface(surface); } -Uint32 getpixel(SDL_Surface *surface, int x, int y) +const double PI = 3.14159265358979323846; + +double gaussian(double x, double sigma) { - int bpp = surface->format->BytesPerPixel; - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; - switch (bpp) { - case 1: - return *p; - case 2: - return *(Uint16 *)p; - case 3: - if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - return p[0] << 16 | p[1] << 8 | p[2]; - else - return p[0] | p[1] << 8 | p[2] << 16; - case 4: - return *(Uint32 *)p; - default: - return 0; - } -} - -void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) -{ - int bpp = surface->format->BytesPerPixel; - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; - switch (bpp) { - case 1: - *p = pixel; - break; - case 2: - *(Uint16 *)p = pixel; - break; - case 3: - if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { - p[0] = (pixel >> 16) & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = pixel & 0xff; - } else { - p[0] = pixel & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = (pixel >> 16) & 0xff; + return (1.0 / (sigma * sqrt(2.0 * PI))) * exp(-(x * x) / (2.0 * sigma * sigma)); +} + +void gaussian_blur(SDL_Surface *surface, int radius, double sigma) +{ + if (surface == NULL) + { + printf("Invalid surface.\n"); + return; + } + + SDL_LockSurface(surface); + + Uint32 *pixels = (Uint32 *) surface->pixels; + int width = surface->w; + int height = surface->h; + //int bpp = surface->format->BytesPerPixel; + + double *kernel = (double *) malloc((2 * radius + 1) * sizeof(double)); + for (int i = 0; i < 2 * radius + 1; i++) { + kernel[i] = gaussian(i - radius, sigma); + } + + Uint32 *temp = (Uint32 *) malloc(width * height * sizeof(Uint32)); + memcpy(temp, pixels, width * height * sizeof(Uint32)); + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + double r_sum = 0, g_sum = 0, b_sum = 0, k_sum = 0; + + for (int i = -radius; i <= radius; i++) { + int xi = x + i; + if (xi >= 0 && xi < width) { + Uint32 pixel = temp[y * width + xi]; + Uint8 r, g, b; + SDL_GetRGB(pixel, surface->format, &r, &g, &b); + + double k = kernel[radius + i]; + r_sum += r * k; + g_sum += g * k; + b_sum += b * k; + k_sum += k; + } } - break; - case 4: - *(Uint32 *)p = pixel; - break; + + Uint8 r = round(r_sum / k_sum); + Uint8 g = round(g_sum / k_sum); + Uint8 b = round(b_sum / k_sum); + pixels[y * width + x] = SDL_MapRGB(surface->format, r, g, b); + } } + + memcpy(temp, pixels, width * height * sizeof(Uint32)); + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + double r_sum = 0, g_sum = 0, b_sum = 0, k_sum = 0; + + for (int i = -radius; i <= radius; i++) { + int yi = y + i; + if (yi >= 0 && yi < height) { + Uint32 pixel = temp[yi * width + x]; + Uint8 r, g, b; + SDL_GetRGB(pixel, surface->format, &r, &g, &b); + + double k = kernel[radius + i]; + r_sum += r * k; + g_sum += g * k; + b_sum += b * k; + k_sum += k; + } + } + + Uint8 r = round(r_sum / k_sum); + Uint8 g = round(g_sum / k_sum); + Uint8 b = round(b_sum / k_sum); + pixels[y * width + x] = SDL_MapRGB(surface->format, r, g, b); + } + } + + free(temp); + free(kernel); + + SDL_UnlockSurface(surface); } -void blur(SDL_Surface *surface, int strength) +double noise_level(SDL_Surface* surface) { - /* Blurs a surface, strength is the blur's strength */ - - // Allocate a temporary surface to store the blurred version - SDL_Surface *tempSurface = SDL_CreateRGBSurface(0, surface->w, surface->h, 24, 0, 0, 0, 0); - - // Loop over every pixel in the surface - for (int y = 0; y < surface->h; y++) + int width = surface->w; + int height = surface->h; + + double count = 0.0; + for (int i = 1; i < width - 1; i++) { - for (int x = 0; x < surface->w; x++) + for (int j = 1; j < height - 1; j++) { - // Calculate the average color of the surrounding pixels - int red = 0, green = 0, blue = 0; - int count = 0; - for (int dy = -strength; dy <= strength; dy++) + double medium = 0.0; + + // Calculate the average of the neighboring pixels + for (int ki = -1; ki <= 1; ki++) { - for (int dx = -strength; dx <= strength; dx++) + for (int kj = -1; kj <= 1; kj++) { - int nx = x + dx; - int ny = y + dy; - if (nx >= 0 && nx < surface->w && ny >= 0 && ny < surface->h) - { - Uint32 pixel = getpixel(surface, nx, ny); - red += (pixel >> 16) & 0xff; - green += (pixel >> 8) & 0xff; - blue += pixel & 0xff; - count++; - } - } - } - red /= count; - green /= count; - blue /= count; - - // Set the pixel in the temporary surface - Uint32 pixel = (red << 16) | (green << 8) | blue; - putpixel(tempSurface, x, y, pixel); - } - } - - // Copy the blurred surface back to the original surface - SDL_BlitSurface(tempSurface, NULL, surface, NULL); - - // Free the temporary surface - SDL_FreeSurface(tempSurface); -} - -// calculate the mean and standard deviation of a window of pixels -void calculate_mean_and_stddev(Uint8 *pixels, int pitch, int x, int y, int window_size, double *mean, double *stddev) -{ - // initialize the sum of pixel values and the sum of squared pixel values - double sum = 0; - double sum_squared = 0; - - // iterate over the pixels in the window - for (int i = x; i < x + window_size; i++) - { - for (int j = y; j < y + window_size; j++) - { - // calculate the index of the pixel - int index = i * pitch + j * 4; - - // add the pixel value to the sum - sum += pixels[index]; - - // add the squared pixel value to the sum_squared - sum_squared += pow(pixels[index], 2); - } - } - - // calculate the mean of the pixel values - *mean = sum / (window_size * window_size); - - // calculate the standard deviation of the pixel values - double variance = sum_squared / (window_size * window_size) - pow(*mean, 2); - *stddev = sqrt(variance); + Uint32 neighborPixel = ((Uint32*)surface->pixels)[(j + kj) * width + (i + ki)]; + Uint8 r, g, b; + SDL_GetRGB(neighborPixel, surface->format, &r, &g, &b); + medium += r; + } + } + medium /= 9; + + // Get the value of the current pixel + Uint32 pixel = ((Uint32*)surface->pixels)[j * width + i]; + Uint8 r, g, b; + SDL_GetRGB(pixel, surface->format, &r, &g, &b); + double val = 1 - (r / medium); + if (val < 0) + val *= -1; + if (val > 0.5) + count++; + } + } + + return count; +} + +void adaptive_threshold(SDL_Surface* surface, double threshold) +{ + int width = surface->w; + int height = surface->h; + + int s2 = fmax(width, height) / 16; + unsigned long *thresh = calloc(width * height, sizeof(unsigned long)); + long sum = 0; + unsigned int count = 0; + int x1, y1, x2, y2; + + for (int y = 0; y < height; y++) + { + Uint32 pixel = ((Uint32*)surface->pixels)[y]; + Uint8 r, g, b; + SDL_GetRGB(pixel, surface->format, &r, &g, &b); + sum += r; + thresh[y] = sum; + } + + for (int i = 1; i < width; i++) + { + sum = 0; + for (int j = 0; j < height; j++) + { + Uint32 pixel = ((Uint32*)surface->pixels)[i * width + j]; + Uint8 r, g, b; + SDL_GetRGB(pixel, surface->format, &r, &g, &b); + sum += r; + thresh[i * height + j] = thresh[(i - 1) * height + j] + sum; + } + } + + for (int i = 0; i < width; i++) + { + for (int j = 0; j < height; j++) + { + x1 = fmax(i - s2, 1); + x2 = fmin(i + s2, width - 1); + y1 = fmax(j - s2, 1); + y2 = fmin(j + s2, height - 1); + count = (x2 - x1) * (y2 - y1); + sum = thresh[x2 * height + y2] - thresh[x2 * height + (y1 - 1)] - thresh[(x1 - 1) * height + y2] + + thresh[(x1 - 1) * height + (y1 - 1)]; + + Uint32 pixel = ((Uint32*)surface->pixels)[j * width + i]; + Uint8 r, g, b; + SDL_GetRGB(pixel, surface->format, &r, &g, &b); + + if (r * count < sum * (1.0 - threshold)) + ((Uint32*)surface->pixels)[j * width + i] = SDL_MapRGB(surface->format, 0, 0, 0); + else + ((Uint32*)surface->pixels)[j * width + i] = SDL_MapRGB(surface->format, 255, 255, 255); + } + } + + free(thresh); } +/* +void dilate(SDL_Surface* surface) +{ + int width = surface->w; + int height = surface->h; + + SDL_Surface* temp = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, surface->format->format); + + SDL_BlitSurface(surface, NULL, temp, NULL); // Copy original surface to temp + + SDL_LockSurface(surface); + SDL_LockSurface(temp); + + Uint32* pixels = (Uint32*)surface->pixels; + Uint32* tempPixels = (Uint32*)temp->pixels; + + for (int y = 4; y < height - 4; ++y) { + for (int x = 4; x < width - 4; ++x) { + Uint8 r, g, b; + + // Check the 9x9 neighborhood + for (int j = -4; j <= 4; ++j) { + for (int i = -4; i <= 4; ++i) { + Uint32 pixel = tempPixels[(y + j) * width + (x + i)]; + SDL_GetRGB(pixel, temp->format, &r, &g, &b); + + // If a white pixel is found, set the current pixel to white and break the loop + if (r == 255 && g == 255 && b == 255) { + pixels[y * width + x] = SDL_MapRGB(surface->format, 255, 255, 255); + i = 5; + j = 5; + } + } + } + } + } + + SDL_UnlockSurface(temp); + SDL_UnlockSurface(surface); + + SDL_FreeSurface(temp); +} +*/ + +void dilate(SDL_Surface* surface) +{ + int width = surface->w; + int height = surface->h; + + SDL_Surface* temp = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, surface->format->format); + + SDL_BlitSurface(surface, NULL, temp, NULL); // Copy original surface to temp + + SDL_LockSurface(surface); + SDL_LockSurface(temp); + + Uint32* pixels = (Uint32*)surface->pixels; + Uint32* tempPixels = (Uint32*)temp->pixels; + + // Horizontal dilation + for (int y = 0; y < height; ++y) { + for (int x = 5; x < width - 5; ++x) { + Uint8 r, g, b; + + for (int i = -5; i <= 5; ++i) { + Uint32 pixel = tempPixels[y * width + (x + i)]; + SDL_GetRGB(pixel, temp->format, &r, &g, &b); + + if (r == 255 && g == 255 && b == 255) { + pixels[y * width + x] = SDL_MapRGB(surface->format, 255, 255, 255); + break; + } + } + } + } + + SDL_UnlockSurface(temp); + + SDL_BlitSurface(surface, NULL, temp, NULL); // Copy dilated surface to temp + + // Vertical dilation + for (int y = 5; y < height - 5; ++y) { + for (int x = 0; x < width; ++x) { + Uint8 r, g, b; + + for (int i = -5; i <= 5; ++i) { + Uint32 pixel = tempPixels[(y + i) * width + x]; + SDL_GetRGB(pixel, temp->format, &r, &g, &b); + + if (r == 255 && g == 255 && b == 255) { + pixels[y * width + x] = SDL_MapRGB(surface->format, 255, 255, 255); + break; + } + } + } + } + + SDL_UnlockSurface(surface); + SDL_FreeSurface(temp); +} + + +SDL_Surface* invert(SDL_Surface *input) +{ + if (input == NULL) + { + printf("Invalid surface.\n"); + return NULL; + } + + SDL_Surface* output = SDL_ConvertSurfaceFormat(input, input->format->format, 0); + if (output == NULL) + { + printf("Failed to create output surface: %s\n", SDL_GetError()); + return NULL; + } + + SDL_LockSurface(output); + Uint32 *pixels = (Uint32 *)output->pixels; + + int width = output->w; + int height = output->h; + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + Uint8 r, g, b; + Uint32 pixel = pixels[y * width + x]; + SDL_GetRGB(pixel, output->format, &r, &g, &b); + + // Invert the color channels + r = 255 - r; + g = 255 - g; + b = 255 - b; + + pixels[y * width + x] = SDL_MapRGB(output->format, r, g, b); + } + } + + SDL_UnlockSurface(output); + return output; +} + +#define PI 3.14159265 +#define HIGH_THRESHOLD 75 +#define LOW_THRESHOLD 30 + +// Calculate Gradient and Direction +void calculateGradientAndDirection(SDL_Surface* grayscaleImage, double** gradient, double** direction) +{ + int sobelX[3][3] = { {-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1} }; + int sobelY[3][3] = { {-1, -2, -1}, {0, 0, 0}, {1, 2, 1} }; + + int width = grayscaleImage->w; + int height = grayscaleImage->h; + + for (int y = 1; y < height - 1; y++) { + for (int x = 1; x < width - 1; x++) { + double dx = 0.0; + double dy = 0.0; + + for (int i = -1; i <= 1; i++) { + for (int j = -1; j <= 1; j++) { + Uint32 pixel = ((Uint32*)grayscaleImage->pixels)[(y + i) * width + (x + j)]; + Uint8 r, g, b; + SDL_GetRGB(pixel, grayscaleImage->format, &r, &g, &b); + dx += (double)r * sobelX[i + 1][j + 1]; + dy += (double)r * sobelY[i + 1][j + 1]; + } + } + + gradient[y][x] = sqrt(dx * dx + dy * dy); + direction[y][x] = atan2(dy, dx) * 180 / PI; + } + } +} + +// Non-Maximum Suppression +void nonMaximumSuppression(SDL_Surface* grayscaleImage, double** gradient, double** direction) +{ + int width = grayscaleImage->w; + int height = grayscaleImage->h; + + for (int y = 1; y < height - 1; y++) { + for (int x = 1; x < width - 1; x++) { + double dir = direction[y][x]; + dir += 180; + dir = fmod(dir, 180); + + if ((dir >= 0 && dir < 22.5) || (dir >= 157.5 && dir < 180)) { + if (gradient[y][x] <= gradient[y][x - 1] || gradient[y][x] <= gradient[y][x + 1]) + gradient[y][x] = 0; + } else if (dir >= 22.5 && dir < 67.5) { + if (gradient[y][x] <= gradient[y - 1][x + 1] || gradient[y][x] <= gradient[y + 1][x - 1]) + gradient[y][x] = 0; + } else if (dir >= 67.5 && dir < 112.5) { + if (gradient[y][x] <= gradient[y - 1][x] || gradient[y][x] <= gradient[y + 1][x]) + gradient[y][x] = 0; + } else if (dir >= 112.5 && dir < 157.5) { + if (gradient[y][x] <= gradient[y - 1][x - 1] || gradient[y][x] <= gradient[y + 1][x + 1]) + gradient[y][x] = 0; + } + } + } +} + +// Double Threshold +void doubleThreshold(SDL_Surface* grayscaleImage, double** gradient) +{ + int width = grayscaleImage->w; + int height = grayscaleImage->h; + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + Uint8 val = (gradient[y][x] > HIGH_THRESHOLD) ? 255 : (gradient[y][x] > LOW_THRESHOLD) ? 125 : 0; + Uint32 newPixel = SDL_MapRGB(grayscaleImage->format, val, val, val); + ((Uint32*)grayscaleImage->pixels)[y * width + x] = newPixel; + } + } +} + +// Edge Tracking by Hysteresis +void edgeTracking(SDL_Surface* grayscaleImage) +{ + int width = grayscaleImage->w; + int height = grayscaleImage->h; + + for (int y = 1; y < height - 1; y++) { + for (int x = 1; x < width - 1; x++) { + Uint32 pixel = ((Uint32*)grayscaleImage->pixels)[y * width + x]; + Uint8 r, g, b; + SDL_GetRGB(pixel, grayscaleImage->format, &r, &g, &b); + + if (r == 125) { + Uint8 val = 0; + for (int i = -1; i <= 1; i++) { + for (int j = -1; j <= 1; j++) { + Uint32 neighborPixel = ((Uint32*)grayscaleImage->pixels)[(y + i) * width + (x + j)]; + Uint8 nr, ng, nb; + SDL_GetRGB(neighborPixel, grayscaleImage->format, &nr, &ng, &nb); + if (nr == 255) { + val = 255; + break; + } + } + if (val == 255) break; + } + + Uint32 newPixel = SDL_MapRGB(grayscaleImage->format, val, val, val); + ((Uint32*)grayscaleImage->pixels)[y * width + x] = newPixel; + } + } + } +} + +// Canny Edge Detection +void canny(SDL_Surface* grayscaleImage) +{ + int width = grayscaleImage->w; + int height = grayscaleImage->h; + + // Initialize gradient and direction matrices + double** gradient = (double**)malloc(height * sizeof(double*)); + double** direction = (double**)malloc(height * sizeof(double*)); + for (int i = 0; i < height; i++) { + gradient[i] = (double*)malloc(width * sizeof(double)); + direction[i] = (double*)malloc(width * sizeof(double)); + } + + calculateGradientAndDirection(grayscaleImage, gradient, direction); + nonMaximumSuppression(grayscaleImage, gradient, direction); + doubleThreshold(grayscaleImage, gradient); + edgeTracking(grayscaleImage); + + // Free the gradient and direction matrices + for (int i = 0; i < height; i++) { + free(gradient[i]); + free(direction[i]); + } + free(gradient); + free(direction); +} + +SDL_Surface* threshold(SDL_Surface *input, Uint8 threshold_value) +{ + if (input == NULL) { + printf("Invalid surface.\n"); + return NULL; + } + + SDL_Surface* output = SDL_ConvertSurfaceFormat(input, input->format->format, 0); + if (output == NULL) { + printf("Failed to create output surface: %s\n", SDL_GetError()); + return NULL; + } + + SDL_LockSurface(output); + Uint32 *pixels = (Uint32 *)output->pixels; + + int width = output->w; + int height = output->h; + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + Uint8 r, g, b; + Uint32 pixel = pixels[y * width + x]; + SDL_GetRGB(pixel, output->format, &r, &g, &b); + + // Convert to grayscale using the average of the three color channels + Uint8 grayscale = (r + g + b) / 3; + + // Thresholding + if (grayscale > threshold_value) { + pixels[y * width + x] = SDL_MapRGB(output->format, 255, 255, 255); + } else { + pixels[y * width + x] = SDL_MapRGB(output->format, 0, 0, 0); + } + } + } + + SDL_UnlockSurface(output); + return output; +} diff --git a/preprocessing/preprocessing/gaussian_blur.c b/preprocessing/preprocessing/gaussian_blur.c deleted file mode 100644 index 3915f2f8c..000000000 --- a/preprocessing/preprocessing/gaussian_blur.c +++ /dev/null @@ -1,91 +0,0 @@ -#include "pretreatment.h" - -const double PI = 3.14159265358979323846; - -double gaussian(double x, double sigma) -{ - return (1.0 / (sigma * sqrt(2.0 * PI))) * exp(-(x * x) / (2.0 * sigma * sigma)); -} - -void gaussian_blur(SDL_Surface *surface, int radius, double sigma) -{ - if (surface == NULL) - { - printf("Invalid surface.\n"); - return; - } - - SDL_LockSurface(surface); - - Uint32 *pixels = (Uint32 *) surface->pixels; - int width = surface->w; - int height = surface->h; - //int bpp = surface->format->BytesPerPixel; - - double *kernel = (double *) malloc((2 * radius + 1) * sizeof(double)); - for (int i = 0; i < 2 * radius + 1; i++) { - kernel[i] = gaussian(i - radius, sigma); - } - - Uint32 *temp = (Uint32 *) malloc(width * height * sizeof(Uint32)); - memcpy(temp, pixels, width * height * sizeof(Uint32)); - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - double r_sum = 0, g_sum = 0, b_sum = 0, k_sum = 0; - - for (int i = -radius; i <= radius; i++) { - int xi = x + i; - if (xi >= 0 && xi < width) { - Uint32 pixel = temp[y * width + xi]; - Uint8 r, g, b; - SDL_GetRGB(pixel, surface->format, &r, &g, &b); - - double k = kernel[radius + i]; - r_sum += r * k; - g_sum += g * k; - b_sum += b * k; - k_sum += k; - } - } - - Uint8 r = round(r_sum / k_sum); - Uint8 g = round(g_sum / k_sum); - Uint8 b = round(b_sum / k_sum); - pixels[y * width + x] = SDL_MapRGB(surface->format, r, g, b); - } - } - - memcpy(temp, pixels, width * height * sizeof(Uint32)); - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - double r_sum = 0, g_sum = 0, b_sum = 0, k_sum = 0; - - for (int i = -radius; i <= radius; i++) { - int yi = y + i; - if (yi >= 0 && yi < height) { - Uint32 pixel = temp[yi * width + x]; - Uint8 r, g, b; - SDL_GetRGB(pixel, surface->format, &r, &g, &b); - - double k = kernel[radius + i]; - r_sum += r * k; - g_sum += g * k; - b_sum += b * k; - k_sum += k; - } - } - - Uint8 r = round(r_sum / k_sum); - Uint8 g = round(g_sum / k_sum); - Uint8 b = round(b_sum / k_sum); - pixels[y * width + x] = SDL_MapRGB(surface->format, r, g, b); - } - } - - free(temp); - free(kernel); - - SDL_UnlockSurface(surface); -} diff --git a/preprocessing/preprocessing/invert.c b/preprocessing/preprocessing/invert.c deleted file mode 100644 index c7642da1f..000000000 --- a/preprocessing/preprocessing/invert.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "pretreatment.h" - -SDL_Surface* invert(SDL_Surface *input) -{ - if (input == NULL) { - printf("Invalid surface.\n"); - return NULL; - } - - SDL_Surface* output = SDL_ConvertSurfaceFormat(input, input->format->format, 0); - if (output == NULL) { - printf("Failed to create output surface: %s\n", SDL_GetError()); - return NULL; - } - - SDL_LockSurface(output); - Uint32 *pixels = (Uint32 *)output->pixels; - - int width = output->w; - int height = output->h; - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - Uint8 r, g, b; - Uint32 pixel = pixels[y * width + x]; - SDL_GetRGB(pixel, output->format, &r, &g, &b); - - // Invert the color channels - r = 255 - r; - g = 255 - g; - b = 255 - b; - - pixels[y * width + x] = SDL_MapRGB(output->format, r, g, b); - } - } - - SDL_UnlockSurface(output); - return output; -} diff --git a/preprocessing/preprocessing/main.c b/preprocessing/preprocessing/main.c index 56e0a4872..1c6ddc479 100644 --- a/preprocessing/preprocessing/main.c +++ b/preprocessing/preprocessing/main.c @@ -1,157 +1,5 @@ #include "pretreatment.h" -double magnitude(double gx, double gy) -{ - return sqrt(gx * gx + gy * gy); -} - -double angle(double gx, double gy) -{ - return atan2(gy, gx); -} - -Uint8 clip(int value) -{ - return (value < 0) ? 0 : (value > 255) ? 255 : (Uint8)value; -} - -void canny_filter(SDL_Surface *surface, int blur_radius, double blur_sigma, int lower_threshold, int upper_threshold) { - if (surface == NULL) { - printf("Invalid surface.\n"); - return; - } - - SDL_LockSurface(surface); - - // Apply Gaussian blur - gaussian_blur(surface, blur_radius, blur_sigma); - - int width = surface->w; - int height = surface->h; - Uint32 *pixels = (Uint32 *)surface->pixels; - - // Gradient intensity calculation using Sobel operator - double *mag = (double *)calloc(width * height, sizeof(double)); - double *ang = (double *)calloc(width * height, sizeof(double)); - - for (int y = 1; y < height - 1; y++) { - for (int x = 1; x < width - 1; x++) { - Uint8 px[3][3][3]; - for (int i = -1; i <= 1; i++) { - for (int j = -1; j <= 1; j++) { - Uint32 pixel = pixels[(y + i) * width + (x + j)]; - SDL_GetRGB(pixel, surface->format, &px[i + 1][j + 1][0], &px[i + 1][j + 1][1], &px[i + 1][j + 1][2]); - } - } - - int gx = (-1 * px[0][0][0] - 2 * px[1][0][0] - 1 * px[2][0][0]) + - (1 * px[0][2][0] + 2 * px[1][2][0] + 1 * px[2][2][0]); - int gy = (-1 * px[0][0][0] - 2 * px[0][1][0] - 1 * px[0][2][0]) + - (1 * px[2][0][0] + 2 * px[2][1][0] + 1 * px[2][2][0]); - - mag[y * width + x] = magnitude(gx, gy); - ang[y * width + x] = angle(gx, gy); - } - } - - // Non-maximum suppression - for (int y = 1; y < height - 1; y++) { - for (int x = 1; x < width - 1; x++) { - double a = ang[y * width + x]; - double m = mag[y * width + x]; - double neighbour1, neighbour2; - - if ((a > -22.5 && a <= 22.5) || (a > 157.5 || a <= -157.5)) { - neighbour1 = mag[y * width + (x - 1)]; - neighbour2 = mag[y * width + (x + 1)]; - } else if ((a > 22.5 && a <= 67.5) || (a > -157.5 && a <= -112.5)) { - neighbour1 = mag[(y - 1) * width + (x + 1)]; - neighbour2 = mag[(y + 1) * width + (x - 1)]; - } else if ((a > 67.5 && a <= 112.5) || (a > -112.5 && a <= -67.5)) { - neighbour1 = mag[(y - 1) * width + x]; - neighbour2 = mag[(y + 1) * width + x]; - } else { - neighbour1 = mag[(y - 1) * width + (x - 1)]; - neighbour2 = mag[(y + 1) * width + (x + 1)]; - } - - if (m > neighbour1 && m > neighbour2) { - mag[y * width + x] = m; - } else { - mag[y * width + x] = 0; - } - } - } - - // Double thresholding and edge tracking by hysteresis - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - double m = mag[y * width + x]; - Uint8 value; - if (m >= upper_threshold) { - value = 255; - } else if (m >= lower_threshold) { - value = 127; - } else { - value = 0; - } - pixels[y * width + x] = SDL_MapRGB(surface->format, value, value, value); - } - } - - free(mag); - free(ang); - - SDL_UnlockSurface(surface); -} - -// Function to apply box blur to a pixel -Uint32 box_blur(SDL_Surface* surface, int x, int y, int size) { - int total_r = 0, total_g = 0, total_b = 0, total_a = 0; - int count = 0; - - SDL_PixelFormat* format = surface->format; - - for (int i = -size; i <= size; i++) { - for (int j = -size; j <= size; j++) { - int new_x = x + i; - int new_y = y + j; - - if (new_x >= 0 && new_x < surface->w && new_y >= 0 && new_y < surface->h) { - Uint32 pixel = ((Uint32*)surface->pixels)[new_y * surface->w + new_x]; - - Uint8 r, g, b, a; - SDL_GetRGBA(pixel, format, &r, &g, &b, &a); - - total_r += r; - total_g += g; - total_b += b; - total_a += a; - - count++; - } - } - } - - return SDL_MapRGBA(format, total_r / count, total_g / count, total_b / count, total_a / count); -} - -// Function to apply box blur to an entire surface -SDL_Surface* reduce_noise(SDL_Surface* surface, int size) -{ - SDL_Surface* new_surface = SDL_ConvertSurface(surface, surface->format, 0); - - for (int y = 0; y < new_surface->h; y++) { - for (int x = 0; x < new_surface->w; x++) { - Uint32 new_pixel = box_blur(surface, x, y, size); - ((Uint32*)new_surface->pixels)[y * new_surface->w + x] = new_pixel; - } - } - - return new_surface; -} - - int main(int argc, char** argv) { if (argc > 3) @@ -167,33 +15,10 @@ int main(int argc, char** argv) char *filepath = argv[1]; SDL_Surface *surface = IMG_Load(filepath); - //int angle = str_to_int(argv[2]); - /* - int points[4][2] = {{628, 179}, - {1366, 695}, - {848, 1435}, - {110, 917}}; - - double angle = detect_angle(points); - - surface = rotate(surface, angle); - IMG_SavePNG(surface, "rotated.png"); - */ - //Converting the surface to a new format to ensure that it is compatible with the display hardware //and the current rendering context, and that it can be efficiently drawn to the screen. surface = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGB888, 0); - //Perspective Correction - /* - double corners[4][2] = {{628, 179}, - {1366, 695}, - {848, 1435}, - {110, 917}}; - surface = perspective_correction(surface, corners); - IMG_SavePNG(surface, "perspective.png"); - */ - //Enhance Contrast enhance_contrast(surface); IMG_SavePNG(surface, "res/contrast.png"); @@ -206,67 +31,13 @@ int main(int argc, char** argv) gaussian_blur(surface, 3, 1.5); IMG_SavePNG(surface, "res/gaussian_blur.png"); - //Threshold Filter - surface = threshold(surface, 110); - IMG_SavePNG(surface, "res/threshold.png"); - - //Otsu Adaptative Filter - otsu_adaptive_threshold(surface); - IMG_SavePNG(surface, "res/otsu.png"); - - //Threshold Filter - surface = threshold(surface, 100); - IMG_SavePNG(surface, "res/threshold.png"); - - /* - //Sauvola Filter - sauvola(surface, 15, 0.3); - IMG_SavePNG(surface, "res/sauvola.png"); - */ - //Invert Filter surface = invert(surface); IMG_SavePNG(surface, "res/invert.png"); //Dilate Filter - surface = dilate(surface, 3); + dilate(surface); IMG_SavePNG(surface, "res/dilate.png"); - - /* - //Reduce Noise - surface = reduce_noise(surface, 3); - IMG_SavePNG(surface, "res/reduce_noise.png"); - - //Sauvola Filter - sauvola_filter(surface, 15, 0.3); - IMG_SavePNG(surface, "sauvola.png"); - - //Median Filter - median_filter(surface, 5); - IMG_SavePNG(surface, "median.png"); - - //Adaptative Threshold Filter - adaptive_threshold(surface, 31, 2); - IMG_SavePNG(surface, "res/adaptive_threshold.png"); - - //Otsu Adaptative Filter - otsu_adaptive_threshold(surface); - IMG_SavePNG(surface, "otsu.png"); - - //Sobel Filter - sobel_filter(surface); - IMG_SavePNG(surface, "sobel.png"); - - //Grayscale FIlter - grayscale(surface); - IMG_SavePNG(surface, "grayscale.png"); - - //Canny Filter - canny_filter(surface, 3, 1.5, 25, 75); - IMG_SavePNG(surface, "canny.png"); - */ - SDL_FreeSurface(surface); - SDL_Quit(); return 0; } diff --git a/preprocessing/preprocessing/median.c b/preprocessing/preprocessing/median.c deleted file mode 100644 index d3f278536..000000000 --- a/preprocessing/preprocessing/median.c +++ /dev/null @@ -1,59 +0,0 @@ -#include "pretreatment.h" - -int compare(const void *a, const void *b) { - return (*(Uint8 *)a - *(Uint8 *)b); -} - -Uint8 median(const Uint8 *values, int length) { - Uint8 sorted_values[length]; - memcpy(sorted_values, values, length); - - qsort(sorted_values, length, sizeof(Uint8), compare); - return sorted_values[length / 2]; -} - -void median_filter(SDL_Surface *surface, int window_size) { - if (surface == NULL) { - printf("Invalid surface.\n"); - return; - } - - SDL_LockSurface(surface); - - int width = surface->w; - int height = surface->h; - Uint32 *pixels = (Uint32 *)surface->pixels; - int half_window = window_size / 2; - - SDL_Surface *filtered_surface = SDL_ConvertSurface(surface, surface->format, 0); - Uint32 *filtered_pixels = (Uint32 *)filtered_surface->pixels; - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - Uint8 window_values[window_size * window_size]; - int count = 0; - - for (int i = -half_window; i <= half_window; i++) { - for (int j = -half_window; j <= half_window; j++) { - int y_neighbour = y + i; - int x_neighbour = x + j; - - if (y_neighbour >= 0 && y_neighbour < height && x_neighbour >= 0 && x_neighbour < width) { - Uint32 pixel = pixels[y_neighbour * width + x_neighbour]; - Uint8 r, g, b; - SDL_GetRGB(pixel, surface->format, &r, &g, &b); - Uint8 gray = 0.299 * r + 0.587 * g + 0.114 * b; - window_values[count++] = gray; - } - } - } - - Uint8 value = median(window_values, count); - filtered_pixels[y * width + x] = SDL_MapRGB(surface->format, value, value, value); - } - } - - memcpy(surface->pixels, filtered_surface->pixels, surface->pitch * surface->h); - SDL_FreeSurface(filtered_surface); - SDL_UnlockSurface(surface); -} diff --git a/preprocessing/preprocessing/otsu.c b/preprocessing/preprocessing/otsu.c deleted file mode 100644 index adead82a3..000000000 --- a/preprocessing/preprocessing/otsu.c +++ /dev/null @@ -1,86 +0,0 @@ -#include "pretreatment.h" - -int otsu_threshold(SDL_Surface *surface) -{ - int width = surface->w; - int height = surface->h; - Uint32 *pixels = (Uint32 *)surface->pixels; - int histogram[256] = {0}; - - for (int y = 0; y < height; y++) - { - for (int x = 0; x < width; x++) - { - Uint32 pixel = pixels[y * width + x]; - Uint8 r, g, b; - SDL_GetRGB(pixel, surface->format, &r, &g, &b); - Uint8 gray = 0.299 * r + 0.587 * g + 0.114 * b; - histogram[gray]++; - } - } - - int total_pixels = width * height; - double sum = 0; - for (int i = 0; i < 256; i++) - sum += i * histogram[i]; - - double sumB = 0; - int wB = 0; - int wF = 0; - double varMax = 0; - int threshold = 0; - - for (int i = 0; i < 256; i++) - { - wB += histogram[i]; - if (wB == 0) continue; - - wF = total_pixels - wB; - if (wF == 0) break; - - sumB += i * histogram[i]; - double mB = sumB / wB; - double mF = (sum - sumB) / wF; - - double varBetween = (double)wB * (double)wF * (mB - mF) * (mB - mF); - - if (varBetween > varMax) - { - varMax = varBetween; - threshold = i; - } - } - - return threshold; -} - -void otsu_adaptive_threshold(SDL_Surface *surface) -{ - if (surface == NULL) - { - printf("Invalid surface.\n"); - return; - } - - SDL_LockSurface(surface); - - int width = surface->w; - int height = surface->h; - Uint32 *pixels = (Uint32 *)surface->pixels; - int threshold = otsu_threshold(surface); - - for (int y = 0; y < height; y++) - { - for (int x = 0; x < width; x++) - { - Uint32 pixel = pixels[y * width + x]; - Uint8 r, g, b; - SDL_GetRGB(pixel, surface->format, &r, &g, &b); - Uint8 gray = 0.299 * r + 0.587 * g + 0.114 * b; - Uint8 value = (gray > threshold) ? 255 : 0; - pixels[y * width + x] = SDL_MapRGB(surface->format, value, value, value); - } - } - - SDL_UnlockSurface(surface); -} diff --git a/preprocessing/preprocessing/pretreatment.h b/preprocessing/preprocessing/pretreatment.h index 87398b390..665248fcf 100644 --- a/preprocessing/preprocessing/pretreatment.h +++ b/preprocessing/preprocessing/pretreatment.h @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include @@ -6,30 +7,22 @@ #include #include -//Rotation -SDL_Surface *rotate(SDL_Surface *surface, double degree); -double calculate_rotation(SDL_Point topLeft, SDL_Point topRight); -SDL_Surface* cropSurface(SDL_Surface* src, int x1, int y1, int x2, int y2); -double calculateSudokuRotation(int corners[4][2]); - -//Perspective Transform +// Perspective Transform SDL_Surface* perspective_transform(SDL_Surface* surface, double corners[4][2]); -//Edge Detection +// Edge Detection void canny(SDL_Surface* grayscaleImage); -//Filters +// Filters +void enhance_contrast(SDL_Surface *surface); void grayscale(SDL_Surface *surface); -void sobel_filter(SDL_Surface *surface); -void blur(SDL_Surface *surface, int strength); -//double detect_angle(int corners[4][2]); void gaussian_blur(SDL_Surface *surface, int radius, double sigma); -int str_to_int(char *str); -void median_filter(SDL_Surface *surface, int window_size); -SDL_Surface* dilate(SDL_Surface* input, int kernel_size); +double noise_level(SDL_Surface* surface); +void adaptive_threshold(SDL_Surface* surface, double threshold); +void canny(SDL_Surface* grayscaleImage); +void dilate(SDL_Surface* input); SDL_Surface* invert(SDL_Surface *input); -void sauvola(SDL_Surface *surface, int window_size, double k); -void enhance_contrast(SDL_Surface *surface); SDL_Surface* threshold(SDL_Surface *input, Uint8 threshold_value); -void otsu_adaptive_threshold(SDL_Surface *surface); -SDL_Surface* adaptive_threshold(SDL_Surface* surface, int neighborhood_size, int C); + +// Utils +int str_to_int(char *str); diff --git a/preprocessing/preprocessing/rotation.c b/preprocessing/preprocessing/rotation.c deleted file mode 100644 index c0756873f..000000000 --- a/preprocessing/preprocessing/rotation.c +++ /dev/null @@ -1,147 +0,0 @@ -#include -#include -#include -#include -#include "pretreatment.h" - -SDL_Surface *rotate(SDL_Surface *surface, double degree) -{ - /* Takes a surface and a angle (in degrees) as parameters - and rotates the surface counter-clockwise. */ - - //Lock the surface - SDL_LockSurface(surface); - - int width = surface->w; - int height = surface->h; - - //Create a copy of the surface - SDL_Surface *copy = SDL_CreateRGBSurface(0,width, height, 32, 0, 0, 0, 0); - - //Create a new surface in SDL_PIXELFORMAT_RGB888 - SDL_Surface *new_surface = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGB888, 0); - - //Lock the surfaces - SDL_LockSurface(copy); - SDL_LockSurface(new_surface); - - //Get the pixels - Uint32* copy_pixels = copy->pixels; - Uint32* new_pixels = new_surface->pixels; - - //Convert the angle in degree to angle in radian - double angle = degree * (M_PI / 180.0); - - double center_x = (width/(double)2); - double center_y = (height/(double)2); - - //Rotation of all pixels (one by one) - for (int x = 0; x < width; x++) - { - for (int y = 0; y < height; y++) - { - double rx = (x - center_x) * cos(angle) - (y - center_y) * sin(angle) + center_x; - double ry = (x - center_x) * sin(angle) + (y - center_y) * cos(angle) + center_y; - - if (0 <= rx && rx < new_surface->w && 0 <= ry && ry < new_surface->h) - { - Uint8 r,g,b; - SDL_GetRGB(new_pixels[((int)ry)*(new_surface->w) + (int)rx], new_surface->format, &r, &g,&b); - copy_pixels[((int)y)*(new_surface->w) + (int)x] = SDL_MapRGB(new_surface->format, r,g,b); - } - else - { - copy_pixels[((int)y)*(new_surface->w) + (int)x] = SDL_MapRGB(new_surface->format, 0,0,0); - } - - } - - } - - //Unlock the surfaces - SDL_UnlockSurface(copy); - SDL_UnlockSurface(surface); - - return copy; -} - -/* -double detect_angle(int corner[4][2]) -{ - // calculate the center point of the square - int center_x = (corner[0][0] + corner[1][0] + corner[2][0] + corner[3][0]) / 4; - int center_y = (corner[0][1] + corner[1][1] + corner[2][1] + corner[3][1]) / 4; - - // calculate the distance from the center point to each corner - double distances[4]; - - distances[0] = sqrt(pow(corner[0][0] - center_x, 2) - + pow(corner[0][1] - center_y, 2)); - distances[1] = sqrt(pow(corner[1][0] - center_x, 2) - + pow(corner[1][1] - center_y, 2)); - distances[2] = sqrt(pow(corner[2][0] - center_x, 2) - + pow(corner[2][1] - center_y, 2)); - distances[3] = sqrt(pow(corner[3][0] - center_x, 2) - + pow(corner[3][1] - center_y, 2)); - - // find the two corners that are farthest apart - int index1 = 0; - int index2 = 0; - double max_distance = 0; - - for (int i = 0; i < 4; i++) - { - if (distances[i] > max_distance) - { - max_distance = distances[i]; - index1 = i; - } - } - - max_distance = 0; - - for (int i = 0; i < 4; i++) - { - if (i != index1 && distances[i] > max_distance) - { - max_distance = distances[i]; - index2 = i; - } - } - - if (index2 == 0) - index2 = 0; - - // calculate the angle between the two corners and the X-axis - int dx = corner[1][0] - corner[0][0]; - int dy = corner[1][1] - corner[0][1]; - double angle = atan2(dy, dx) * 180 / M_PI; - - // adjust the angle if necessary - if (angle < 0) - angle += 180; - - return angle; -} -*/ - -double calculateSudokuRotation(int corners[4][2]) -{ - // Calculate deltas for top and bottom edges - double dxTop = corners[1][0] - corners[0][0]; - double dyTop = corners[1][1] - corners[0][1]; - double dxBottom = corners[3][0] - corners[2][0]; - double dyBottom = corners[3][1] - corners[2][1]; - - // Calculate angles for top and bottom edges in radians - double angleTop = atan2(dyTop, dxTop); - double angleBottom = atan2(dyBottom, dxBottom); - - // Convert to degrees and adjust range from -180 to 180 - angleTop = angleTop * 180 / M_PI; - angleBottom = angleBottom * 180 / M_PI; - - // Calculate and return average angle - double averageAngle = (angleTop + angleBottom) / 2; - return averageAngle; -} diff --git a/preprocessing/preprocessing/sauvola.c b/preprocessing/preprocessing/sauvola.c deleted file mode 100644 index bf653f267..000000000 --- a/preprocessing/preprocessing/sauvola.c +++ /dev/null @@ -1,72 +0,0 @@ -#include "pretreatment.h" - -double mean(const Uint8 *values, int length) -{ - double sum = 0; - for (int i = 0; i < length; i++) { - sum += values[i]; - } - return sum / length; -} - -double standard_deviation(const Uint8 *values, int length, double mean_value) -{ - double sum = 0; - for (int i = 0; i < length; i++) - { - double diff = values[i] - mean_value; - sum += diff * diff; - } - return sqrt(sum / length); -} - -void sauvola(SDL_Surface *surface, int window_size, double k) -{ - if (surface == NULL) - { - printf("Invalid surface.\n"); - return; - } - - SDL_LockSurface(surface); - - int width = surface->w; - int height = surface->h; - Uint32 *pixels = (Uint32 *)surface->pixels; - int half_window = window_size / 2; - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - Uint8 window_values[window_size * window_size]; - int count = 0; - - for (int i = -half_window; i <= half_window; i++) { - for (int j = -half_window; j <= half_window; j++) { - int y_neighbour = y + i; - int x_neighbour = x + j; - - if (y_neighbour >= 0 && y_neighbour < height && x_neighbour >= 0 && x_neighbour < width) { - Uint32 pixel = pixels[y_neighbour * width + x_neighbour]; - Uint8 r, g, b; - SDL_GetRGB(pixel, surface->format, &r, &g, &b); - Uint8 gray = 0.299 * r + 0.587 * g + 0.114 * b; - window_values[count++] = gray; - } - } - } - - double mean_value = mean(window_values, count); - double std_dev = standard_deviation(window_values, count, mean_value); - double threshold = mean_value * (1 + k * (std_dev / 128 - 1)); - - Uint32 pixel = pixels[y * width + x]; - Uint8 r, g, b; - SDL_GetRGB(pixel, surface->format, &r, &g, &b); - Uint8 gray = 0.299 * r + 0.587 * g + 0.114 * b; - Uint8 value = (gray > threshold) ? 255 : 0; - pixels[y * width + x] = SDL_MapRGB(surface->format, value, value, value); - } - } - - SDL_UnlockSurface(surface); -} diff --git a/preprocessing/preprocessing/threshold.c b/preprocessing/preprocessing/threshold.c deleted file mode 100644 index fa86a8281..000000000 --- a/preprocessing/preprocessing/threshold.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "pretreatment.h" - - -SDL_Surface* threshold(SDL_Surface *input, Uint8 threshold_value) -{ - if (input == NULL) { - printf("Invalid surface.\n"); - return NULL; - } - - SDL_Surface* output = SDL_ConvertSurfaceFormat(input, input->format->format, 0); - if (output == NULL) { - printf("Failed to create output surface: %s\n", SDL_GetError()); - return NULL; - } - - SDL_LockSurface(output); - Uint32 *pixels = (Uint32 *)output->pixels; - - int width = output->w; - int height = output->h; - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - Uint8 r, g, b; - Uint32 pixel = pixels[y * width + x]; - SDL_GetRGB(pixel, output->format, &r, &g, &b); - - // Convert to grayscale using the average of the three color channels - Uint8 grayscale = (r + g + b) / 3; - - // Thresholding - if (grayscale > threshold_value) { - pixels[y * width + x] = SDL_MapRGB(output->format, 255, 255, 255); - } else { - pixels[y * width + x] = SDL_MapRGB(output->format, 0, 0, 0); - } - } - } - - SDL_UnlockSurface(output); - return output; -} diff --git a/preprocessing/preprocessing/utils.c b/preprocessing/preprocessing/utils.c index 0243fdf23..58df87ab4 100644 --- a/preprocessing/preprocessing/utils.c +++ b/preprocessing/preprocessing/utils.c @@ -19,3 +19,55 @@ int str_to_int(char *str) return res * sign; } + +Uint32 getpixel(SDL_Surface *surface, int x, int y) +{ + int bpp = surface->format->BytesPerPixel; + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + switch (bpp) { + case 1: + return *p; + case 2: + return *(Uint16 *)p; + case 3: + if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + return p[0] << 16 | p[1] << 8 | p[2]; + else + return p[0] | p[1] << 8 | p[2] << 16; + case 4: + return *(Uint32 *)p; + default: + return 0; + } +} + +void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) +{ + int bpp = surface->format->BytesPerPixel; + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + + switch (bpp) + { + case 1: + *p = pixel; + break; + case 2: + *(Uint16 *)p = pixel; + break; + case 3: + if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + { + p[0] = (pixel >> 16) & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = pixel & 0xff; + } else { + p[0] = pixel & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = (pixel >> 16) & 0xff; + } + break; + case 4: + *(Uint32 *)p = pixel; + break; + } +} diff --git a/preprocessing/processing/Makefile b/preprocessing/processing/Makefile index 3375c9e0f..7a4485f0f 100644 --- a/preprocessing/processing/Makefile +++ b/preprocessing/processing/Makefile @@ -5,7 +5,7 @@ CFLAGS = -Wall -Wextra -O3 `pkg-config --cflags sdl2 SDL2_image` LDFLAGS = LDLIBS = `pkg-config --libs sdl2 SDL2_image` -lm -SRC = main.c hough_transform.c doubles_lists.c basic_utilities.c SDL_utilities.c grid_detection.c contour_manager.c img_upgrade.c ../preprocessing/rotation.c ../preprocessing/filter.c ../preprocessing/gaussian_blur.c ../preprocessing/utils.c ../preprocessing/median.c ../preprocessing/perspective.c ../preprocessing/dilate.c ../preprocessing/contrast.c ../preprocessing/sauvola.c ../preprocessing/threshold.c ../preprocessing/otsu.c ../preprocessing/invert.c ../preprocessing/adaptive_threshold.c crop.c ../preprocessing/canny.c +SRC = main.c hough_transform.c doubles_lists.c basic_utilities.c SDL_utilities.c grid_detection.c contour_manager.c img_upgrade.c ../preprocessing/filter.c ../preprocessing/utils.c ../preprocessing/perspective.c OBJ = ${SRC:.c=.o} DEP = ${SRC:.c=.d} diff --git a/preprocessing/processing/img/0_0.png b/preprocessing/processing/img/0_0.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/0_0.png and /dev/null differ diff --git a/preprocessing/processing/img/0_1.png b/preprocessing/processing/img/0_1.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/0_1.png and /dev/null differ diff --git a/preprocessing/processing/img/0_2.png b/preprocessing/processing/img/0_2.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/0_2.png and /dev/null differ diff --git a/preprocessing/processing/img/0_3.png b/preprocessing/processing/img/0_3.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/0_3.png and /dev/null differ diff --git a/preprocessing/processing/img/0_4.png b/preprocessing/processing/img/0_4.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/0_4.png and /dev/null differ diff --git a/preprocessing/processing/img/0_5.png b/preprocessing/processing/img/0_5.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/0_5.png and /dev/null differ diff --git a/preprocessing/processing/img/0_6.png b/preprocessing/processing/img/0_6.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/0_6.png and /dev/null differ diff --git a/preprocessing/processing/img/0_7.png b/preprocessing/processing/img/0_7.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/0_7.png and /dev/null differ diff --git a/preprocessing/processing/img/0_8.png b/preprocessing/processing/img/0_8.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/0_8.png and /dev/null differ diff --git a/preprocessing/processing/img/1_0.png b/preprocessing/processing/img/1_0.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/1_0.png and /dev/null differ diff --git a/preprocessing/processing/img/1_1.png b/preprocessing/processing/img/1_1.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/1_1.png and /dev/null differ diff --git a/preprocessing/processing/img/1_2.png b/preprocessing/processing/img/1_2.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/1_2.png and /dev/null differ diff --git a/preprocessing/processing/img/1_3.png b/preprocessing/processing/img/1_3.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/1_3.png and /dev/null differ diff --git a/preprocessing/processing/img/1_4.png b/preprocessing/processing/img/1_4.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/1_4.png and /dev/null differ diff --git a/preprocessing/processing/img/1_5.png b/preprocessing/processing/img/1_5.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/1_5.png and /dev/null differ diff --git a/preprocessing/processing/img/1_6.png b/preprocessing/processing/img/1_6.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/1_6.png and /dev/null differ diff --git a/preprocessing/processing/img/1_7.png b/preprocessing/processing/img/1_7.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/1_7.png and /dev/null differ diff --git a/preprocessing/processing/img/1_8.png b/preprocessing/processing/img/1_8.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/1_8.png and /dev/null differ diff --git a/preprocessing/processing/img/2_0.png b/preprocessing/processing/img/2_0.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/2_0.png and /dev/null differ diff --git a/preprocessing/processing/img/2_1.png b/preprocessing/processing/img/2_1.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/2_1.png and /dev/null differ diff --git a/preprocessing/processing/img/2_2.png b/preprocessing/processing/img/2_2.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/2_2.png and /dev/null differ diff --git a/preprocessing/processing/img/2_3.png b/preprocessing/processing/img/2_3.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/2_3.png and /dev/null differ diff --git a/preprocessing/processing/img/2_4.png b/preprocessing/processing/img/2_4.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/2_4.png and /dev/null differ diff --git a/preprocessing/processing/img/2_5.png b/preprocessing/processing/img/2_5.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/2_5.png and /dev/null differ diff --git a/preprocessing/processing/img/2_6.png b/preprocessing/processing/img/2_6.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/2_6.png and /dev/null differ diff --git a/preprocessing/processing/img/2_7.png b/preprocessing/processing/img/2_7.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/2_7.png and /dev/null differ diff --git a/preprocessing/processing/img/2_8.png b/preprocessing/processing/img/2_8.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/2_8.png and /dev/null differ diff --git a/preprocessing/processing/img/3_0.png b/preprocessing/processing/img/3_0.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/3_0.png and /dev/null differ diff --git a/preprocessing/processing/img/3_1.png b/preprocessing/processing/img/3_1.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/3_1.png and /dev/null differ diff --git a/preprocessing/processing/img/3_2.png b/preprocessing/processing/img/3_2.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/3_2.png and /dev/null differ diff --git a/preprocessing/processing/img/3_3.png b/preprocessing/processing/img/3_3.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/3_3.png and /dev/null differ diff --git a/preprocessing/processing/img/3_4.png b/preprocessing/processing/img/3_4.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/3_4.png and /dev/null differ diff --git a/preprocessing/processing/img/3_5.png b/preprocessing/processing/img/3_5.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/3_5.png and /dev/null differ diff --git a/preprocessing/processing/img/3_6.png b/preprocessing/processing/img/3_6.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/3_6.png and /dev/null differ diff --git a/preprocessing/processing/img/3_7.png b/preprocessing/processing/img/3_7.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/3_7.png and /dev/null differ diff --git a/preprocessing/processing/img/3_8.png b/preprocessing/processing/img/3_8.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/3_8.png and /dev/null differ diff --git a/preprocessing/processing/img/4_0.png b/preprocessing/processing/img/4_0.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/4_0.png and /dev/null differ diff --git a/preprocessing/processing/img/4_1.png b/preprocessing/processing/img/4_1.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/4_1.png and /dev/null differ diff --git a/preprocessing/processing/img/4_2.png b/preprocessing/processing/img/4_2.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/4_2.png and /dev/null differ diff --git a/preprocessing/processing/img/4_3.png b/preprocessing/processing/img/4_3.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/4_3.png and /dev/null differ diff --git a/preprocessing/processing/img/4_4.png b/preprocessing/processing/img/4_4.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/4_4.png and /dev/null differ diff --git a/preprocessing/processing/img/4_5.png b/preprocessing/processing/img/4_5.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/4_5.png and /dev/null differ diff --git a/preprocessing/processing/img/4_6.png b/preprocessing/processing/img/4_6.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/4_6.png and /dev/null differ diff --git a/preprocessing/processing/img/4_7.png b/preprocessing/processing/img/4_7.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/4_7.png and /dev/null differ diff --git a/preprocessing/processing/img/4_8.png b/preprocessing/processing/img/4_8.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/4_8.png and /dev/null differ diff --git a/preprocessing/processing/img/5_0.png b/preprocessing/processing/img/5_0.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/5_0.png and /dev/null differ diff --git a/preprocessing/processing/img/5_1.png b/preprocessing/processing/img/5_1.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/5_1.png and /dev/null differ diff --git a/preprocessing/processing/img/5_2.png b/preprocessing/processing/img/5_2.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/5_2.png and /dev/null differ diff --git a/preprocessing/processing/img/5_3.png b/preprocessing/processing/img/5_3.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/5_3.png and /dev/null differ diff --git a/preprocessing/processing/img/5_4.png b/preprocessing/processing/img/5_4.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/5_4.png and /dev/null differ diff --git a/preprocessing/processing/img/5_5.png b/preprocessing/processing/img/5_5.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/5_5.png and /dev/null differ diff --git a/preprocessing/processing/img/5_6.png b/preprocessing/processing/img/5_6.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/5_6.png and /dev/null differ diff --git a/preprocessing/processing/img/5_7.png b/preprocessing/processing/img/5_7.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/5_7.png and /dev/null differ diff --git a/preprocessing/processing/img/5_8.png b/preprocessing/processing/img/5_8.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/5_8.png and /dev/null differ diff --git a/preprocessing/processing/img/6_0.png b/preprocessing/processing/img/6_0.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/6_0.png and /dev/null differ diff --git a/preprocessing/processing/img/6_1.png b/preprocessing/processing/img/6_1.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/6_1.png and /dev/null differ diff --git a/preprocessing/processing/img/6_2.png b/preprocessing/processing/img/6_2.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/6_2.png and /dev/null differ diff --git a/preprocessing/processing/img/6_3.png b/preprocessing/processing/img/6_3.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/6_3.png and /dev/null differ diff --git a/preprocessing/processing/img/6_4.png b/preprocessing/processing/img/6_4.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/6_4.png and /dev/null differ diff --git a/preprocessing/processing/img/6_5.png b/preprocessing/processing/img/6_5.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/6_5.png and /dev/null differ diff --git a/preprocessing/processing/img/6_6.png b/preprocessing/processing/img/6_6.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/6_6.png and /dev/null differ diff --git a/preprocessing/processing/img/6_7.png b/preprocessing/processing/img/6_7.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/6_7.png and /dev/null differ diff --git a/preprocessing/processing/img/6_8.png b/preprocessing/processing/img/6_8.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/6_8.png and /dev/null differ diff --git a/preprocessing/processing/img/7_0.png b/preprocessing/processing/img/7_0.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/7_0.png and /dev/null differ diff --git a/preprocessing/processing/img/7_1.png b/preprocessing/processing/img/7_1.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/7_1.png and /dev/null differ diff --git a/preprocessing/processing/img/7_2.png b/preprocessing/processing/img/7_2.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/7_2.png and /dev/null differ diff --git a/preprocessing/processing/img/7_3.png b/preprocessing/processing/img/7_3.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/7_3.png and /dev/null differ diff --git a/preprocessing/processing/img/7_4.png b/preprocessing/processing/img/7_4.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/7_4.png and /dev/null differ diff --git a/preprocessing/processing/img/7_5.png b/preprocessing/processing/img/7_5.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/7_5.png and /dev/null differ diff --git a/preprocessing/processing/img/7_6.png b/preprocessing/processing/img/7_6.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/7_6.png and /dev/null differ diff --git a/preprocessing/processing/img/7_7.png b/preprocessing/processing/img/7_7.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/7_7.png and /dev/null differ diff --git a/preprocessing/processing/img/7_8.png b/preprocessing/processing/img/7_8.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/7_8.png and /dev/null differ diff --git a/preprocessing/processing/img/8_0.png b/preprocessing/processing/img/8_0.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/8_0.png and /dev/null differ diff --git a/preprocessing/processing/img/8_1.png b/preprocessing/processing/img/8_1.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/8_1.png and /dev/null differ diff --git a/preprocessing/processing/img/8_2.png b/preprocessing/processing/img/8_2.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/8_2.png and /dev/null differ diff --git a/preprocessing/processing/img/8_3.png b/preprocessing/processing/img/8_3.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/8_3.png and /dev/null differ diff --git a/preprocessing/processing/img/8_4.png b/preprocessing/processing/img/8_4.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/8_4.png and /dev/null differ diff --git a/preprocessing/processing/img/8_5.png b/preprocessing/processing/img/8_5.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/8_5.png and /dev/null differ diff --git a/preprocessing/processing/img/8_6.png b/preprocessing/processing/img/8_6.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/8_6.png and /dev/null differ diff --git a/preprocessing/processing/img/8_7.png b/preprocessing/processing/img/8_7.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/8_7.png and /dev/null differ diff --git a/preprocessing/processing/img/8_8.png b/preprocessing/processing/img/8_8.png deleted file mode 100644 index e220bec79..000000000 Binary files a/preprocessing/processing/img/8_8.png and /dev/null differ diff --git a/preprocessing/processing/main b/preprocessing/processing/main index f11842abd..997673372 100755 Binary files a/preprocessing/processing/main and b/preprocessing/processing/main differ diff --git a/preprocessing/processing/main.c b/preprocessing/processing/main.c index 00c87c6cc..0538149f7 100644 --- a/preprocessing/processing/main.c +++ b/preprocessing/processing/main.c @@ -4,7 +4,6 @@ #include "img_upgrade.h" #include "../preprocessing/pretreatment.h" - /// @brief Main function to test the detection of sudoku. int main(int argc, char** argv) { @@ -18,7 +17,6 @@ int main(int argc, char** argv) // Creates a new surface from the image in parameter. SDL_Surface* surf_img = load_image(argv[1]); SDL_Surface* cut_img = load_image(argv[1]); - cut_img = SDL_ConvertSurfaceFormat(cut_img, SDL_PIXELFORMAT_RGBA32, 0); // Checks if there is any error with the image. if (surf_img == NULL) errx(EXIT_FAILURE, "%s", SDL_GetError()); @@ -34,88 +32,48 @@ int main(int argc, char** argv) surf_wait = SDL_ConvertSurfaceFormat(surf_wait, SDL_PIXELFORMAT_RGB888, 0); cut_img = SDL_ConvertSurfaceFormat(cut_img, SDL_PIXELFORMAT_RGB888, 0); - //-----CUT_IMG-----// - - //Grayscale Filter - grayscale(cut_img); - - //Invert Filter - cut_img = invert(cut_img); - - //-----SURF_WAIT-----// //Enhance Contrast enhance_contrast(surf_wait); - IMG_SavePNG(surf_wait, "res/contrast.png"); //Grayscale Filter grayscale(surf_wait); - IMG_SavePNG(surf_wait, "res/grayscale.png"); //Gaussian Blur gaussian_blur(surf_wait, 1, 0.5); - IMG_SavePNG(surf_wait, "res/gaussian_blur.png"); - //Median Filter - //median_filter(surf_wait, 5); - //IMG_SavePNG(surf_wait, "res/median.png"); + //Adaptive Threshold Filter + double noise = noise_level(surf_wait); + printf("noise = %f\n", noise); + if (noise > 15) + { + printf("adaptive\n"); + noise = 0.5; + adaptive_threshold(surf_wait, noise); + } + else + { + printf("non-adaptive\n"); + noise = 0.2; + adaptive_threshold(surf_wait, noise); + //surf_wait = threshold(surf_wait, 150); + } + SDL_BlitSurface(surf_wait, NULL, cut_img, NULL); + IMG_SavePNG(surf_wait, "res/adaptive_threshold.png"); + + //Invert Filter + cut_img = invert(cut_img); - //Threshold Filter - surf_wait = threshold(surf_wait, 150); - IMG_SavePNG(surf_wait, "res/threshold.png"); - - //Otsu Adaptative Filter - otsu_adaptive_threshold(surf_wait); - IMG_SavePNG(surf_wait, "res/otsu.png"); - //Canny Edge Detection canny(surf_wait); IMG_SavePNG(surf_wait, "res/canny.png"); - /* - //Invert Filter - surf_wait = invert(surf_wait); - IMG_SavePNG(surf_wait, "res/invert.png"); - */ - - /* - //Sauvola Filter - sauvola(surf_wait, 15, 0.5); - IMG_SavePNG(surf_wait, "res/sauvola.png"); - */ - //Dilate Filter - surf_wait = dilate(surf_wait, 10); + dilate(surf_wait); IMG_SavePNG(surf_wait, "res/dilate.png"); - - /* - //Reduce Noise - surface = reduce_noise(surface, 3); - IMG_SavePNG(surface, "res/reduce_noise.png"); - - //Sauvola Filter - sauvola_filter(surface, 15, 0.3); - IMG_SavePNG(surface, "sauvola.png"); - - //Median Filter - median_filter(surface, 5); - IMG_SavePNG(surface, "median.png"); - - //Adaptative Threshold Filter - adaptive_threshold(surface, 31, 2); - IMG_SavePNG(surface, "res/adaptive_threshold.png"); - - //Otsu Adaptative Filter - otsu_adaptive_threshold(surface); - IMG_SavePNG(surface, "otsu.png"); - - //Sobel Filter - sobel_filter(surface); - IMG_SavePNG(surface, "sobel.png"); - */ // ==================================================== - + // UPGRADE IMAGE - REMOVE PARASITES // ==================================================== @@ -133,8 +91,6 @@ int main(int argc, char** argv) {corners_x[1], corners_y[1]}, {corners_x[2], corners_y[2]}, {corners_x[3], corners_y[3]}}; - for (int i = 0; i<4; i++) - printf("x = %f / y = %f\n", corners[i][0], corners[i][1]); // ==================================================== @@ -147,16 +103,13 @@ int main(int argc, char** argv) IMG_SavePNG(surf, "res/perspective.png"); surf = SDL_ConvertSurfaceFormat(surf, SDL_PIXELFORMAT_RGBA32, 0); - IMG_SavePNG(surf, "res/perspectiveconverted.png"); cut_img = perspective_transform(cut_img, corners); - cut_img = threshold(cut_img, 150); IMG_SavePNG(cut_img, "res/cut_img.png"); cut_img = SDL_ConvertSurfaceFormat(cut_img, SDL_PIXELFORMAT_RGBA32, 0); // ==================================================== - printf("%s\n", "coucou3"); // HOUGH TRANSFORM - LINES DETECTION // ==================================================== @@ -164,23 +117,22 @@ int main(int argc, char** argv) struct list* list_theta = list_new(); // Performs Hough Transform Algorithm. hough_transform(surf, &list_theta, &list_rho, 2.1); - printf("%s\n", "coucou4"); // ==================================================== // MAXIMUM DETECTION - MATRIX PERSPECTIVE TRANSFORM - CELLS EXTRACTION // ==================================================== grid_detection(list_rho, list_theta, cut_img); - printf("%s\n", "coucou5"); // ==================================================== - + // Frees memory. SDL_FreeSurface(surf); SDL_FreeSurface(surf_wait); + SDL_FreeSurface(cut_img); list_destroy(list_rho); list_destroy(list_theta); - + // End. return EXIT_SUCCESS; } diff --git a/preprocessing/processing/pimg/ag2.jpg b/preprocessing/processing/pimg/ag2.jpg deleted file mode 100644 index 3a38e2e84..000000000 Binary files a/preprocessing/processing/pimg/ag2.jpg and /dev/null differ diff --git a/preprocessing/processing/pimg/ag4.jpg b/preprocessing/processing/pimg/ag4.jpg new file mode 100644 index 000000000..0efa31c8c Binary files /dev/null and b/preprocessing/processing/pimg/ag4.jpg differ diff --git a/preprocessing/processing/pimg/e.JPG b/preprocessing/processing/pimg/e.JPG new file mode 100644 index 000000000..ca16c9c96 Binary files /dev/null and b/preprocessing/processing/pimg/e.JPG differ diff --git a/preprocessing/processing/pimg/e2.jpg b/preprocessing/processing/pimg/e2.jpg new file mode 100644 index 000000000..b4a08cbb1 Binary files /dev/null and b/preprocessing/processing/pimg/e2.jpg differ diff --git a/preprocessing/processing/pimg/e3.jpg b/preprocessing/processing/pimg/e3.jpg new file mode 100644 index 000000000..95e84589c Binary files /dev/null and b/preprocessing/processing/pimg/e3.jpg differ diff --git a/preprocessing/processing/pimg/e4.jpg b/preprocessing/processing/pimg/e4.jpg new file mode 100644 index 000000000..2b2e729b5 Binary files /dev/null and b/preprocessing/processing/pimg/e4.jpg differ diff --git a/preprocessing/processing/pimg/e5.jpg b/preprocessing/processing/pimg/e5.jpg new file mode 100644 index 000000000..efd81b5f9 Binary files /dev/null and b/preprocessing/processing/pimg/e5.jpg differ diff --git "a/preprocessing/processing/pimg/evannpench\303\251.jpg" "b/preprocessing/processing/pimg/evannpench\303\251.jpg" new file mode 100644 index 000000000..16c8e38dd Binary files /dev/null and "b/preprocessing/processing/pimg/evannpench\303\251.jpg" differ diff --git "a/preprocessing/processing/pimg/evannpench\303\2512.jpg" "b/preprocessing/processing/pimg/evannpench\303\2512.jpg" new file mode 100644 index 000000000..26edc9817 Binary files /dev/null and "b/preprocessing/processing/pimg/evannpench\303\2512.jpg" differ diff --git "a/preprocessing/processing/pimg/evannpench\303\2513.jpg" "b/preprocessing/processing/pimg/evannpench\303\2513.jpg" new file mode 100644 index 000000000..733b13922 Binary files /dev/null and "b/preprocessing/processing/pimg/evannpench\303\2513.jpg" differ diff --git a/preprocessing/processing/pimg/image_05.png b/preprocessing/processing/pimg/image_05.png deleted file mode 100644 index 1c02df470..000000000 Binary files a/preprocessing/processing/pimg/image_05.png and /dev/null differ diff --git a/preprocessing/processing/pimg/mainag.jpg b/preprocessing/processing/pimg/mainag.jpg new file mode 100644 index 000000000..5dab6b497 Binary files /dev/null and b/preprocessing/processing/pimg/mainag.jpg differ diff --git a/preprocessing/processing/pimg/sudoku1.jpg b/preprocessing/processing/pimg/sudoku1.jpg deleted file mode 100644 index cbb0e06e9..000000000 Binary files a/preprocessing/processing/pimg/sudoku1.jpg and /dev/null differ diff --git a/preprocessing/processing/res/canny.png b/preprocessing/processing/res/canny.png deleted file mode 100644 index 18c290c1e..000000000 Binary files a/preprocessing/processing/res/canny.png and /dev/null differ diff --git a/preprocessing/processing/res/contrast.png b/preprocessing/processing/res/contrast.png deleted file mode 100644 index 6d289e81e..000000000 Binary files a/preprocessing/processing/res/contrast.png and /dev/null differ diff --git a/preprocessing/processing/res/cut_img.png b/preprocessing/processing/res/cut_img.png deleted file mode 100644 index a7a73196d..000000000 Binary files a/preprocessing/processing/res/cut_img.png and /dev/null differ diff --git a/preprocessing/processing/res/dilate.png b/preprocessing/processing/res/dilate.png deleted file mode 100644 index ff555e51f..000000000 Binary files a/preprocessing/processing/res/dilate.png and /dev/null differ diff --git a/preprocessing/processing/res/gaussian_blur.png b/preprocessing/processing/res/gaussian_blur.png deleted file mode 100644 index c7893e34a..000000000 Binary files a/preprocessing/processing/res/gaussian_blur.png and /dev/null differ diff --git a/preprocessing/processing/res/grayscale.png b/preprocessing/processing/res/grayscale.png deleted file mode 100644 index de4393c22..000000000 Binary files a/preprocessing/processing/res/grayscale.png and /dev/null differ diff --git a/preprocessing/processing/res/otsu.png b/preprocessing/processing/res/otsu.png deleted file mode 100644 index 207dc792f..000000000 Binary files a/preprocessing/processing/res/otsu.png and /dev/null differ diff --git a/preprocessing/processing/res/perspective.png b/preprocessing/processing/res/perspective.png deleted file mode 100644 index c9e36d09f..000000000 Binary files a/preprocessing/processing/res/perspective.png and /dev/null differ diff --git a/preprocessing/processing/res/perspectiveconverted.png b/preprocessing/processing/res/perspectiveconverted.png deleted file mode 100644 index 53967161b..000000000 Binary files a/preprocessing/processing/res/perspectiveconverted.png and /dev/null differ diff --git a/preprocessing/processing/res/threshold.png b/preprocessing/processing/res/threshold.png deleted file mode 100644 index 207dc792f..000000000 Binary files a/preprocessing/processing/res/threshold.png and /dev/null differ diff --git a/preprocessing/processing/res/thxreshold.png b/preprocessing/processing/res/thxreshold.png deleted file mode 100644 index 207dc792f..000000000 Binary files a/preprocessing/processing/res/thxreshold.png and /dev/null differ