PandA-2024.02
laplacian.c
Go to the documentation of this file.
1 /* laplacian.c */
2 #include "mypgm.h"
3 #include <float.h>
4 
5 int laplacian(unsigned char *image1, unsigned char *image2, unsigned int x_size, unsigned int y_size)
6  /* Spatial filtering of image data */
7  /* 8-neighbor Laplacian filter */
8  /* Input: image1[y][x] ---- Outout: image2[y][x] */
9 {
10  /* Definition of 8-neighbor Laplacian filter */
11  int weight[3][3] = {{ 1, 1, 1 },
12  { 1, -8, 1 },
13  { 1, 1, 1 }};
14  double pixel_value;
15  double min, max;
16  int x, y, i, j; /* Loop variable */
17 
18  /* Maximum values calculation after filtering*/
19  min = DBL_MAX;
20  max = -DBL_MAX;
21  for (y = 1; y < y_size - 1; y++) {
22  for (x = 1; x < x_size - 1; x++) {
23  pixel_value = 0.0;
24  for (j = - 1; j < 2; j++) {
25  for (i = -1; i < 2; i++) {
26  pixel_value += weight[j + 1][i + 1] * (*(image1 + (y + j) + (x + i) * MAX_IMAGESIZE));
27  }
28  }
29  if (pixel_value < min) min = pixel_value;
30  if (pixel_value > max) max = pixel_value;
31  }
32  }
33  if ((int)(max - min) == 0) {
34  return -1;
35  }
36 
37  /* Initialization of image2[y][x] */
38  for (y = 0; y < y_size; y++) {
39  for (x = 0; x < x_size; x++) {
40  *(image2 + y + x * MAX_IMAGESIZE) = 0;
41  }
42  }
43 
44  /* Generation of image2 after linear transformtion */
45  for (y = 1; y < y_size - 1; y++) {
46  for (x = 1; x < x_size - 1; x++) {
47  pixel_value = 0.0;
48  for (j = - 1; j < 2; j++) {
49  for (i = -1; i < 2; i++) {
50  pixel_value += weight[j + 1][i + 1] * (*(image1 + (y + j) + (x + i) * MAX_IMAGESIZE));
51  }
52  }
53  pixel_value = MAX_BRIGHTNESS * (pixel_value - min) / (max - min);
54  *(image2 + y + x * MAX_IMAGESIZE) = (unsigned char)pixel_value;
55  }
56  }
57  return 0;
58 }
#define MAX_IMAGESIZE
Definition: mypgm.h:7
#define min(x, y)
#define MAX_BRIGHTNESS
Definition: mypgm.h:8
#define max
Definition: backprop.h:17
int laplacian(unsigned char *image1, unsigned char *image2, unsigned int x_size, unsigned int y_size)
Definition: laplacian.c:5
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