oozsen
1
Here is my structure :
struct Pixel {int r, c;};
struct EdgeSegment {
Pixel *pixels;
int noPixels;
};
struct EdgeMap {
public:
EdgeSegment *segments;
int noSegments;
public:
// constructor
EdgeMap(int capacity){
segments = new EdgeSegment[capacity];
noSegments = 0;
} //end-EdgeMap
// Destructor
~EdgeMap(){delete segments;}
};
And my serial code is here :
void Segments2Lines(EdgeSegment *segments, int noSegments, EDLines *lines){
double *x;
double *y;
x = (double*)malloc(WIDTH+HEIGHT*8);
y = (double*)malloc(WIDTH+HEIGHT*8);
for (int segmentNo=0; segmentNo<noSegments; segmentNo++){
for(int i=0; i<segments[segmentNo].noPixels; i++){
x[i]=segments[segmentNo].pixels[i].c;
y[i]=segments[segmentNo].pixels[i].r;
}
SplitSegment2Lines(x, y, segments[segmentNo].noPixels, segmentNo, lines);
}
free(x);
free(y);
}
Is the above code like the following version of the kernel?
__global__ void Segments2LinesKernel(EdgeSegment *segments, double *d_x, double *d_y, EDLines *lines){
__shared__ double *x, *y;
int i = blockIdx.x * blockDim.x + threadIdx.x;
int nopixels = segments[i].noPixels;
boolean b = true;
int count = 0;
while (b){
x[i]=segments[i].pixels[count].c;
y[i]=segments[i].pixels[count].r;
if (count < nopixels) count++;
else b = false;
SplitSegment2LinesKernel(x, y, segments[i].noPixels, i, lines);
}
}
how many segment and pixel ?
perhaps do only one kernel with 2 variable one is the c for all segment pixel the other is r who do
x[i]=c(?);
y[i]=r(?);
and the SplitSegment2LinesKernel in the same kernel
oozsen
3
For example 512x512 pixels Lena’s image output shown below :
=========== TOTAL NUMBER of SEGMENTS [489]===========
+===SEGMENT: 0. NoPixels: 13 ====+
+------+------+--------
| Row |Column|Segment|
+------+------+--------
| 2| 55| 0|
| 3| 55| 0|
| 4| 55| 0|
| 5| 56| 0|
| 6| 56| 0|
| 6| 57| 0|
| 7| 58| 0|
| 8| 58| 0|
| 9| 57| 0|
| 10| 56| 0|
| 9| 55| 0|
| 8| 55| 0|
| 7| 55| 0|
+------+------+-------+
+===SEGMENT: 1. NoPixels: 252 ====+
+------+------+--------
| Row |Column|Segment|
+------+------+--------
| 2| 59| 1|
| 3| 60| 1|
| 4| 61| 1|
| 5| 62| 1|
| 6| 63| 1|
| 7| 63| 1|
| 8| 63| 1|
| 9| 63| 1|
| 10| 62| 1|
| 11| 61| 1|
| 12| 61| 1|
| 13| 61| 1|
| 14| 62| 1|
| 15| 62| 1|
| 16| 62| 1|
| 17| 61| 1|
| 18| 62| 1|
| 19| 63| 1|
| 20| 63| 1|
| 21| 63| 1|
| 22| 62| 1|
| 23| 62| 1|
| 24| 62| 1|
| 25| 62| 1|
| 26| 62| 1|
| 27| 62| 1|
| 28| 62| 1|
| 29| 61| 1|
| 30| 61| 1|
| 31| 61| 1|
| 32| 61| 1|
| 33| 61| 1|
| 34| 61| 1|
| 35| 61| 1|
| 36| 61| 1|
| 37| 62| 1|
| 38| 62| 1|
| 39| 62| 1|
| 40| 61| 1|
| 41| 61| 1|
| 42| 61| 1|
| 43| 61| 1|
| 44| 61| 1|
| 45| 61| 1|
| 46| 61| 1|
| 47| 62| 1|
| 48| 62| 1|
| 49| 62| 1|
| 50| 62| 1|
| 51| 61| 1|
| 52| 61| 1|
| 53| 61| 1|
| 54| 61| 1|
| 55| 62| 1|
| 56| 62| 1|
| 57| 62| 1|
| 58| 62| 1|
| 59| 62| 1|
| 60| 62| 1|
| 61| 62| 1|
| 62| 62| 1|
| 63| 62| 1|
| 64| 62| 1|
| 65| 62| 1|
| 66| 62| 1|
| 67| 62| 1|
| 68| 62| 1|
| 69| 62| 1|
| 70| 63| 1|
| 71| 63| 1|
| 72| 63| 1|
| 73| 63| 1|
| 74| 62| 1|
| 75| 62| 1|
| 76| 62| 1|
| 77| 63| 1|
| 78| 63| 1|
| 79| 62| 1|
| 80| 62| 1|
| 81| 62| 1|
| 82| 62| 1|
| 83| 63| 1|
| 84| 63| 1|
| 85| 63| 1|
| 86| 63| 1|
| 87| 63| 1|
| 88| 62| 1|
| 89| 61| 1|
| 90| 62| 1|
| 91| 62| 1|
| 92| 62| 1|
| 93| 61| 1|
| 94| 62| 1|
| 95| 63| 1|
| 96| 64| 1|
| 97| 64| 1|
| 98| 64| 1|
| 99| 63| 1|
| 100| 63| 1|
| 101| 63| 1|
| 102| 64| 1|
| 103| 65| 1|
| 104| 64| 1|
| 105| 63| 1|
| 106| 62| 1|
| 107| 61| 1|
| 108| 61| 1|
| 109| 61| 1|
| 110| 62| 1|
| 111| 62| 1|
| 112| 63| 1|
| 113| 63| 1|
| 114| 63| 1|
| 115| 63| 1|
| 116| 63| 1|
| 117| 64| 1|
| 118| 63| 1|
| 119| 63| 1|
| 120| 62| 1|
| 121| 62| 1|
| 122| 62| 1|
| 123| 62| 1|
| 124| 62| 1|
| 125| 62| 1|
| 126| 62| 1|
| 127| 63| 1|
| 128| 63| 1|
| 129| 63| 1|
| 130| 63| 1|
| 131| 63| 1|
| 132| 63| 1|
| 133| 62| 1|
| 134| 62| 1|
| 135| 63| 1|
| 136| 63| 1|
| 137| 63| 1|
| 138| 63| 1|
| 139| 63| 1|
| 140| 62| 1|
| 140| 63| 1|
| 141| 62| 1|
| 142| 61| 1|
| 143| 61| 1|
| 144| 62| 1|
| 145| 63| 1|
| 146| 63| 1|
| 147| 63| 1|
| 148| 63| 1|
| 149| 63| 1|
| 150| 63| 1|
| 151| 63| 1|
| 152| 62| 1|
| 153| 63| 1|
| 154| 63| 1|
| 155| 63| 1|
| 156| 62| 1|
| 157| 62| 1|
| 158| 62| 1|
| 159| 61| 1|
| 160| 61| 1|
| 161| 60| 1|
| 162| 60| 1|
| 163| 61| 1|
| 164| 61| 1|
| 165| 61| 1|
| 166| 61| 1|
| 167| 62| 1|
| 168| 63| 1|
| 169| 63| 1|
| 170| 62| 1|
| 171| 62| 1|
| 172| 62| 1|
| 173| 62| 1|
| 174| 62| 1|
| 175| 62| 1|
| 176| 62| 1|
| 177| 62| 1|
| 178| 62| 1|
| 179| 62| 1|
| 180| 62| 1|
| 181| 63| 1|
| 182| 63| 1|
| 183| 63| 1|
| 184| 62| 1|
| 185| 62| 1|
| 186| 62| 1|
| 187| 62| 1|
| 188| 62| 1|
| 189| 62| 1|
| 190| 62| 1|
| 191| 62| 1|
| 192| 62| 1|
| 193| 62| 1|
| 194| 62| 1|
| 195| 62| 1|
| 196| 62| 1|
| 197| 62| 1|
| 198| 62| 1|
| 199| 62| 1|
| 200| 62| 1|
| 201| 63| 1|
| 202| 63| 1|
| 203| 63| 1|
| 204| 63| 1|
| 205| 63| 1|
| 206| 63| 1|
| 207| 63| 1|
| 208| 63| 1|
| 209| 62| 1|
| 210| 62| 1|
| 211| 63| 1|
| 212| 63| 1|
| 213| 63| 1|
| 214| 63| 1|
| 215| 63| 1|
| 216| 63| 1|
| 217| 63| 1|
| 218| 63| 1|
| 219| 63| 1|
| 220| 63| 1|
| 221| 63| 1|
| 222| 63| 1|
| 223| 63| 1|
| 224| 63| 1|
| 225| 63| 1|
| 226| 63| 1|
| 227| 63| 1|
| 228| 63| 1|
| 229| 63| 1|
| 230| 63| 1|
| 231| 63| 1|
| 232| 63| 1|
| 233| 62| 1|
| 234| 62| 1|
| 235| 62| 1|
| 236| 62| 1|
| 237| 62| 1|
| 238| 61| 1|
| 237| 60| 1|
| 236| 59| 1|
| 235| 58| 1|
| 234| 57| 1|
| 233| 56| 1|
| 232| 56| 1|
| 231| 56| 1|
| 230| 56| 1|
| 229| 56| 1|
| 228| 56| 1|
| 227| 56| 1|
| 226| 56| 1|
| 225| 56| 1|
| 224| 55| 1|
+------+------+-------+
+===SEGMENT: 2. NoPixels: 146 ====+
+------+------+--------
| Row |Column|Segment|
+------+------+--------
| 2| 403| 2|
| 3| 403| 2|
| 4| 403| 2|
| 5| 404| 2|
| 6| 404| 2|
| 7| 405| 2|
| 8| 405| 2|
| 9| 406| 2|
| 10| 407| 2|
.
.
.
+===SEGMENT: 487. NoPixels: 14 ====+
+------+------+--------
| Row |Column|Segment|
+------+------+--------
| 503| 453| 487|
| 504| 452| 487|
| 504| 451| 487|
| 505| 450| 487|
| 505| 451| 487|
| 506| 450| 487|
| 506| 449| 487|
| 507| 448| 487|
| 507| 447| 487|
| 508| 446| 487|
| 509| 445| 487|
| 509| 444| 487|
| 509| 443| 487|
| 509| 442| 487|
+------+------+-------+
+===SEGMENT: 488. NoPixels: 9 ====+
+------+------+--------
| Row |Column|Segment|
+------+------+--------
| 504| 165| 488|
| 505| 164| 488|
| 506| 163| 488|
| 506| 164| 488|
| 507| 165| 488|
| 508| 166| 488|
| 509| 167| 488|
| 509| 168| 488|
| 509| 169| 488|
+------+------+-------+