From f618466c25d43f3bae9e40920273bf77de1e1149 Mon Sep 17 00:00:00 2001 From: leochanj105 Date: Mon, 19 Oct 2020 23:09:30 -0400 Subject: initial sd-vbs initial sd-vbs add sd-vbs sd-vbs --- SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c | 142 +++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c (limited to 'SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c') diff --git a/SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c b/SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c new file mode 100644 index 0000000..72bc16f --- /dev/null +++ b/SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c @@ -0,0 +1,142 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#include +#include +#include +#include "segment.h" + +#ifndef M_PI +#define M_PI 3.141592653589793 +#endif + +// dissimilarity measure between pixels +float diff(F2D *r, int x1, int y1, int x2, int y2) +{ + return sqrt(abs(( subsref(r,y1,x1) * subsref(r,y1,x1)) - ( subsref(r,y2,x2) * subsref(r,y2,x2)))); +} + +I2D *segment_image(I2D* im, float sigma, float c, int min_size, int *num_ccs, + int* segments, edge* edges, + F2D* imageOut, F2D* tempOut, I2D* kernel, + F2D* edgeWeights, F2D* in, I2D* ind, + universe* u, + I2D* output) +{ + int width = im->width; + int height = im->height; + int num = 0, x, y, i; + F2D* smooth_im; + //I2D *output; + //edge* edges; + int components = 0; +/* int *colors = (int *) malloc(width*height*sizeof(int)); */ + //segments = (int *) malloc(height*width*sizeof(int)); + + // smooth each color channel + smooth_im = imageReblur(im, imageOut, tempOut, kernel); + + //build graph + //edges = (edge*)malloc(sizeof(edge)*width*height*4); + + for (y = 0; y < height; y++) + { + for (x = 0; x < width; x++) + { + segments[y*width+x] = -1; + if (x < width-1) + { + edges[num].a = y * width + x; + edges[num].b = y * width + (x+1); + edges[num].w = diff(smooth_im, x, y, x+1, y); + num++; + } + + if (y < height-1) + { + edges[num].a = y * width + x; + edges[num].b = (y+1) * width + x; + edges[num].w = diff(smooth_im, x, y, x, y+1); + num++; + } + + if ((x < width-1) && (y < height-1)) + { + edges[num].a = y * width + x; + edges[num].b = (y+1) * width + (x+1); + edges[num].w = diff(smooth_im, x, y, x+1, y+1); + num++; + } + + if ((x < width-1) && (y > 0)) + { + edges[num].a = y * width + x; + edges[num].b = (y-1) * width + (x+1); + edges[num].w = diff(smooth_im, x, y, x+1, y-1); + num++; + } + } + } + + //free(smooth_im); + + // segment + u = segment_graph(width*height, num, edges, c, edgeWeights, in, ind, u); + + // post process small components + for (i = 0; i < num; i++) + { + int a, b; + a = find(u,edges[i].a); + b = find(u,edges[i].b); + if ((a != b) && ((u->elts[a].size < min_size) || (u->elts[b].size < min_size))) + join(u, a, b); + } + + //free(edges); + arrayref(num_ccs,0) = u->num; + + // pick random colors for each component + //output = iMallocHandle(height, width); + +/* srand(time(0)); + for (i = 0; i < width*height; i++) + { + float temp; + temp = rand()/((float)RAND_MAX); + colors[i] = (int)(temp*255); + } +*/ + + for (y = 0; y < height; y++) + { + for (x = 0; x < width; x++) + { + int comp; + comp = find(u, y * width + x); + if(segments[comp] == -1) + segments[comp] = components++; + subsref(output, y, x) = segments[comp]; + } + } + +/* + for (y = 0; y < height; y++) + { + for (x = 0; x < width; x++) + { + int comp; + comp = find(u, y * width + x); + subsref(output, y, x) = colors[comp]; + } + } +*/ + //free(u->elts); + //free(u); + //free(segments); + + return output; +} + + -- cgit v1.2.2