diff options
| author | leochanj105 <leochanj@live.unc.edu> | 2021-10-26 13:22:32 -0400 |
|---|---|---|
| committer | leochanj105 <leochanj@live.unc.edu> | 2021-10-26 13:22:32 -0400 |
| commit | 14c854543b1a3cf344a371a5b45595657f95786b (patch) | |
| tree | 70f752880522e5e44669af365754ac0f649dce81 /SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c | |
| parent | 5e2ccfae0532ddd89bcc04bf14aad451e9c79785 (diff) | |
add deadlines and costs
Diffstat (limited to 'SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c')
| -rw-r--r-- | SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c | 142 |
1 files changed, 0 insertions, 142 deletions
diff --git a/SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c b/SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c deleted file mode 100644 index 72bc16f..0000000 --- a/SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c +++ /dev/null | |||
| @@ -1,142 +0,0 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <time.h> | ||
| 8 | #include "segment.h" | ||
| 9 | |||
| 10 | #ifndef M_PI | ||
| 11 | #define M_PI 3.141592653589793 | ||
| 12 | #endif | ||
| 13 | |||
| 14 | // dissimilarity measure between pixels | ||
| 15 | float diff(F2D *r, int x1, int y1, int x2, int y2) | ||
| 16 | { | ||
| 17 | return sqrt(abs(( subsref(r,y1,x1) * subsref(r,y1,x1)) - ( subsref(r,y2,x2) * subsref(r,y2,x2)))); | ||
| 18 | } | ||
| 19 | |||
| 20 | I2D *segment_image(I2D* im, float sigma, float c, int min_size, int *num_ccs, | ||
| 21 | int* segments, edge* edges, | ||
| 22 | F2D* imageOut, F2D* tempOut, I2D* kernel, | ||
| 23 | F2D* edgeWeights, F2D* in, I2D* ind, | ||
| 24 | universe* u, | ||
| 25 | I2D* output) | ||
| 26 | { | ||
| 27 | int width = im->width; | ||
| 28 | int height = im->height; | ||
| 29 | int num = 0, x, y, i; | ||
| 30 | F2D* smooth_im; | ||
| 31 | //I2D *output; | ||
| 32 | //edge* edges; | ||
| 33 | int components = 0; | ||
| 34 | /* int *colors = (int *) malloc(width*height*sizeof(int)); */ | ||
| 35 | //segments = (int *) malloc(height*width*sizeof(int)); | ||
| 36 | |||
| 37 | // smooth each color channel | ||
| 38 | smooth_im = imageReblur(im, imageOut, tempOut, kernel); | ||
| 39 | |||
| 40 | //build graph | ||
| 41 | //edges = (edge*)malloc(sizeof(edge)*width*height*4); | ||
| 42 | |||
| 43 | for (y = 0; y < height; y++) | ||
| 44 | { | ||
| 45 | for (x = 0; x < width; x++) | ||
| 46 | { | ||
| 47 | segments[y*width+x] = -1; | ||
| 48 | if (x < width-1) | ||
| 49 | { | ||
| 50 | edges[num].a = y * width + x; | ||
| 51 | edges[num].b = y * width + (x+1); | ||
| 52 | edges[num].w = diff(smooth_im, x, y, x+1, y); | ||
| 53 | num++; | ||
| 54 | } | ||
| 55 | |||
| 56 | if (y < height-1) | ||
| 57 | { | ||
| 58 | edges[num].a = y * width + x; | ||
| 59 | edges[num].b = (y+1) * width + x; | ||
| 60 | edges[num].w = diff(smooth_im, x, y, x, y+1); | ||
| 61 | num++; | ||
| 62 | } | ||
| 63 | |||
| 64 | if ((x < width-1) && (y < height-1)) | ||
| 65 | { | ||
| 66 | edges[num].a = y * width + x; | ||
| 67 | edges[num].b = (y+1) * width + (x+1); | ||
| 68 | edges[num].w = diff(smooth_im, x, y, x+1, y+1); | ||
| 69 | num++; | ||
| 70 | } | ||
| 71 | |||
| 72 | if ((x < width-1) && (y > 0)) | ||
| 73 | { | ||
| 74 | edges[num].a = y * width + x; | ||
| 75 | edges[num].b = (y-1) * width + (x+1); | ||
| 76 | edges[num].w = diff(smooth_im, x, y, x+1, y-1); | ||
| 77 | num++; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | //free(smooth_im); | ||
| 83 | |||
| 84 | // segment | ||
| 85 | u = segment_graph(width*height, num, edges, c, edgeWeights, in, ind, u); | ||
| 86 | |||
| 87 | // post process small components | ||
| 88 | for (i = 0; i < num; i++) | ||
| 89 | { | ||
| 90 | int a, b; | ||
| 91 | a = find(u,edges[i].a); | ||
| 92 | b = find(u,edges[i].b); | ||
| 93 | if ((a != b) && ((u->elts[a].size < min_size) || (u->elts[b].size < min_size))) | ||
| 94 | join(u, a, b); | ||
| 95 | } | ||
| 96 | |||
| 97 | //free(edges); | ||
| 98 | arrayref(num_ccs,0) = u->num; | ||
| 99 | |||
| 100 | // pick random colors for each component | ||
| 101 | //output = iMallocHandle(height, width); | ||
| 102 | |||
| 103 | /* srand(time(0)); | ||
| 104 | for (i = 0; i < width*height; i++) | ||
| 105 | { | ||
| 106 | float temp; | ||
| 107 | temp = rand()/((float)RAND_MAX); | ||
| 108 | colors[i] = (int)(temp*255); | ||
| 109 | } | ||
| 110 | */ | ||
| 111 | |||
| 112 | for (y = 0; y < height; y++) | ||
| 113 | { | ||
| 114 | for (x = 0; x < width; x++) | ||
| 115 | { | ||
| 116 | int comp; | ||
| 117 | comp = find(u, y * width + x); | ||
| 118 | if(segments[comp] == -1) | ||
| 119 | segments[comp] = components++; | ||
| 120 | subsref(output, y, x) = segments[comp]; | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | /* | ||
| 125 | for (y = 0; y < height; y++) | ||
| 126 | { | ||
| 127 | for (x = 0; x < width; x++) | ||
| 128 | { | ||
| 129 | int comp; | ||
| 130 | comp = find(u, y * width + x); | ||
| 131 | subsref(output, y, x) = colors[comp]; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | */ | ||
| 135 | //free(u->elts); | ||
| 136 | //free(u); | ||
| 137 | //free(segments); | ||
| 138 | |||
| 139 | return output; | ||
| 140 | } | ||
| 141 | |||
| 142 | |||
