void appendImageBytesToRaw(int fd, char * file) { Image *img = get_image_from_path(file); unsigned char *pixel_map = NULL; size_t pixel_map_size = img->columns * img->rows * sizeof(*pixel_map); pixel_map = malloc(pixel_map_size); unsigned int x = 0; unsigned int y = 0; int width = (int)img->columns; int height = (int)img->rows; PixelPacket *px; ExceptionInfo exception; GetExceptionInfo(&exception); px = GetImagePixels(img, 0, 0, img->columns, img->rows); while (y < height) { x = 0; while (x < width) { pixel_map[(width * y) + x] = (char)px[(width * y) + x].green; x++; } y++; } write(fd, pixel_map, pixel_map_size); free(pixel_map); DestroyImage(img); }
int main(int ac, char **av) { Image *img; int *histogram; InitializeMagick("./"); img = get_image_from_path(av[1]); img = get_grayscale_image(img); histogram = create_histogram(img); dump_histogram(histogram, av[2]); dump_image(img, "./", "gray", "jpeg"); return (0); }
int main(int ac, char **av) { char *image_path; char *image_name; RectangleInfo *portion; struct dirent **names; int nb; int i = 0; int j = 0; Image *img; Image *img_channel; Image *img_tmp; ac = ac; InitializeMagick("./"); portion = malloc(sizeof(*portion)); portion->width = 5538 - 3602; portion->height = 1523; portion->x = 3602; portion->y = 0; nb = scandir(av[1], &names, NULL, versionsort); while (i < nb) { if (check_extension(names[i]->d_name, ".jpeg")) { printf("\rImage => %i", j); fflush(stdout); asprintf(&image_path, "%s/%s", av[1], names[i]->d_name); if ((img = get_image_from_path(image_path)) == NULL) printf("Failed to load the image from disk!\n"); /* asprintf(&image_name, "%i_rgb", j); img = crop_image_from_path(image_path, portion); dump_image(img, "/media/Data/histology/brain_2", image_name, "jpeg"); free(image_name); */ if ((img_channel = get_red_channe_image(img)) == NULL) printf("Filed to extract the red channel from the image"); asprintf(&image_name, "%i_r", j); dump_image(img_channel, "/media/Data/histology/brain_1_r", image_name, "jpeg"); DestroyImage(img_channel); free(image_name); if ((img_channel = get_green_channe_image(img)) == NULL) printf("Filed to extract the green channel from the image"); asprintf(&image_name, "%i_g", j); dump_image(img_channel, "/media/Data/histology/brain_1_g", image_name, "jpeg"); free(image_name); DestroyImage(img_channel); if ((img_channel = get_blue_channe_image(img)) == NULL) printf("Filed to extract the blue channel from the image"); asprintf(&image_name, "%i_b", j); dump_image(img_channel, "/media/Data/histology/brain_1_b", image_name, "jpeg"); free(image_name); DestroyImage(img_channel); if ((img_tmp = apply_green_contrast(img, 0, 100)) == NULL) printf("Filed to extract the - channel from the image"); asprintf(&image_name, "%i_gr", j); dump_image(img_tmp, "/media/Data/histology/brain_1_gr", image_name, "jpeg"); free(image_name); /* DestroyImage(img_channel); */ if ((img_channel = get_green_grayscale_image(img_tmp)) == NULL) printf("Filed to extract the - channel from the image"); asprintf(&image_name, "%i_g", j); dump_image(img_channel, "/media/Data/histology/brain_1_gr", image_name, "jpeg"); free(image_name); DestroyImage(img_tmp); img_tmp = img_channel; if ((img_channel = substract_grayscale_to_original(img, img_tmp, 20, 255)) == NULL) printf("Filed to extract the - channel from the image"); asprintf(&image_name, "%i_final", j); dump_image(img_channel, "/media/Data/histology/brain_1_gr", image_name, "jpeg"); free(image_name); DestroyImage(img_channel); DestroyImage(img_tmp); DestroyImage(img); free(image_path); j++; } i++; } printf("\n"); return (0); }
/* check image processing is working for currection */ void image_correction(char *path, char *output_path){ Image *final_img = NULL; DIR *FD; struct dirent *in_file; char *imagePath; //char *imageName; char *name; int count = 1; if (NULL == (FD = opendir(path))) { fprintf(stderr, "Error : Failed to open input directory - %s\n", strerror(errno)); free(FD); return; } c_threshold *t = malloc(sizeof(*t)); t->max_threshold = 10; while ((in_file = readdir(FD))) { if (!strcmp (in_file->d_name, ".")) continue; if (!strcmp (in_file->d_name, "..")) continue; //APPLE Dir ISSUE if (!strcmp (in_file->d_name, ".DS_Store")) continue; asprintf(&imagePath, "%s%s", path, in_file->d_name); final_img = get_image_from_path(imagePath); printf("File name: %s\n", in_file->d_name); /* put your image processing function/measure here ! */ /* crop image before reconstruction (IMAGE_WIDTH, IMAGE_HEIGHT, WIDTH_OFFSET, HEIGHT_OFFSET) */ //final_img = crop_image(final_img, imagePath, 1300, 1150, 1700, 3150); //brain_2 //final_img = crop_image(final_img, imageName, 1727, 1575, 2450, 1850); //blockface 08.05.2013 //final_img = rotate_image(final_img, 90); asprintf(&name, "%.4i%s", count, "_image"); dump_image(final_img, output_path, name, "jpg"); count ++; printf("Name Changed: %s\n", name); /* for (int i = 0 ; i < 6 ; i ++) { asprintf(&name, "%.4i%s", count, "_image"); dump_multi_image(final_img, output_path, name, "jpg"); count ++; printf("Name Changed: %s\n", name); } DestroyImage(final_img); */ } closedir(FD); free(t); return; }