PandA-2024.02
sharpen.c
Go to the documentation of this file.
1 /* sharpen.c */
2 #include "mypgm.h"
3 
4 int sharpen(unsigned char *image1, unsigned char *image2, unsigned int x_size, unsigned int y_size)
5  /* Spatial filtering of image data */
6  /* Sharpening filter by 8-neighbor Laplacian subtraction */
7  /* Input: image1[y][x] ---- Outout: image2[y][x] */
8 {
9  /* Definition of sharpening filter */
10  int weight[3][3] = {{ 1, 1, 1 },
11  { 1, -8, 1 },
12  { 1, 1, 1 }};
13  const double alpha = 0.2;
14  double pixel_value;
15  int x, y, i, j; /* Loop variable */
16  int new_value;
17 
18  /* Initialization of image2[y][x] */
19  for (y = 0; y < y_size; y++) {
20  for (x = 0; x < x_size; x++) {
21  *(image2 + y + x * MAX_IMAGESIZE) = *(image1 + y + x * MAX_IMAGESIZE);
22  }
23  }
24 
25  /* Original image minus Laplacian image */
26  for (y = 1; y < y_size - 1; y++) {
27  for (x = 1; x < x_size - 1; x++) {
28  pixel_value = 0.0;
29  for (j = - 1; j < 2; j++) {
30  for (i = -1; i < 2; i++) {
31  pixel_value += weight[j + 1][i + 1] * *(image1 + (y + j) + (x + i) * MAX_IMAGESIZE);
32  }
33  }
34  new_value = (int)(*(image1 + y + x * MAX_IMAGESIZE) - alpha * pixel_value);
35  if (new_value < 0) new_value = 0;
36  if (new_value > MAX_BRIGHTNESS) new_value = MAX_BRIGHTNESS;
37  *(image2 + y + x * MAX_IMAGESIZE) = (unsigned char)new_value;
38  }
39  }
40 
41  return 0;
42 }
#define MAX_IMAGESIZE
Definition: mypgm.h:7
#define MAX_BRIGHTNESS
Definition: mypgm.h:8
int sharpen(unsigned char *image1, unsigned char *image2, unsigned int x_size, unsigned int y_size)
Definition: sharpen.c:4
x
Return the smallest n such that 2^n >= _x.

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13