-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConditionalCudaConvert.m
37 lines (34 loc) · 1.13 KB
/
ConditionalCudaConvert.m
1
2
3
4
5
6
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
% res=ConditionalCudaConvert(toConvert,useCuda, forceBin) : Checks the dataformat wether it is a
% cuda type or not and performs the appropriate converion. Can also handle
% a cell datatype by converting all of the entries.
% toConvert : Array or cell array to convert
% useCuda : 0 : convert to dipimage, 1: convert to cuda
% forceBin: 1 force result to be binary (only for conversion to dipimage)
function res=ConditionalCudaConvert(toConvert,useCuda,forceBin,minSize)
if nargin < 3
forceBin=0;
end
if nargin < 4
minSize=10;
end
res=toConvert;
if ~isempty(res) %Aurelie 03.03.2014
if isa(toConvert,'cell')
for n=1:numel(toConvert)
res{n}=ConditionalCudaConvert(res{n},useCuda,forceBin);
end
else
if isa(toConvert,'cuda') && (useCuda==0)
if isDip(toConvert)
res=dip_image_force(res);
else
res=double_force(res);
end
elseif (~isa(toConvert,'cuda')) && (useCuda==1) && (isa(res,'dip_image') || numel(res) > minSize)
res=cuda(res);
end
if forceBin
res=(res~=0);
end
end
end