Newer
Older
#include "MexCommand.h"
#include "../Cuda/Vec.h"
#include "../Cuda/CWrappers.h"
#include "../Cuda/ImageDimensions.cuh"
#include "../Cuda/ImageContainer.h"
#include "MexKernel.h"
void MexGetMinMax::execute(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) const
{
// TODO: Why is this the only device with a 0 default?
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
int device = 0;
if (!mxIsEmpty(prhs[1]))
device = mat_to_c((int)mxGetScalar(prhs[1]));
ImageDimensions imageDims;
if (mxIsLogical(prhs[0]))
{
bool* imageInPtr, minVal, maxVal;
setupImagePointers(prhs[0], &imageInPtr, imageDims);
getMinMax(imageInPtr, imageDims.getNumElements(), minVal, maxVal, device);
plhs[0] = mxCreateDoubleScalar(minVal);
plhs[1] = mxCreateDoubleScalar(maxVal);
}
else if (mxIsUint8(prhs[0]))
{
unsigned char* imageInPtr, minVal, maxVal;
setupImagePointers(prhs[0], &imageInPtr, imageDims);
getMinMax(imageInPtr, imageDims.getNumElements(), minVal, maxVal, device);
plhs[0] = mxCreateDoubleScalar(minVal);
plhs[1] = mxCreateDoubleScalar(maxVal);
}
else if (mxIsUint16(prhs[0]))
{
unsigned short* imageInPtr, minVal, maxVal;
setupImagePointers(prhs[0], &imageInPtr, imageDims);
getMinMax(imageInPtr, imageDims.getNumElements(), minVal, maxVal, device);
plhs[0] = mxCreateDoubleScalar(minVal);
plhs[1] = mxCreateDoubleScalar(maxVal);
}
else if (mxIsInt16(prhs[0]))
{
short* imageInPtr, minVal, maxVal;
setupImagePointers(prhs[0], &imageInPtr, imageDims);
getMinMax(imageInPtr, imageDims.getNumElements(), minVal, maxVal, device);
plhs[0] = mxCreateDoubleScalar(minVal);
plhs[1] = mxCreateDoubleScalar(maxVal);
}
else if (mxIsUint32(prhs[0]))
{
unsigned int* imageInPtr, minVal, maxVal;
setupImagePointers(prhs[0], &imageInPtr, imageDims);
getMinMax(imageInPtr, imageDims.getNumElements(), minVal, maxVal, device);
plhs[0] = mxCreateDoubleScalar(minVal);
plhs[1] = mxCreateDoubleScalar(maxVal);
}
else if (mxIsInt32(prhs[0]))
{
int* imageInPtr, minVal, maxVal;
setupImagePointers(prhs[0], &imageInPtr, imageDims);
getMinMax(imageInPtr, imageDims.getNumElements(), minVal, maxVal, device);
plhs[0] = mxCreateDoubleScalar(minVal);
plhs[1] = mxCreateDoubleScalar(maxVal);
}
else if (mxIsSingle(prhs[0]))
{
float* imageInPtr, minVal, maxVal;
setupImagePointers(prhs[0], &imageInPtr, imageDims);
getMinMax(imageInPtr, imageDims.getNumElements(), minVal, maxVal, device);
plhs[0] = mxCreateDoubleScalar(minVal);
plhs[1] = mxCreateDoubleScalar(maxVal);
}
else if (mxIsDouble(prhs[0]))
{
double* imageInPtr, minVal, maxVal;
setupImagePointers(prhs[0], &imageInPtr, imageDims);
getMinMax(imageInPtr, imageDims.getNumElements(), minVal, maxVal, device);
plhs[0] = mxCreateDoubleScalar(minVal);
plhs[1] = mxCreateDoubleScalar(maxVal);
}
else
{
mexErrMsgTxt("Image type not supported!");
}
}
std::string MexGetMinMax::check(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) const
{
if (nrhs < 1 || nrhs > 2)
return "Incorrect number of inputs!";
if (nlhs != 2)
return "Requires two outputs!";
size_t imgNumDims = mxGetNumberOfDimensions(prhs[0]);
if (imgNumDims > 5)
return "Image can have a maximum of five dimensions!";
return "";
}
void MexGetMinMax::usage(std::vector<std::string>& outArgs, std::vector<std::string>& inArgs) const
{
inArgs.push_back("arrayIn");
inArgs.push_back("[device]");
outArgs.push_back("minValue");
outArgs.push_back("maxValue");
}
void MexGetMinMax::help(std::vector<std::string>& helpLines) const
{
helpLines.push_back("This function finds the lowest and highest value in the array that is passed in.");
helpLines.push_back("\timageIn = This is a one to five dimensional array.");
helpLines.push_back("");
helpLines.push_back("\tdevice (optional) = Use this if you have multiple devices and want to select one explicitly.");
helpLines.push_back("\t\tSetting this to [] allows the algorithm to either pick the best device and/or will try to split");
helpLines.push_back("\t\tthe data across multiple devices.");
helpLines.push_back("");
helpLines.push_back("\tminValue = This is the lowest value found in the array.");
helpLines.push_back("\tmaxValue = This is the highest value found in the array.");
}