

Unsigned char x0, x1, x2, x3, x4, x5, 圆, x7, x8 įor (int j = 1 j > (in_gpu, out_gpu, imgHeight, imgWidth) Int y = threadIdx.y + blockDim.y * blockIdx.y Int x = threadIdx.x + blockDim.x * blockIdx.x _global_ void sobel_gpu(unsigned char* in, unsigned char* out, int imgHeight, int imgWidth)
DIM3 BLOCKSPERGRID CODE
The code is as follows : #include "cuda_runtime.h" Each thread reads the value around a pixel ( In the following code comments x0~x8), Then calculate While using CUDA The principle of solving this problem is, Each thread processes one pixel. Threads can use the gridDim structure, which is a dim3, as a record of how many. Simply put, it may be clearer to use an animation : example) but the maximum number of blocks per grid is very large.

The approximate values of the transverse and longitudinal gradients of each pixel of the image can be combined with the following formula, To calculate the gradient size. If A Represents the original image, G x G_x G x and G y G_y G y They represent the images of transverse and longitudinal edge detection respectively, The formula is as follows : Then we can get the approximate values of the horizontal and longitudinal brightness difference respectively. It contains two groups 3 x 3 Matrix, Do plane convolution with the image for transverse and longitudinal respectively. It is a relatively small and integer filter, Relatively few calculations are required, But for places with high frequency variation in the image, His gradient approximation will be rough. Sobel Operator is one of the commonly used operators in image processing, It is often used for edge detection in computer vision. Let's start with a brief introduction Sobel edge detection :

These are the top rated real world C (CSharp) examples of extracted from open source projects. CUDA Example Series IV : utilize GPU Speed up Sobel edge detection C (CSharp) ManagedCuda.NVRTC CudaRuntimeCompiler - 2 examples found.
