Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Gumix committed May 31, 2008
0 parents commit 371262e
Show file tree
Hide file tree
Showing 46 changed files with 968 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apertures/All_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3
1 1 1
1 1 1
1 1 1
6 changes: 6 additions & 0 deletions apertures/All_5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
4 changes: 4 additions & 0 deletions apertures/Plus_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3
0 1 0
1 1 1
0 1 0
6 changes: 6 additions & 0 deletions apertures/Plus_5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
5
0 0 1 0 0
0 0 1 0 0
1 1 1 1 1
0 0 1 0 0
0 0 1 0 0
Binary file added images/Goldhill.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Goldhill_sap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Lena.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Numbers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Peppers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Stars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions kernels/Blur_11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
11
121
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1
5 changes: 5 additions & 0 deletions kernels/Blur_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
3
9
1 1 1
1 1 1
1 1 1
5 changes: 5 additions & 0 deletions kernels/East.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
3
1
-1 1 1
-1 -2 1
-1 1 1
5 changes: 5 additions & 0 deletions kernels/Laplacian.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
3
1
0 -1 0
-1 4 -1
0 -1 0
5 changes: 5 additions & 0 deletions kernels/Sharp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
3
4
-1 -1 -1
-1 12 -1
-1 -1 -1
5 changes: 5 additions & 0 deletions kernels/Sobel_h.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
3
1
-1 -2 -1
0 0 0
1 2 1
5 changes: 5 additions & 0 deletions kernels/Sobel_v.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
3
1
-1 0 1
-2 0 2
-1 0 1
Binary file added lab1_1/Lena_out_080.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lab1_1/Lena_out_100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lab1_1/Lena_out_120.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions lab1_1/lab1_1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <stdlib.h>
#include <string.h>
#include "png_wrapper.h"

static void process_image(struct Image img, unsigned char threshold)
{
for (size_t y = 0; y < img.height; y++)
for (size_t x = 0; x < img.width; x++)
img.pixels[y][x] = img.pixels[y][x] >= threshold ? 255 : 0;
}

int main(int argc, char * const argv[])
{
if (argc < 3 || argc > 4)
error("usage: %s <input_file> [<output_file>] <threshold (0-255)>",
argv[0]);

char *input_filename = argv[1];
char *output_filename;
char *s_threshold;

if (argc == 4)
{
output_filename = argv[2];
s_threshold = argv[3];
}
else
{
output_filename = alloca(strlen(input_filename) + sizeof("_out.png"));
strcpy(output_filename, input_filename);
strcat(output_filename, "_out.png");
s_threshold = argv[2];
}

int threshold = atoi(s_threshold);
if (threshold < 0 || threshold > 255)
error("wrong threshold (%d)", threshold);

struct Image img = read_grayscale_png(input_filename);
printf("Input file \"%s\" opened (width = %u, height = %u)\n",
input_filename, img.width, img.height);

process_image(img, (unsigned char) threshold);

write_grayscale_png(img, output_filename);
free_pixels(img);

return 0;
}
Binary file added lab1_2/Lena_out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions lab1_2/lab1_2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <stdlib.h>
#include <string.h>
#include "png_wrapper.h"

static inline void add_sat(struct Image img, int x, int y, double a)
{
if (x < 0 || y < 0 || x >= img.width || y >= img.height)
return;

int sum = img.pixels[y][x] + a + 0.5;

if (sum < 0)
sum = 0;
else if (sum > 255)
sum = 255;

img.pixels[y][x] = sum;
}

static void process_image(struct Image img)
{
for (int y = 0; y < img.height; y++)
for (int x = 0; x < img.width; x++)
{
unsigned char old_val = img.pixels[y][x];
unsigned char new_val = (old_val / 128) * 255;
img.pixels[y][x] = new_val;
int err = old_val - new_val;

add_sat(img, x + 1, y + 0, err * 7 / 16.0);
add_sat(img, x - 1, y + 1, err * 3 / 16.0);
add_sat(img, x + 0, y + 1, err * 5 / 16.0);
add_sat(img, x + 1, y + 1, err * 1 / 16.0);
}
}

int main(int argc, char * const argv[])
{
if (argc < 2 || argc > 3)
error("usage: %s <input_file> [<output_file>]", argv[0]);

char *input_filename = argv[1];
char *output_filename;

if (argc == 3)
output_filename = argv[2];
else
{
output_filename = alloca(strlen(input_filename) + sizeof("_out.png"));
strcpy(output_filename, input_filename);
strcat(output_filename, "_out.png");
}

struct Image img = read_grayscale_png(input_filename);
printf("Input file \"%s\" opened (width = %u, height = %u)\n",
input_filename, img.width, img.height);

process_image(img);

write_grayscale_png(img, output_filename);
free_pixels(img);

return 0;
}
Binary file added lab2_1/Lena_out_5x_crop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions lab2_1/lab2_1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <stdlib.h>
#include <string.h>
#include "png_wrapper.h"

static void process_image(struct Image in, struct Image out, double N)
{
for (size_t y = 0; y < out.height; y++)
for (size_t x = 0; x < out.width; x++)
{
size_t in_x = x / N + 0.5,
in_y = y / N + 0.5;

if (in_x > in.width - 1) in_x = in.width - 1;
if (in_y > in.height - 1) in_y = in.height - 1;

out.pixels[y][x] = in.pixels[in_y][in_x];
}
}

int main(int argc, char * const argv[])
{
if (argc < 3 || argc > 4)
error("usage: %s <input_file> [<output_file>] <N (0.0-10.0)>", argv[0]);

char *input_filename = argv[1];
char *output_filename;
char *sN;

if (argc == 4)
{
output_filename = argv[2];
sN = argv[3];
}
else
{
output_filename = alloca(strlen(input_filename) + sizeof("_out.png"));
strcpy(output_filename, input_filename);
strcat(output_filename, "_out.png");
sN = argv[2];
}

double N = atof(sN);
if (N <= 0.0 || N > 10.0)
error("N should be in the range 0.0-10.0");

struct Image in = read_grayscale_png(input_filename);
printf("Input file \"%s\" opened (width = %u, height = %u)\n",
input_filename, in.width, in.height);

struct Image out = { in.width * N + 0.5, in.height * N + 0.5 };
alloc_pixels(&out);

process_image(in, out, N);
free_pixels(in);

write_grayscale_png(out, output_filename);
free_pixels(out);

return 0;
}
Binary file added lab2_2/Lena_out_5x_crop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions lab2_2/lab2_2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <stdlib.h>
#include <string.h>
#include "png_wrapper.h"

static void process_image(struct Image in, struct Image out, double N)
{
for (size_t y = 0; y < out.height; y++)
for (size_t x = 0; x < out.width; x++)
{
size_t in_x = x / N,
in_y = y / N;

if (in_x > in.width - 2) in_x = in.width - 2;
if (in_y > in.height - 2) in_y = in.height - 2;

unsigned char I00 = in.pixels[in_y + 0][in_x + 0],
I10 = in.pixels[in_y + 0][in_x + 1],
I01 = in.pixels[in_y + 1][in_x + 0],
I11 = in.pixels[in_y + 1][in_x + 1];

double u = x / N - in_x,
v = y / N - in_y;

int res = I00 * (1-u) * (1-v)
+ I10 * u * (1-v)
+ I01 * (1-u) * v
+ I11 * u * v + 0.5;

if (res < 0) res = 0;
if (res > 255) res = 255;
out.pixels[y][x] = res;
}
}

int main(int argc, char * const argv[])
{
if (argc < 3 || argc > 4)
error("usage: %s <input_file> [<output_file>] <N (0.0-10.0)>", argv[0]);

char *input_filename = argv[1];
char *output_filename;
char *sN;

if (argc == 4)
{
output_filename = argv[2];
sN = argv[3];
}
else
{
output_filename = alloca(strlen(input_filename) + sizeof("_out.png"));
strcpy(output_filename, input_filename);
strcat(output_filename, "_out.png");
sN = argv[2];
}

double N = atof(sN);
if (N <= 0.0 || N > 10.0)
error("N should be in the range 0.0-10.0");

struct Image in = read_grayscale_png(input_filename);
printf("Input file \"%s\" opened (width = %u, height = %u)\n",
input_filename, in.width, in.height);

struct Image out = { in.width * N + 0.5, in.height * N + 0.5 };
alloc_pixels(&out);

process_image(in, out, N);
free_pixels(in);

write_grayscale_png(out, output_filename);
free_pixels(out);

return 0;
}
Binary file added lab3/Goldhill_Lena_Peppers_out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions lab3/lab3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <stdlib.h>
#include <string.h>
#include "png_wrapper.h"

static void process_images(struct Image top, struct Image bot,
struct Image alpha, struct Image out)
{
for (int y = 0; y < out.height; y++)
for (int x = 0; x < out.width; x++)
{
double a = alpha.pixels[y][x] / 255.0;

int res = top.pixels[y][x] * (1 - a)
+ bot.pixels[y][x] * a + 0.5;

if (res > 255) res = 255;
out.pixels[y][x] = res;
}
}

int main(int argc, char * const argv[])
{
if (argc < 4 || argc > 5)
error("usage: %s <top_file> <bottom_file> "
"<alpha_channel_file> [<output_file>]", argv[0]);

char *input1_filename = argv[1];
char *input2_filename = argv[2];
char *input3_filename = argv[3];
char *output_filename;

if (argc == 5)
output_filename = argv[4];
else
{
output_filename = alloca(strlen(input1_filename) + sizeof("_out.png"));
strcpy(output_filename, input1_filename);
strcat(output_filename, "_out.png");
}

struct Image in1 = read_grayscale_png(input1_filename);
printf("Top input file \"%s\" opened (width = %u, height = %u)\n",
input1_filename, in1.width, in1.height);

struct Image in2 = read_grayscale_png(input2_filename);
printf("Bottom input file \"%s\" opened (width = %u, height = %u)\n",
input2_filename, in2.width, in2.height);

struct Image in3 = read_grayscale_png(input3_filename);
printf("Alpha channel input file \"%s\" opened (width = %u, height = %u)\n",
input3_filename, in3.width, in3.height);

struct Image out = { in1.width, in2.height };
alloc_pixels(&out);

process_images(in1, in2, in3, out);
free_pixels(in1);
free_pixels(in2);
free_pixels(in3);

write_grayscale_png(out, output_filename);
free_pixels(out);

return 0;
}
Binary file added lab4/Goldhill_in_hist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lab4/Goldhill_out_100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lab4/Goldhill_out_100_hist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 371262e

Please sign in to comment.