Newer
Older
Eric Wait
committed
% NormalizedHistogram - histogram = NormalizedHistogram(imageIn,numBins,min,max,device)
function histogram = NormalizedHistogram(imageIn,numBins,min,max)
% 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
histogram = ImProc.Cuda.NormalizedHistogram(imageIn,numBins,min,max,device);
catch errMsg
delete(mutexfile);
throw(errMsg);
end
delete(mutexfile);
else
histogram = lclNormalizedHistogram(imageIn,numBins,min,max);
Eric Wait
committed
end
end
function histogram = lclNormalizedHistogram(imageIn,numBins,min,max)
if nargin < 1 || nargin > 5
error('Incorrect number of inputs!')
end
if length(size(imageIn))>3
error('Image can have a maximum of three dimensions!')
end
if isempty(numBins) || ~exist('numBins') || numBins == 0
histogram = imhist(imageIn(imageIn > min)) ./ sum(imhist(imageIn(imageIn > min)));
else
histogram = imhist(imageIn(imageIn > min),numBins) ./ sum(imhist(imageIn(imageIn > min),numBins));
end