Skip to content

Commit

Permalink
Add bit-plane slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
Gumix committed Mar 25, 2017
1 parent 5efc654 commit 9970bd0
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LDIR = /opt/local/lib/
LIBS = -lc -lpng16
CFLAGS = -Wall -march=native -Ofast -Wa,-q
OUT_DIR = build
LABS = lab1_1 lab1_2 lab1_3 lab1_4 lab1_5 lab1_6 lab1_7 lab2_1 lab2_2 lab3 lab4_1 lab4_2 lab5 lab6 lab7
LABS = lab1_1 lab1_2 lab1_3 lab1_4 lab1_5 lab1_6 lab1_7 lab1_8 lab2_1 lab2_2 lab3 lab4_1 lab4_2 lab5 lab6 lab7
BINS = $(addprefix $(OUT_DIR)/,${LABS})
OBJS = $(addsuffix .o,${BINS})

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Here are the programs that I wrote during the Digital Image Processing class in
5. [Ordered dithering](#ordered-dithering-lab1_5c)
6. [Random dithering](#random-dithering-lab1_6c)
7. [Clustered dithering](#clustered-dithering-lab1_7c)
8. [Bit-plane slicing](#bit-plane-slicing-lab1_8c)
2. Image scaling
1. [Nearest-neighbor interpolation](#nearest-neighbor-interpolation-lab2_1c)
2. [Bilinear interpolation](#bilinear-interpolation-lab2_2c)
Expand Down Expand Up @@ -63,6 +64,16 @@ Here are the programs that I wrote during the Digital Image Processing class in
| ----- | ------ |
| ![Input](images/Lena.png) | ![Output](lab1_7/Lena_out.png) |

---
## Bit-plane slicing ([lab1_8.c](lab1_8/lab1_8.c))
| Output (bit 6) | Output (bit 5) |
| ----- | ------ |
| ![Output](lab1_8/Lena_out_6.png) | ![Output](lab1_8/Lena_out_5.png) |

| Output (bit 4) | Output (bit 3) |
| ----- | ------ |
| ![Output](lab1_8/Lena_out_4.png) | ![Output](lab1_8/Lena_out_3.png) |

---
## Nearest-neighbor interpolation ([lab2_1.c](lab2_1/lab2_1.c))
| Input | Output (N = 5, cropped) |
Expand Down
Binary file added lab1_8/Lena_out_0.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_8/Lena_out_1.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_8/Lena_out_2.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_8/Lena_out_3.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_8/Lena_out_4.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_8/Lena_out_5.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_8/Lena_out_6.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_8/Lena_out_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions lab1_8/lab1_8.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <stdlib.h>
#include "png_wrapper.h"

static void process_image(struct Image in, struct Image out[8])
{
for (size_t y = 0; y < in.height; y++)
for (size_t x = 0; x < in.width; x++)
for (int b = 0; b < 8; b++)
out[b].pixels[y][x] = in.pixels[y][x] & 1 << b ? 255 : 0;
}

int main(int argc, char * const argv[])
{
if (argc != 10)
error("usage: %s <in_file> <out0_file> <out1_file> <out2_file> <out3_file> "
"<out4_file> <out5_file> <out6_file> <out7_file> ", argv[0]);

char *input_filename = argv[1];
char *output_filenames[8];
for (int i = 0; i < 8; i++)
output_filenames[i] = argv[i + 2];

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[8];
for (int i = 0; i < 8; i++)
{
out[i].width = in.width;
out[i].height = in.height;
alloc_pixels(&out[i]);
}

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

for (int i = 0; i < 8; i++)
{
write_grayscale_png(out[i], output_filenames[i]);
free_pixels(out[i]);
}

return 0;
}

0 comments on commit 9970bd0

Please sign in to comment.