aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorjvech <jmvalenciae@unal.edu.co>2023-06-19 13:11:29 -0500
committerjvech <jmvalenciae@unal.edu.co>2023-06-19 13:11:29 -0500
commitd579b5e8bf669918908c894304efd66ee79f179e (patch)
treea2165cbd64f0ab2c5798320e9a581c53293d5113 /src/main.c
parentfd82f4c6257db8bc3753d28c092a62134cd6f629 (diff)
fix: convolution filter fixed
edge filters work
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/main.c b/src/main.c
index 0182328..ec29a6b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -27,6 +27,7 @@ image_convolution(Image input, float kernel[9])
}
uint8_t *r, *g, *b;
+ uint8_t red, green, blue;
r = calloc(input.width * input.height, sizeof(uint8_t));
g = calloc(input.width * input.height, sizeof(uint8_t));
b = calloc(input.width * input.height, sizeof(uint8_t));
@@ -36,13 +37,16 @@ image_convolution(Image input, float kernel[9])
for (i = 0; i < input.height; i++) {
for (j = 0; j < input.width; j++) {
index = i * input.width + j;
- r[index] = kernel_op(r, kernel, i, j, input.width, input.height);
- g[index] = kernel_op(g, kernel, i, j, input.width, input.height);
- b[index] = kernel_op(b, kernel, i, j, input.width, input.height);
+ red = kernel_op(r, kernel, i, j, input.width, input.height);
+ green = kernel_op(g, kernel, i, j, input.width, input.height);
+ blue = kernel_op(b, kernel, i, j, input.width, input.height);
+ out.data[index * 3] = red;
+ out.data[index * 3 + 1] = green;
+ out.data[index * 3 + 2] = blue;
}
}
- merge_rgb(&out, r, g, b);
+ //merge_rgb(&out, r, g, b);
free(r);
free(g);
free(b);
@@ -81,10 +85,10 @@ kernel_op(uint8_t *data, float kernel[9], int i, int j, int w, int h)
kernel_value += data[img_index] * kernel[index_k];
}
- kernel_value = (kernel_value > 255) ? 255: kernel_value;
- kernel_value = (kernel_value < 0) ? 0: kernel_value;
}
}
+ kernel_value = (kernel_value > 255) ? 255: kernel_value;
+ kernel_value = (kernel_value < 0) ? 0: kernel_value;
return (uint8_t)kernel_value;
}
@@ -109,15 +113,27 @@ split_rgb(Image input, uint8_t *r, uint8_t *g, uint8_t *b)
int main(int argc, char *argv[])
{
Image img;
- float kernel[9] = {
+ float edge[9] = {
-1, -1, -1,
-1, 8, -1,
-1, -1, -1,
};
- //for (int i = 0; i < 9; i++) kernel[i] /= 16;
- ppm_read("images/synth_1.ppm", &img);
- Image out_img = image_convolution(img, kernel);
- ppm_write("out.ppm", &out_img);
+ float eye[9] = {
+ 0, 0, 0,
+ 0, 1, 0,
+ 0, 0, 0,
+ };
+ float gauss[9] = {
+ 1, 2, 1,
+ 2, 4, 2,
+ 1, 2, 1,
+ };
+ for (int i = 0; i < 9; i++) gauss[i] /= 16;
+ ppm_read("images/house_1.ppm", &img);
+ Image out_img = image_convolution(img, edge);
+ ppm_write("out1.ppm", &out_img);
+ out_img = image_convolution(out_img, gauss);
+ ppm_write("out2.ppm", &out_img);
return 0;
}
Feel free to download, copy and edit any repo