Skip to content

Commit

Permalink
Fix bug in mintV
Browse files Browse the repository at this point in the history
Random image sizes where not accepted by min TV causing crashes

Resolves #24
  • Loading branch information
AnderBiguri authored and AnderBiguri committed Nov 1, 2016
1 parent 79dcc95 commit bcb1f64
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
16 changes: 8 additions & 8 deletions Algorithms/ASD_POCS.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@
% TV MINIMIZATION
% =========================================================================
% Call GPU to minimize TV
% f=minimizeTV(f0,dtvg,ng); % This is the MATLAB CODE, the functions are sill in the library, but CUDA is used nowadays
for ii=1:ng
% Steepest descend of TV norm
tv(ng*(iter-1)+ii)=im3Dnorm(f,'TV','forward');
df=weighted_gradientTVnorm2(f,0.002);
df=df./im3Dnorm(df,'L2');
f=f-dtvg.*df;
end
f=minimizeTV(f0,dtvg,ng); % This is the MATLAB CODE, the functions are sill in the library, but CUDA is used nowadays
% for ii=1:ng
% % Steepest descend of TV norm
% tv(ng*(iter-1)+ii)=im3Dnorm(f,'TV','forward');
% df=weighted_gradientTVnorm2(f,0.002);
% df=df./im3Dnorm(df,'L2');
% f=f-dtvg.*df;
% end

% update parameters
% ==========================================================================
Expand Down
14 changes: 7 additions & 7 deletions Source/minTV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ void mexFunction(int nlhs , mxArray *plhs[],
float * img = (float*)malloc(size_img[0] *size_img[1] *size_img[2]* sizeof(float));
// We need a float image, and, unfortunatedly, the only way of casting it is by value
// Also, MATLAB is column mayor and C is row mayor! we need to deal with that
for(int i=0;i<size_img[0];i++)
for(int j=0;j<size_img[1];j++)
for(int k=0;k<size_img[2];k++)
img[i*size_img[0]*size_img[1]+j*size_img[1]+k]=(float)imgaux[k*size_img[1]*size_img[2]+j*size_img[2]+i];



// for(int i=0;i<size_img[0];i++)
// for(int j=0;j<size_img[1];j++)
// for(int k=0;k<size_img[2];k++)
// img[i*size_img[0]*size_img[1]+j*size_img[1]+k]=(float)imgaux[k*size_img[1]*size_img[2]+j*size_img[2]+i];

// return;
for(int i=0;i<size_img[0]*size_img[1]*size_img[2];i++)
img[i]=(float)imgaux[i];


// Allocte output image
Expand Down
11 changes: 7 additions & 4 deletions Source/tvDenoise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,13 @@ void mexFunction(int nlhs , mxArray *plhs[],
float * img = (float*)malloc(size_img[0] *size_img[1] *size_img[2]* sizeof(float));
// for (int i=0;i<size_img[0] *size_img[1] *size_img[2];i++)
// img[i]=(float)imgaux[i];
for(int i=0;i<size_img[0];i++)
for(int j=0;j<size_img[1];j++)
for(int k=0;k<size_img[2];k++)
img[i*size_img[0]*size_img[1]+j*size_img[1]+k]=(float)imgaux[k*size_img[1]*size_img[2]+j*size_img[2]+i];
// for(int i=0;i<size_img[0];i++)
// for(int j=0;j<size_img[1];j++)
// for(int k=0;k<size_img[2];k++)
// img[i*size_img[0]*size_img[1]+j*size_img[1]+k]=(float)imgaux[k*size_img[1]*size_img[2]+j*size_img[2]+i];
//
for(int i=0;i<size_img[0]*size_img[1]*size_img[2];i++)
img[i]=(float)imgaux[i];
//////////////

// Allocte output image
Expand Down
2 changes: 1 addition & 1 deletion Utilities/im3DDenoise.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
immax=prctile(img(:),99);
img=img./immax;

imgO=(permute(tvDenoise(permute(img,[3 2 1]),hyper,iter),[1 2 3]));
imgO=(permute(tvDenoise(permute(img,[3 2 1]),hyper,iter),[3 2 1]));
clear img;

imgO=imgO*immax;
Expand Down
1 change: 1 addition & 0 deletions Utilities/minimizeTV.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
error('Wrogn amount of inputs');
end
end
img=(permute(img,[3 2 1]));
img=minTV(img,dtvg,ng);
img=(permute(img,[3 2 1]));
end

0 comments on commit bcb1f64

Please sign in to comment.