Newer
Older
Eric Wait
committed
% OtsuThresholdValue - threshold = OtsuThresholdValue(imageIn,device)
function threshold = OtsuThresholdValue(imageIn)
% check for Cuda capable devices
Eric Wait
committed
curPath = which('ImProc.Cuda');
curPath = fileparts(curPath);
n = ImProc.Cuda.DeviceCount();
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
% if there are devices find the availble one and grab the mutex
if (n>0)
foundDevice = false;
device = -1;
while(~foundDevice)
for deviceIdx=1:n
mutexfile = fullfile(curPath,sprintf('device%02d.txt',deviceIdx));
if (~exist(mutexfile,'file'))
try
fclose(fopen(mutexfile,'wt'));
catch errMsg
continue;
end
foundDevice = true;
device = deviceIdx;
break;
end
end
if (~foundDevice)
pause(2);
end
end
try
threshold = ImProc.Cuda.OtsuThresholdValue(imageIn,device);
catch errMsg
delete(mutexfile);
throw(errMsg);
end
delete(mutexfile);
else
threshold = lclOtsuThresholdValue(imageIn);
Eric Wait
committed
end
end
function threshold = lclOtsuThresholdValue(imageIn)
if nargin ~= 1
error('Incorrect number of inputs!')
end
if length(size(imageIn)) > 3
error('Image can have a maximum of three dimensions!')
end
if ~isa(imageIn, 'double')
imageIn = im2double(imageIn);
end
threshold = graythresh(imageIn);