Optimized Belief Propagation (CPU and GPU)
SharedSmoothImageFuncts.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2024 Scott Grauer-Gray
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
28 #ifndef SHAREDSMOOTHIMAGEFUNCTS_H_
29 #define SHAREDSMOOTHIMAGEFUNCTS_H_
30 
31 #include "RunImp/UtilityFuncts.h"
34 #include "SharedBpUtilFuncts.h"
35 
36 namespace beliefprop {
37 
54 template <BpImData_t T>
56  unsigned int x_val, unsigned int y_val, const T* image_to_filter,
57  float* filtered_image, unsigned int width_images, unsigned int height_images,
58  const float* image_filter, unsigned int size_filter)
59 {
60  float filtered_pixel_val = image_filter[0] * ((float)image_to_filter[y_val*width_images + x_val]);
61 
62  for (unsigned int i = 1; i < size_filter; i++) {
63  filtered_pixel_val +=
64  image_filter[i] *
65  (((float)image_to_filter[y_val*width_images + (unsigned int)util_functs::GetMax((int)x_val - (int)i, 0)]) +
66  ((float)image_to_filter[y_val*width_images + util_functs::GetMin(x_val + i, width_images - 1)]));
67  }
68 
69  filtered_image[y_val*width_images + x_val] = filtered_pixel_val;
70 }
71 
88 template <BpImData_t T>
90  unsigned int x_val, unsigned int y_val, const T* image_to_filter,
91  float* filtered_image, unsigned int width_images, unsigned int height_images,
92  const float* image_filter, unsigned int size_filter)
93 {
94  float filtered_pixel_val = image_filter[0] * ((float)image_to_filter[y_val*width_images + x_val]);
95 
96  for (unsigned int i = 1; i < size_filter; i++) {
97  filtered_pixel_val +=
98  image_filter[i] *
99  ((float)(image_to_filter[(unsigned int)util_functs::GetMax((int)y_val - (int)i, 0) * width_images + x_val]) +
100  ((float)image_to_filter[util_functs::GetMin(y_val + i, height_images - 1) * width_images + x_val]));
101  }
102 
103  filtered_image[y_val * width_images + x_val] = filtered_pixel_val;
104 }
105 
106 }
107 
108 #endif /* SHAREDSMOOTHIMAGEFUNCTS_H_ */
Define constraint for data type in belief propagation processing related to image processing.
Define constraints for data type in processing.
Utility functions for belief propagation processing that are used in both optimized CPU and CUDA impl...
Contains namespace with utility functions for implementation.
#define ARCHITECTURE_ADDITION
Definition: UtilityFuncts.h:37
Namespace for enums, constants, structures, and functions specific to belief propagation processing.
ARCHITECTURE_ADDITION void FilterImageAcrossProcessPixel(unsigned int x_val, unsigned int y_val, const T *image_to_filter, float *filtered_image, unsigned int width_images, unsigned int height_images, const float *image_filter, unsigned int size_filter)
kernel to apply a horizontal filter on each pixel of the image in parallel the input image is stored ...
ARCHITECTURE_ADDITION void FilterImageVerticalProcessPixel(unsigned int x_val, unsigned int y_val, const T *image_to_filter, float *filtered_image, unsigned int width_images, unsigned int height_images, const float *image_filter, unsigned int size_filter)
kernel to apply a vertical filter on each pixel of the image in parallel the input image is stored as...
requires std::is_arithmetic_v< T > ARCHITECTURE_ADDITION T GetMin(T val1, T val2)
Definition: UtilityFuncts.h:65
requires std::is_arithmetic_v< T > ARCHITECTURE_ADDITION T GetMax(T val1, T val2)
Definition: UtilityFuncts.h:71