void draw_depth_image(FILE *file, int width, int height) { image *img = image_create(width, height); image_downsample(depth_image, img); int x, y; unsigned char pixel, c; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { pixel = image_get_pixel(img, x, y); if (pixel < 0x40) { c = '%'; } else if (pixel < 0x80) { c = '+'; } else if (pixel < 0xC0) { c = '.'; } else { c = ' '; } fputc(c, file); } fputc('\n', file); } image_destroy(img); }
void image_median_filter(image_t* orig, int limits[2], int* pixels) { int rgb; int r_sum; int g_sum; int b_sum; int rgb_count; int i; int j; int x; int y; int ax; int ay; int initial; int end; int rank; int size; initial = limits[0]; end = limits[1]; printf(".. Median filter between %d and %d!\n", initial, end); int k = 0; for (j = initial; j <= end; j++) { r_sum = 0; g_sum = 0; b_sum = 0; rgb_count = 0; // for each pixel in 3x3 mask for (y = -1; y <= 1; y++) { for (x = -1; x <= 1; x++) { // current pixel, so just continue if (y == 1 && x == 1) continue; ay = j/orig->width + y; ax = j%orig->width + x; // check if pixel is in image if (ay >= 0 && ay < orig->height && ax >= 0 && ax < orig->width) { rgb = image_get_pixel(orig, ax, ay); r_sum += (rgb) & 0xFF; g_sum += (rgb >> 8) & 0xFF; b_sum += (rgb >> 16) & 0xFF; rgb_count++; } } } rgb = (r_sum/rgb_count << 16) | (g_sum/rgb_count << 8) | b_sum/rgb_count | (255 << 24); pixels[k++] = rgb; }