Skip to content

Commit 461d9c0

Browse files
committed
✨🔥🎨🔨Add Image2D
1 parent 1b02310 commit 461d9c0

File tree

11 files changed

+443
-17
lines changed

11 files changed

+443
-17
lines changed

CL/ImageFilter2D.cl

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
// Edge filter of image
3+
4+
__kernel void edge_filter(__read_only image2d_t srcImg,
5+
__write_only image2d_t dstImg,
6+
sampler_t sampler,
7+
int width, int height)
8+
{
9+
10+
float kernelWeights[9] = { -1.0f, 0.0f, -1.0f,
11+
0.0f , 4.0f, 0.0f,
12+
-1.0f, 0.0f, -1.0f };
13+
14+
int2 startImageCoord = (int2) (get_global_id(0) - 1, get_global_id(1) - 1);
15+
int2 endImageCoord = (int2) (get_global_id(0) + 1, get_global_id(1) + 1);
16+
int2 outImageCoord = (int2) (get_global_id(0), get_global_id(1));
17+
18+
if (outImageCoord.x < width && outImageCoord.y < height)
19+
{
20+
int weight = 0;
21+
float4 outColor = (float4)(0.0f, 0.0f, 0.0f, 0.0f);
22+
for( int y = startImageCoord.y; y <= endImageCoord.y; y++)
23+
{
24+
for( int x = startImageCoord.x; x <= endImageCoord.x; x++)
25+
{
26+
//outColor:(R,G,B,A)
27+
outColor += (read_imagef(srcImg, sampler, (int2)(x, y)) * kernelWeights[weight]);
28+
weight += 1;
29+
}
30+
}
31+
32+
// Write the output value to image
33+
write_imagef(dstImg, outImageCoord, outColor);
34+
}
35+
}

GPU/image2D.png

148 KB
Loading

README.md

+44-15
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@ filter2D is studied as well.
1010
Inter(R) Corporation Intel(R) Core(TM) i7-4710MQ CPU@2.5GHZ
1111
NVIDIA Corporation GeForce GTX 850M
1212
## How to Run
13+
Buffer Method
1314
``` shell
1415
$ git clone git@github.com:ShoupingShan/OpenCL-Image-Filter.git
15-
$ cd OpenCL-Image-Filter
16+
$ cd OpenCL-Image-Filter/src/buffer_method
17+
$ make clean
18+
$ make
19+
$ ./pic
20+
```
21+
Image2D Method
22+
``` shell
23+
$ git clone git@github.com:ShoupingShan/OpenCL-Image-Filter.git
24+
$ cd OpenCL-Image-Filter/src/bimage2D_method
1625
$ make clean
1726
$ make
1827
$ ./pic
@@ -35,29 +44,49 @@ $ ./pic
3544
#### 2.OpenCV
3645
![OpenCV](CPU/OpenCV.jpg)
3746

38-
### OpenCL_CPU and OpenCL_GPU results
47+
### OpenCL_CPU, OpenCL_GPU and OpenCL_Image2D results
3948
#### 1.OpenCL_CPU
4049
![OpenCL_CPU](CPU/OpenCL_cpu.jpg)
4150
#### 2.OpenCL_GPU
4251
![OpenCL_GPU](GPU/OpenCL_gpu.jpg)
52+
#### 3.OpenCL_Image2D
53+
![OpenCL_GPU](GPU/image2D.png)
4354

4455
### Run time compare
45-
| `Method`/`Time(/s)` | Normal | OpenCV | OpenCL(CPU) | OpenCL(GPU) |
46-
|:--------------------:|:-------:|:-------:|:------------:|:-------------:|
47-
| 1 | 0.015371 | 0.00033 |0.005138 |0.000637 |
48-
| 2 | 0.015318 | 0.000313|0.005108 |0.00064 |
49-
| 3 | 0.01417 | 0.000312|0.005323 |0.000651 |
50-
| 4 | 0.014164 | 0.000331|0.005341 |0.000621 |
51-
| 5 | 0.014439 | 0.000308|0.005168 |0.000623 |
52-
| 6 | 0.014289 | 0.00031 |0.006278 |0.000624 |
53-
| 7 | 0.014349 | 0.000311|0.005307 |0.000625 |
54-
| 8 | 0.014133 | 0.000307|0.00513 |0.000624 |
55-
| 9 | 0.014122 | 0.000315|0.005227 |0.000624 |
56-
|10 | 0.014315 | 0.00033 |0.005174 |0.000629 |
57-
|Average Time/s | 0.014467| 0.0003145|0.0053194 |0.0006298 |
56+
| `Method`/`Time(/s)` | Normal | OpenCV | OpenCL(CPU) | OpenCL(GPU) |Image2D|
57+
|:--------------------:|:-------:|:-------:|:------------:|:-------------:|:--:|
58+
| 1 | 0.015371 | 0.00033 |0.005138 |0.000637 | 0.000375|
59+
| 2 | 0.015318 | 0.000313|0.005108 |0.00064 |0.000367|
60+
| 3 | 0.01417 | 0.000312|0.005323 |0.000651 |0.000377|
61+
| 4 | 0.014164 | 0.000331|0.005341 |0.000621 |0.00038|
62+
| 5 | 0.014439 | 0.000308|0.005168 |0.000623 |0.00037|
63+
| 6 | 0.014289 | 0.00031 |0.006278 |0.000624 |0.000364|
64+
| 7 | 0.014349 | 0.000311|0.005307 |0.000625 |0.000374|
65+
| 8 | 0.014133 | 0.000307|0.00513 |0.000624 |0.000379|
66+
| 9 | 0.014122 | 0.000315|0.005227 |0.000624 |0.000377|
67+
|10 | 0.014315 | 0.00033 |0.005174 |0.000629 |0.000372|
68+
|Average Time/s | `0.014467`| `0.0003145`|`0.0053194` |`0.0006298` |`0.000374`|
5869

5970

6071
![runtime](image/runtime.png)
6172

73+
### Run time changed by image size
74+
75+
| `Method`/`Time(/s)` | Normal | OpenCV | OpenCL(CPU) | OpenCL(GPU) | Image2D|
76+
|:--------------------:|:-------:|:-------:|:------------:|:-------------:|:---:|
77+
| 256*256 | 0.003827 | 0.000123 |0.001939 |0.000408 | 0.000351 |
78+
| 512*512 | 0.014761 | 0.0003444|0.005273 |0.000589 | 0.000375|
79+
| 1280*720 | 0.0050005 | 0.001282|0.017817 |0.001345 | 0.000485|
80+
| 1920*1080 | 0.110346 | 0.002831|0.037708 |0.002273 | 0.000926|
81+
| 2560*1440 | 0.195084 | 0.005242|0.06523|0.003523 |0.001367 |
82+
| 2880*2560 | 0.390584 | 0.09822 |0.128243 |0.009293 | 0.0022|
83+
| 3840*2160 | 0.441809 | 0.0118741|0.143425 |0.010045 |0.002367 |
84+
| 7680*4320 | 1.7679 | 0.04676|0.56525 |0.029638 |0.007554 |
85+
86+
87+
![dimensiontime](image/dimension_time.png)
88+
89+
### OpenCV & OpenCL_GPU & OpenCL_Image2D
90+
![OOO](image/image2dopencvopencl.png)
6291
## Contact me
6392
**Email**: shp395210@outlook.com

image/dimension_time.png

54.1 KB
Loading

image/image2dopencvopencl.png

49.9 KB
Loading
File renamed without changes.
File renamed without changes.

pic.cpp renamed to src/buffer_method/pic.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <CL/cl.h>
88
#include <sys/types.h>
99
#include<fcntl.h>
10-
#define COMPUTE_KERNEL_FILENAME ("./CL/oclFilter.cl") // path to file
10+
#define COMPUTE_KERNEL_FILENAME ("../../CL/oclFilter.cl") // path to file
1111
using namespace std;
1212
int width = 512,height = 512; // image resolution, change it to yours one
1313
cl_int err; // error output
@@ -237,7 +237,7 @@ int main()
237237
fout1.open("./result/OpenCL.txt",ios::out);
238238
fout2.open("./result/Normal.txt",ios::out);
239239
fout3.open("./result/OpenCV.txt",ios::out);
240-
Mat rgbimage = imread("./data/Lena.jpg");
240+
Mat rgbimage = imread("../../data/Lena.jpg");
241241
if(!rgbimage.data)//judge weather the image load successfully
242242
{
243243
cout << "Fail to load image!" << endl;

src/image2D_method/OpenCL_image_2d

371 KB
Binary file not shown.

0 commit comments

Comments
 (0)