Skip to content

Commit

Permalink
Remove dependency to Statistics Toolbox
Browse files Browse the repository at this point in the history
Removed the use of normrnd, poissrnd and prctile from the code for users without Statistical toolbox

Resolves: #6
  • Loading branch information
AnderBiguri authored and AnderBiguri committed Jul 15, 2016
1 parent 22446a8 commit 75c4438
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Utilities/addCTnoise.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@
Im=I0*exp(-proj);

% Photon noise + electronic noise
Im=poissrnd(Im)+normrnd(m,sigma);
if areTheseToolboxesInstalled({'MATLAB','Statistics Toolbox'})
Im=poissrnd(Im)+randn(size(Im)).*sigma + m;
else
Im=poissonrandom(Im)+randn(size(Im)).*sigma + m; % this one is slower
end
Im(Im<0)=1e-6;
proj=log(I0./Im);
end
18 changes: 18 additions & 0 deletions Utilities/areTheseToolboxesInstalled.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function tf = areTheseToolboxesInstalled(requiredToolboxes)
%ARETHESETOOLBOXESINSTALLED takes a cell array of toolbox names and checks whether they are currently installed
% SYNOPSIS tf = areTheseToolboxesInstalled(requiredToolboxes)
%
% INPUT requiredToolboxes: cell array with toolbox names to test for. Eg.
% {'MATLAB','Image Processing Toolbox'}
%
% OUTPUT tf: true or false if the required toolboxes are installed or not
%%%%%%%%%%%%%%%%%%%%%%%%%%
% http://stackoverflow.com/a/2061075/1485872

% get all installed toolbox names
v = ver;
% collect the names in a cell array
[installedToolboxes{1:length(v)}] = deal(v.Name);

% check
tf = all(ismember(requiredToolboxes,installedToolboxes));
6 changes: 5 additions & 1 deletion Utilities/plotImg.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ function plotImg(img,varargin)
% % % % % % % Limits of the colors
case 'Clims'
if default
climits=prctile(double(img(:)),[1 99]);
if any(size(img)>512) || ~areTheseToolboxesInstalled({'MATLAB','Statistics Toolbox'})
climits=[0, 0.95*max(img(:))];
else
climits=prctile(double(img(:)),[1 99]);
end
else
if min(size(val))==1 && max(size(val))==2
climits=val;
Expand Down
20 changes: 20 additions & 0 deletions Utilities/poissonrandom.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function km=poissonrandom(lambda)

% Donald Knuth's poisson random generator

% This sucks bananas because its O(lambda) and we want lambda~=10000...

km=zeros(size(lambda));
for ii=1:numel(lambda)

L=exp(-lambda(ii));
k=1;
p=1*rand;

while p>L
k=k+1;
p=p*rand;
end
km(ii)=k-1;
end
end

0 comments on commit 75c4438

Please sign in to comment.