Skip to content
Snippets Groups Projects
Commit e4c54711 authored by Mark Winter's avatar Mark Winter
Browse files

Removed superfluous min/max functions

parent e33cffbc
No related branches found
No related tags found
No related merge requests found
......@@ -120,7 +120,6 @@ copy $(OutDir)CudaMex.dll "$(ProjectDir)Mex.mexw64"</Command>
<ClCompile Include="Mex\MexMaxFilter.cpp" />
<ClCompile Include="Mex\MexMeanFilter.cpp" />
<ClCompile Include="Mex\MexMinFilter.cpp" />
<ClCompile Include="Mex\MexMinMax.cpp" />
<ClCompile Include="Mex\MexMultiplySum.cpp" />
<ClCompile Include="Mex\MexOpener.cpp" />
<ClCompile Include="Mex\MexStdFilter.cpp" />
......
......@@ -104,9 +104,6 @@
<ClCompile Include="Mex\MexSum.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Mex\MexMinMax.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Mex\MexVarFilter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
......
......@@ -36,7 +36,6 @@
<ClCompile Include="Python\PyWrapMeanFilter.cpp" />
<ClCompile Include="Python\PyWrapMedianFilter.cpp" />
<ClCompile Include="Python\PyWrapMinFilter.cpp" />
<ClCompile Include="Python\PyWrapMinMax.cpp" />
<ClCompile Include="Python\PyWrapMultiplySum.cpp" />
<ClCompile Include="Python\PyWrapOpener.cpp" />
<ClCompile Include="Python\PyWrapStdFilter.cpp" />
......
......@@ -63,9 +63,6 @@
<ClCompile Include="Python\PyWrapMinFilter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Python\PyWrapMinMax.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Python\PyWrapOpener.cpp">
<Filter>Source Files</Filter>
</ClCompile>
......
#include "MexCommand.h"
#include "../Cuda/Vec.h"
#include "../Cuda/CWrappers.h"
#include "../Cuda/ImageDimensions.cuh"
#include "../Cuda/ImageContainer.h"
#include "MexKernel.h"
void MexMinMax::execute(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) const
{
int device = -1;
if (!mxIsEmpty(prhs[1]))
device = mat_to_c((int)mxGetScalar(prhs[1]));
ImageDimensions imageDims;
double minOut = 0.0;
double maxOut = 0.0;
if (mxIsLogical(prhs[0]))
{
bool* imageInPtr;
Script::setupImagePointers(prhs[0], &imageInPtr, imageDims);
ImageContainer<bool> imageIn(imageInPtr, imageDims);
bool lclMin = 0;
bool lclMax = 0;
minMax(imageIn, lclMin, lclMax, device);
minOut = double(lclMin);
maxOut = double(lclMax);
}
else if (mxIsUint8(prhs[0]))
{
unsigned char* imageInPtr;
Script::setupImagePointers(prhs[0], &imageInPtr, imageDims);
ImageContainer<unsigned char> imageIn(imageInPtr, imageDims);
unsigned char lclMin = 0;
unsigned char lclMax = 0;
minMax(imageIn, lclMin, lclMax, device);
minOut = double(lclMin);
maxOut = double(lclMax);
}
else if (mxIsUint16(prhs[0]))
{
unsigned short* imageInPtr;
Script::setupImagePointers(prhs[0], &imageInPtr, imageDims);
ImageContainer<unsigned short> imageIn(imageInPtr, imageDims);
unsigned short lclMin = 0;
unsigned short lclMax = 0;
minMax(imageIn, lclMin, lclMax, device);
minOut = double(lclMin);
maxOut = double(lclMax);
}
else if (mxIsInt16(prhs[0]))
{
short* imageInPtr;
Script::setupImagePointers(prhs[0], &imageInPtr, imageDims);
ImageContainer<short> imageIn(imageInPtr, imageDims);
short lclMin = 0;
short lclMax = 0;
minMax(imageIn, lclMin, lclMax, device);
minOut = double(lclMin);
maxOut = double(lclMax);
}
else if (mxIsUint32(prhs[0]))
{
unsigned int* imageInPtr;
Script::setupImagePointers(prhs[0], &imageInPtr, imageDims);
ImageContainer<unsigned int> imageIn(imageInPtr, imageDims);
unsigned int lclMin = 0;
unsigned int lclMax = 0;
minMax(imageIn, lclMin, lclMax, device);
minOut = double(lclMin);
maxOut = double(lclMax);
}
else if (mxIsInt32(prhs[0]))
{
int* imageInPtr;
Script::setupImagePointers(prhs[0], &imageInPtr, imageDims);
ImageContainer<int> imageIn(imageInPtr, imageDims);
int lclMin = 0;
int lclMax = 0;
minMax(imageIn, lclMin, lclMax, device);
minOut = double(lclMin);
maxOut = double(lclMax);
}
else if (mxIsSingle(prhs[0]))
{
float* imageInPtr;
Script::setupImagePointers(prhs[0], &imageInPtr, imageDims);
ImageContainer<float> imageIn(imageInPtr, imageDims);
float lclMin = 0;
float lclMax = 0;
minMax(imageIn, lclMin, lclMax, device);
minOut = double(lclMin);
maxOut = double(lclMax);
}
else if (mxIsDouble(prhs[0]))
{
double* imageInPtr;
Script::setupImagePointers(prhs[0], &imageInPtr, imageDims);
ImageContainer<double> imageIn(imageInPtr, imageDims);
double lclMin = 0;
double lclMax = 0;
minMax(imageIn, lclMin, lclMax, device);
minOut = double(lclMin);
maxOut = double(lclMax);
}
else
{
mexErrMsgTxt("Image type not supported!");
}
plhs[0] = mxCreateDoubleScalar(minOut);
if (nlhs>1)
plhs[1] = mxCreateDoubleScalar(maxOut);
}
std::string MexMinMax::check(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) const
{
if (nrhs != 2)
return "Incorrect number of inputs!";
if (nlhs < 1)
return "Requires one output!";
if (nlhs > 2)
return "Only returns two values!";
std::size_t imgNumDims = mxGetNumberOfDimensions(prhs[0]);
if (imgNumDims > 5)
return "Image can have a maximum of five dimensions!";
return "";
}
void MexMinMax::usage(std::vector<std::string>& outArgs, std::vector<std::string>& inArgs) const
{
inArgs.push_back("arrayIn");
inArgs.push_back("[device]");
outArgs.push_back("minOut");
outArgs.push_back("maxOut");
}
void MexMinMax::help(std::vector<std::string>& helpLines) const
{
helpLines.push_back("This returns the global min and max values.");
helpLines.push_back("\timageIn = This is a one to five dimensional array. The first three dimensions are treated as spatial.");
helpLines.push_back("\t\tThe spatial dimensions will have the kernel applied. The last two dimensions will determine");
helpLines.push_back("\t\thow to stride or jump to the next spatial block.");
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("\tminOut = This is the minimum value found in the input.");
helpLines.push_back("\tmaxOut = This is the maximum value found in the input.");
}
#include "PyWrapCommand.h"
#include "../Cuda/Vec.h"
#include "../Cuda/CWrappers.h"
#include "../Cuda/ImageDimensions.cuh"
#include "../Cuda/ImageContainer.h"
#include "PyKernel.h"
// TODO: This is a superfluous function!!!!
const char PyWrapMinMax::docString[] = "minOut,maxOut = HIP.MinMax(imageIn,[device])\n\n"\
"This returns the global min and max values.\n"\
"\timageIn = This is a one to five dimensional array. The first three dimensions are treated as spatial.\n"\
"\t\tThe spatial dimensions will have the kernel applied. The last two dimensions will determine\n"\
"\t\thow to stride or jump to the next spatial block.\n"\
"\n"\
"\tdevice (optional) = Use this if you have multiple devices and want to select one explicitly.\n"\
"\t\tSetting this to [] allows the algorithm to either pick the best device and/or will try to split\n"\
"\t\tthe data across multiple devices.\n"\
"\n"\
"\tminOut = This is the minimum value found in the input.\n"\
"\tmaxOut = This is the maximum value found in the input.\n";
PyObject* PyWrapMinMax::execute(PyObject* self, PyObject* args)
{
PyObject* imIn;
int device = -1;
if ( !PyArg_ParseTuple(args, "O!|i", &PyArray_Type, &imIn, &device) )
return nullptr;
if ( imIn == nullptr ) return nullptr;
PyArrayObject* imContig = (PyArrayObject*)PyArray_FROM_OTF(imIn, NPY_NOTYPE, NPY_ARRAY_IN_ARRAY);
ImageDimensions imageDims;
PyObject* outMinMax = PyTuple_New(2);
if ( PyArray_TYPE(imContig) == NPY_BOOL )
{
bool* imageInPtr;
bool minVal, maxVal;
Script::setupImagePointers(imContig, &imageInPtr, imageDims);
ImageContainer<bool> imageIn(imageInPtr, imageDims);
minMax(imageIn, minVal, maxVal, device);
PyTuple_SetItem(outMinMax, 0, PyBool_FromLong(minVal));
PyTuple_SetItem(outMinMax, 1, PyBool_FromLong(maxVal));
}
else if ( PyArray_TYPE(imContig) == NPY_UINT8 )
{
unsigned char* imageInPtr;
unsigned char minVal, maxVal;
Script::setupImagePointers(imContig, &imageInPtr, imageDims);
ImageContainer<unsigned char> imageIn(imageInPtr, imageDims);
minMax(imageIn, minVal, maxVal, device);
PyTuple_SetItem(outMinMax, 0, PyLong_FromLong(minVal));
PyTuple_SetItem(outMinMax, 1, PyLong_FromLong(maxVal));
}
else if ( PyArray_TYPE(imContig) == NPY_UINT16 )
{
unsigned short* imageInPtr;
unsigned short minVal, maxVal;
Script::setupImagePointers(imContig, &imageInPtr, imageDims);
ImageContainer<unsigned short> imageIn(imageInPtr, imageDims);
minMax(imageIn, minVal, maxVal, device);
PyTuple_SetItem(outMinMax, 0, PyLong_FromLong(minVal));
PyTuple_SetItem(outMinMax, 1, PyLong_FromLong(maxVal));
}
else if ( PyArray_TYPE(imContig) == NPY_INT16 )
{
short* imageInPtr, minVal, maxVal;
Script::setupImagePointers(imContig, &imageInPtr, imageDims);
ImageContainer<short> imageIn(imageInPtr, imageDims);
minMax(imageIn, minVal, maxVal, device);
PyTuple_SetItem(outMinMax, 0, PyLong_FromLong(minVal));
PyTuple_SetItem(outMinMax, 1, PyLong_FromLong(maxVal));
}
else if ( PyArray_TYPE(imContig) == NPY_UINT32 )
{
unsigned int* imageInPtr;
unsigned int minVal, maxVal;
Script::setupImagePointers(imContig, &imageInPtr, imageDims);
ImageContainer<unsigned int> imageIn(imageInPtr, imageDims);
minMax(imageIn, minVal, maxVal, device);
PyTuple_SetItem(outMinMax, 0, PyLong_FromLong(minVal));
PyTuple_SetItem(outMinMax, 1, PyLong_FromLong(maxVal));
}
else if ( PyArray_TYPE(imContig) == NPY_INT32 )
{
int* imageInPtr;
int minVal, maxVal;
Script::setupImagePointers(imContig, &imageInPtr, imageDims);
ImageContainer<int> imageIn(imageInPtr, imageDims);
minMax(imageIn, minVal, maxVal, device);
PyTuple_SetItem(outMinMax, 0, PyLong_FromLong(minVal));
PyTuple_SetItem(outMinMax, 1, PyLong_FromLong(maxVal));
}
else if ( PyArray_TYPE(imContig) == NPY_FLOAT )
{
float* imageInPtr;
float minVal, maxVal;
Script::setupImagePointers(imContig, &imageInPtr, imageDims);
ImageContainer<float> imageIn(imageInPtr, imageDims);
minMax(imageIn, minVal, maxVal, device);
PyTuple_SetItem(outMinMax, 0, PyFloat_FromDouble(minVal));
PyTuple_SetItem(outMinMax, 1, PyFloat_FromDouble(maxVal));
}
else if ( PyArray_TYPE(imContig) == NPY_DOUBLE )
{
double* imageInPtr;
double minVal, maxVal;
Script::setupImagePointers(imContig, &imageInPtr, imageDims);
ImageContainer<double> imageIn(imageInPtr, imageDims);
minMax(imageIn, minVal, maxVal, device);
PyTuple_SetItem(outMinMax, 0, PyFloat_FromDouble(minVal));
PyTuple_SetItem(outMinMax, 1, PyFloat_FromDouble(maxVal));
}
else
{
PyErr_SetString(PyExc_RuntimeError, "Image type not supported.");
Py_XDECREF(imContig);
Py_XDECREF(outMinMax);
return nullptr;
}
Py_XDECREF(imContig);
return outMinMax;
}
......@@ -18,7 +18,6 @@ BEGIN_WRAP_COMMANDS
DEF_WRAP_COMMAND(MeanFilter)
DEF_WRAP_COMMAND(MedianFilter)
DEF_WRAP_COMMAND(MinFilter)
DEF_WRAP_COMMAND(MinMax)
DEF_WRAP_COMMAND(MultiplySum)
DEF_WRAP_COMMAND(Opener)
DEF_WRAP_COMMAND(StdFilter)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment