-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreconstructionCUDA.cu
223 lines (216 loc) · 7.13 KB
/
reconstructionCUDA.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#pragma once
//#include "header.cuh"
//#include "initANDcheck.h"
#include "reconstructionCUDA.cuh"
__global__ void Zhuan_Complex_kernel(float *PSF_1_gpu, cufftComplex *PSF_1_gpu_Complex, int total)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < total)
{
PSF_1_gpu_Complex[i].x = PSF_1_gpu[i];
PSF_1_gpu_Complex[i].y = 0;
}
}
__global__ void PSF_unshort(float *PSF_1_gpu, unsigned short *PSF, int total)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < total)
{
if (PSF_1_gpu[i] < 0)
{
PSF[i] = 0;
}
else if (PSF_1_gpu[i] > 65535)
{
PSF[i] = 65535;
}
else
{
PSF[i] = (int)(PSF_1_gpu[i] + 0.5);
}
}
}
__global__ void initial_kernel_1(float *ImgEst, float *Ratio, int total)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < total)
{
ImgEst[i] = 0;
Ratio[i] = 1;
}
}
__global__ void gpuObjRecon_fuzhi(float *gpuObjRecon, int total)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < total)
{
gpuObjRecon[i] = 1;
}
}
__global__ void initial_kernel_3(float *gpuObjRecROI, int total)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < total)
{
gpuObjRecROI[i] = 1;
}
}
__global__ void ImgExp_ge(unsigned short *Img_gpu, int BkgMean, float *ImgExp, int total)
{
//Turn the result of the difference less than 0 into 0, greater than 0 rounded, greater than 65535 into 65535
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < total)
{
if ((Img_gpu[i] - BkgMean) < 0)
{
ImgExp[i] = 0;
}
else if ((Img_gpu[i] - BkgMean) > 65535)
{
ImgExp[i] = 65535;
}
else
{
ImgExp[i] = (int)((Img_gpu[i] - BkgMean) + 0.5);
}
}
}
__global__ void Ratio_fuzhi(float *Ratio, int total)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < total)
{
Ratio[i] = 1;
}
}
__global__ void OTF_mul_gpuObjRecon_Complex(cufftComplex *OTF, cufftComplex *gpuObjRecon_Complex, int total)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < total)
{
float aaa = OTF[i].x*gpuObjRecon_Complex[i].x - OTF[i].y*gpuObjRecon_Complex[i].y;//Real Department Results
float bbb = OTF[i].x*gpuObjRecon_Complex[i].y + OTF[i].y*gpuObjRecon_Complex[i].x;//Virtual Part Results
gpuObjRecon_Complex[i].x = aaa;
gpuObjRecon_Complex[i].y = bbb;
}
}
__global__ void ifftshift_real_max(cufftComplex *OTF, float *float_temp, int PSF_size_1, int PSF_size_2, int PSF_size_3)
{
const int i = blockDim.x * blockIdx.x + threadIdx.x;
const int j = blockDim.y * blockIdx.y + threadIdx.y;
const int k = blockDim.z * blockIdx.z + threadIdx.z;
int lie_half = PSF_size_2 / 2;
if (i < PSF_size_1 / 2 && j < PSF_size_2 && k < PSF_size_3)
{
//Implement the image ifftshift+real+max, i.e.: divide the image into 4 quadrants, swap the first and third translations, swap the second and fourth translations
float_temp[k*PSF_size_1*PSF_size_2 + (i + PSF_size_1 / 2)*PSF_size_2 + j + lie_half - j / lie_half * 512] = OTF[k*PSF_size_1*PSF_size_2 + i * PSF_size_2 + j].x >= 0 ? OTF[k*PSF_size_1*PSF_size_2 + i * PSF_size_2 + j].x : 0;
float_temp[k*PSF_size_1*PSF_size_2 + i * PSF_size_2 + j] = OTF[k*PSF_size_1*PSF_size_2 + (i + PSF_size_1 / 2)*PSF_size_2 + j + lie_half - j / lie_half * PSF_size_2].x >= 0 ? OTF[k*PSF_size_1*PSF_size_2 + (i + PSF_size_1 / 2)*PSF_size_2 + j + lie_half - j / lie_half * PSF_size_2].x : 0;
}
}
__global__ void ifftshift(cufftComplex *OTF, float *float_temp, int PSF_size_1, int PSF_size_2, int PSF_size_3, cufftComplex *OTF_ifftshift)
{
const int i = blockDim.x * blockIdx.x + threadIdx.x;
const int j = blockDim.y * blockIdx.y + threadIdx.y;
const int k = blockDim.z * blockIdx.z + threadIdx.z;
int lie_half = PSF_size_2 / 2;
if (i < PSF_size_1 / 2 && j < PSF_size_2 && k < PSF_size_3)
{
//Implement the image ifftshift, i.e.: divide the image into 4 quadrants, first and third translation swap, second and fourth translation swap
OTF_ifftshift[k*PSF_size_1*PSF_size_2 + (i + PSF_size_1 / 2)*PSF_size_2 + j + lie_half - j / lie_half * 512] = OTF[k*PSF_size_1*PSF_size_2 + i * PSF_size_2 + j];
OTF_ifftshift[k*PSF_size_1*PSF_size_2 + i * PSF_size_2 + j] = OTF[k*PSF_size_1*PSF_size_2 + (i + PSF_size_1 / 2)*PSF_size_2 + j + lie_half - j / lie_half * PSF_size_2];
}
}
__global__ void float_temp_sum(float *float_temp, float *ImgEst, int PSF_size_1, int PSF_size_2, int PSF_size_3)
{
const int i = blockDim.x * blockIdx.x + threadIdx.x;
const int j = blockDim.y * blockIdx.y + threadIdx.y;
if (i < PSF_size_1 && j < PSF_size_2)
{
ImgEst[i*PSF_size_2 + j] = 0;
for (int k = 0; k < PSF_size_3; k++)
{
ImgEst[i*PSF_size_2 + j] += float_temp[k*PSF_size_1*PSF_size_2 + (i*PSF_size_2 + j)];
}
}
}
__global__ void Ratio_fuzhi_2(float *ImgExp, float *ImgEst, float Tmp, int SNR, float *Ratio, int total)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < total)
{
Ratio[i] = ImgExp[i] / (ImgEst[i] + Tmp / SNR);
}
}
__global__ void Ratio_Complex_ge(float *ImgExp, float *ImgEst, float Tmp, int SNR, cufftComplex *Ratio_Complex, int total)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < total)
{
Ratio_Complex[i].x = ImgExp[i] / (ImgEst[i] + Tmp / SNR);
Ratio_Complex[i].y = 0;
}
}
__global__ void fftRatio_ge(cufftComplex *Ratio_Complex, cufftComplex *fftRatio, int PSF_size_1, int PSF_size_2, int PSF_size_3)
{
const int i = blockDim.x * blockIdx.x + threadIdx.x;
const int j = blockDim.y * blockIdx.y + threadIdx.y;
const int k = blockDim.z * blockIdx.z + threadIdx.z;
if (i < PSF_size_1 && j < PSF_size_2 && k < PSF_size_3)
{
fftRatio[k*PSF_size_1*PSF_size_2 + i * PSF_size_2 + j] = Ratio_Complex[i*PSF_size_2 + j];
}
}
__global__ void fftceshi_gpu_fuzhi(cufftComplex *PSF_1_gpu_Complex, cufftComplex *fftceshi_gpu, int total)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < total)
{
fftceshi_gpu[i] = PSF_1_gpu_Complex[i];
}
}
__global__ void ifft2_divide(cufftComplex *OTF, int total, int scale)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < total)
{
OTF[i].x = OTF[i].x / scale;
OTF[i].y = OTF[i].y / scale;
}
}
__global__ void real_multiply(float *gpuObjRecon, float *float_temp, int total)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < total)
{
gpuObjRecon[i] = gpuObjRecon[i] * float_temp[i];
}
}
__global__ void fftRatio_mul_conjOTF(cufftComplex *fftRatio, cufftComplex *OTF, int total)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < total)
{
float aaa = fftRatio[i].x*OTF[i].x + fftRatio[i].y*OTF[i].y;//Real Department Results
float bbb = -fftRatio[i].x*OTF[i].y + fftRatio[i].y*OTF[i].x;//Virtual Part Results
fftRatio[i].x = aaa;
fftRatio[i].y = bbb;
}
}
__global__ void cropReconImage_kernel(float *gpuObjRecon, float *gpuObjRecon_crop)
{
const int x = blockDim.x * blockIdx.x + threadIdx.x;//XObj
const int y = blockDim.y * blockIdx.y + threadIdx.y;//YObj
const int z = blockDim.z * blockIdx.z + threadIdx.z;//ZObj
int line_start = 156;
int line_end = 355;
int line_total = 200;
int col_start = 156;
int col_end = 355;
int col_total = 200;
int band = 50;
if (z < 50 && x < 200 && y < 200)
{
gpuObjRecon_crop[z * 200 * 200 + y * 200 + x] = gpuObjRecon[z*512*512 + (y + line_start)*255 + x + col_start];
//gpuObjRecon_crop[z*200*200 + y * 200 + x] = gpuObjRecon[z * 512 * 512 + (256 - 100 + y) * 512 + 256 - 100 + x];
}
}