@@ -281,81 +281,81 @@ namespace cv
281
281
}
282
282
};
283
283
// !median 1x9 paralelized filter
284
+ template <typename T>
284
285
class Median1x9 :public ParallelLoopBody
285
286
{
286
287
private:
287
- uint8_t *original;
288
- uint8_t *filtered;
289
- int height, width,_stride ;
288
+ T *original;
289
+ T *filtered;
290
+ int height, width;
290
291
public:
291
292
Median1x9 (const Mat &originalImage, Mat &filteredImage)
292
293
{
293
- original = originalImage.data ;
294
- filtered = filteredImage.data ;
294
+ original = (T *) originalImage.data ;
295
+ filtered = (T *) filteredImage.data ;
295
296
height = originalImage.rows ;
296
297
width = originalImage.cols ;
297
- _stride = (int )originalImage.step ;
298
298
}
299
299
void operator ()(const cv::Range &r) const {
300
300
for (int m = r.start ; m <= r.end ; m++)
301
301
{
302
302
for (int n = 4 ; n < width - 4 ; ++n)
303
303
{
304
304
int k = 0 ;
305
- uint8_t window[9 ];
305
+ T window[9 ];
306
306
for (int i = n - 4 ; i <= n + 4 ; ++i)
307
- window[k++] = original[m * _stride + i];
307
+ window[k++] = original[m * width + i];
308
308
for (int j = 0 ; j < 5 ; ++j)
309
309
{
310
310
int min = j;
311
311
for (int l = j + 1 ; l < 9 ; ++l)
312
312
if (window[l] < window[min])
313
313
min = l;
314
- const uint8_t temp = window[j];
314
+ const T temp = window[j];
315
315
window[j] = window[min];
316
316
window[min] = temp;
317
317
}
318
- filtered[m * _stride + n] = window[4 ];
318
+ filtered[m * width + n] = window[4 ];
319
319
}
320
320
}
321
321
}
322
322
};
323
323
// !median 9x1 paralelized filter
324
+ template <typename T>
324
325
class Median9x1 :public ParallelLoopBody
325
326
{
326
327
private:
327
- uint8_t *original;
328
- uint8_t *filtered;
329
- int height, width, _stride ;
328
+ T *original;
329
+ T *filtered;
330
+ int height, width;
330
331
public:
331
332
Median9x1 (const Mat &originalImage, Mat &filteredImage)
332
333
{
333
- original = originalImage.data ;
334
- filtered = filteredImage.data ;
334
+ original = (T *) originalImage.data ;
335
+ filtered = (T *) filteredImage.data ;
335
336
height = originalImage.rows ;
336
337
width = originalImage.cols ;
337
- _stride = (int )originalImage.step ;
338
338
}
339
339
void operator ()(const Range &r) const {
340
340
for (int n = r.start ; n <= r.end ; ++n)
341
341
{
342
342
for (int m = 4 ; m < height - 4 ; ++m)
343
343
{
344
344
int k = 0 ;
345
- uint8_t window[9 ];
345
+ T window[9 ];
346
346
for (int i = m - 4 ; i <= m + 4 ; ++i)
347
- window[k++] = original[i * _stride + n];
347
+ window[k++] = original[i * width + n];
348
348
for (int j = 0 ; j < 5 ; j++)
349
349
{
350
350
int min = j;
351
351
for (int l = j + 1 ; l < 9 ; ++l)
352
352
if (window[l] < window[min])
353
353
min = l;
354
- const uint8_t temp = window[j];
354
+ const T temp = window[j];
355
355
window[j] = window[min];
356
356
window[min] = temp;
357
357
}
358
- filtered[m * _stride + n] = window[4 ];
358
+ filtered[m * width + n] = window[4 ];
359
359
}
360
360
}
361
361
}
@@ -471,6 +471,7 @@ namespace cv
471
471
parallel_for_ (cv::Range (win + 1 ,height - win - 1 ), agregateCost (partialSums,windowSize,maxDisp,cost));
472
472
}
473
473
// !remove small regions that have an area smaller than t, we fill the region with the average of the good pixels around it
474
+ template <typename T>
474
475
void smallRegionRemoval (const Mat ¤tMap, int t, Mat &out)
475
476
{
476
477
CV_Assert (currentMap.cols == out.cols );
@@ -480,11 +481,11 @@ namespace cv
480
481
int *specklePointX = (int *)speckleX.data ;
481
482
int *specklePointY = (int *)speckleY.data ;
482
483
memset (pus, 0 , previous_size * sizeof (pus[0 ]));
483
- uint8_t *map = currentMap.data ;
484
- uint8_t *outputMap = out.data ;
484
+ T *map = (T *) currentMap.data ;
485
+ T *outputMap = (T *) out.data ;
485
486
int height = currentMap.rows ;
486
487
int width = currentMap.cols ;
487
- uint8_t k = 1 ;
488
+ T k = 1 ;
488
489
int st, dr;
489
490
int di[] = { -1 , -1 , -1 , 0 , 1 , 1 , 1 , 0 },
490
491
dj[] = { -1 , 0 , 1 , 1 , 1 , 0 , -1 , -1 };
@@ -502,8 +503,8 @@ namespace cv
502
503
}
503
504
else if (map[iw + j] == 0 )
504
505
{
505
- int nr = 1 ;
506
- int avg = 0 ;
506
+ T nr = 1 ;
507
+ T avg = 0 ;
507
508
speckle_size = dr;
508
509
specklePointX[dr] = i;
509
510
specklePointY[dr] = j;
@@ -520,7 +521,7 @@ namespace cv
520
521
if (ii + di[d] >= 0 && ii + di[d] < height && jj + dj[d] >= 0 && jj + dj[d] < width &&
521
522
pus[(ii + di[d]) * width + jj + dj[d]] == 0 )
522
523
{
523
- int val = map[(ii + di[d]) * width + jj + dj[d]];
524
+ T val = map[(ii + di[d]) * width + jj + dj[d]];
524
525
if (val == 0 )
525
526
{
526
527
map[(ii + di[d]) * width + jj + dj[d]] = k;
@@ -529,7 +530,7 @@ namespace cv
529
530
dr++;
530
531
pus[(ii + di[d]) * width + jj + dj[d]] = 1 ;
531
532
}// this means that my point is a good point to be used in computing the final filling value
532
- else if (val > 2 && val < 250 )
533
+ else if (val >= 1 && val < 250 )
533
534
{
534
535
avg += val;
535
536
nr++;
@@ -540,7 +541,7 @@ namespace cv
540
541
}// if hole size is smaller than a specified threshold we fill the respective hole with the average of the good neighbours
541
542
if (st - speckle_size <= t)
542
543
{
543
- uint8_t fillValue = (uint8_t )(avg / nr);
544
+ T fillValue = (T )(avg / nr);
544
545
while (speckle_size < st)
545
546
{
546
547
int ii = specklePointX[speckle_size];
@@ -573,18 +574,20 @@ namespace cv
573
574
public:
574
575
// !a median filter of 1x9 and 9x1
575
576
// !1x9 median filter
577
+ template <typename T>
576
578
void Median1x9Filter (const Mat &originalImage, Mat &filteredImage)
577
579
{
578
580
CV_Assert (originalImage.rows == filteredImage.rows );
579
581
CV_Assert (originalImage.cols == filteredImage.cols );
580
- parallel_for_ (Range (1 ,originalImage.rows - 2 ), Median1x9 (originalImage,filteredImage));
582
+ parallel_for_ (Range (1 ,originalImage.rows - 2 ), Median1x9<T> (originalImage,filteredImage));
581
583
}
582
584
// !9x1 median filter
585
+ template <typename T>
583
586
void Median9x1Filter (const Mat &originalImage, Mat &filteredImage)
584
587
{
585
588
CV_Assert (originalImage.cols == filteredImage.cols );
586
589
CV_Assert (originalImage.cols == filteredImage.cols );
587
- parallel_for_ (Range (1 ,originalImage.cols - 2 ), Median9x1 (originalImage,filteredImage));
590
+ parallel_for_ (Range (1 ,originalImage.cols - 2 ), Median9x1<T> (originalImage,filteredImage));
588
591
}
589
592
// !constructor for the matching class
590
593
// !maxDisp - represents the maximum disparity
0 commit comments