Skip to content

Commit

Permalink
Fix bug in voxel_backprojection2
Browse files Browse the repository at this point in the history
CGLS was behaving weirdly as there was a weight missing.
  • Loading branch information
AnderBiguri authored and AnderBiguri committed Feb 7, 2017
1 parent 9c8fa00 commit 3990468
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Algorithms/CGLS.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@
if ii>1 && errorL2(ii)>errorL2(ii-1)
% OUT!
x=x-alpha*p;

if verbose
disp(['CGLS stoped in iteration N', num2str(ii),' due to divergence.'])
end
return;
end
% If step is adecuatem, then continue withg CGLS
Expand Down
2 changes: 1 addition & 1 deletion Demos/d09_Algorithms04.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@


% 'alpha_red': Defines the reduction rate of the TV hyperparameter
alpha_red=0.95;
alpha_red=0.noise_projections95;

% 'Ratio': The maximum allowed image/TV update ration. If the TV
% update changes the image more than this, the parameter
Expand Down
18 changes: 14 additions & 4 deletions Source/voxel_backprojection2.cu
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ do { \
*
**/
texture<float, cudaTextureType3D , cudaReadModeElementType> tex;

__global__ void matrixConstantMultiply(const Geometry geo,float* image,float constant){
size_t idx = threadIdx.x + blockIdx.x * blockDim.x;
for(; idx<geo.nVoxelX* geo.nVoxelY *geo.nVoxelZ; idx+=gridDim.x*blockDim.x) {
image[idx]*=constant;
}

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// RB, 10/31/2016: Add constant memory arrays to store parameters for all projections to be analyzed during a single kernel call
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -259,14 +265,16 @@ __global__ void kernelPixelBackprojection(const Geometry geo, float* image,const
realD.y=-realDaux.x*sinalpha + realDaux.y*cosalpha; //sin(-x)=-sin(x) , cos(-x)=cos(x)
float L,l;
L = sqrt( (realS.x-realD.x)*(realS.x-realD.x)+ (realS.y-realD.y)*(realS.y-realD.y)+ (realD.z)*(realD.z)); // Sz=0 always.
l = sqrt( (realS.x-realvoxel.x)*(realS.x-realvoxel.x)+ (realS.y-realvoxel.y)*(realS.y-realvoxel.y)+ (realS.z-realvoxel.z)*(realS.z-realvoxel.z));
l = sqrt( (realS.x-realvoxel.x)*(realS.x-realvoxel.x)
+ (realS.y-realvoxel.y)*(realS.y-realvoxel.y)
+ (realS.z-realvoxel.z)*(realS.z-realvoxel.z));
weigth=L*L*L/(geo.DSD*l*l);

// Get Value in the computed (U,V) and multiply by the corresponding weigth.
// indAlpha is the ABSOLUTE number of projection in the projection array (NOT the current number of projection set!)
voxelColumn[colIdx]+=tex3D(tex, u +0.5 ,
v +0.5 ,
indAlpha+0.5)*weigth;
indAlpha+0.5)* weigth;
} // END iterating through column of voxels

} // END iterating through multiple projections
Expand Down Expand Up @@ -415,9 +423,11 @@ int voxel_backprojection2(float const * const projections, Geometry geo, float*
cudaMemcpyToSymbol(projParamsArray2Dev, projParamsArray2Host, sizeof(Point3D)*7*PROJ_PER_KERNEL);

kernelPixelBackprojection<<<grid,block>>>(geo,dimage,i,nalpha);

cudaCheckErrors("Kernel fail");
} // END for

matrixConstantMultiply<<<60,MAXTREADS>>>( geo,dimage,geo.dVoxelX*geo.dVoxelY*geo.dVoxelZ/(geo.dDetecU*geo.dDetecV));

//////////////////////////////////////////////////////////////////////////////////////
// END Main reconstruction loop: go through projections (rotation angles) and backproject
//////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 3990468

Please sign in to comment.