Skip to content
Snippets Groups Projects
Commit 234a7966 authored by sundar's avatar sundar
Browse files

ReduceImage implementation : Mean, median, min and max

parent f2197d8e
No related branches found
No related tags found
No related merge requests found
function imageOut = ReduceImage(imageIn,NeighborhoodX,NeighborhoodY,NeighborhoodZ,method,device,useMatlab)
% ReductionFactorX, reductionFactorY, and reductionFactorZ is the amount of
% pixels and direction to "collapse" into one pixel. The optional parameter "method" can be "median," "mean," "min," or "max" and will take the median
% of the neighborhood respectfully.
if (~exist('device','var') || isempty(device))
device = 1;
end
if (~exist('useMatlab','var') || isempty(useMatlab))
useMatlab = false;
end
if (~useMatlab)
[numCudaDevices, memoryStats] = CudaMex('DeviceCount');
if (numCudaDevices < 1)
useMatlab = true;
elseif (device > numCudaDevices)
device = numCudaDevices;
end
% do something smart here if there is not enough memory...
end
if strcmp(method,'min')
fhandleInput = @(x)min(x);
elseif strcmp(method,'max')
fhandleInput = @(x)max(x);
elseif strcmp(method,'mean')
fhandleInput = @(x)mean(x);
elseif strcmp(method,'median')
fhandleInput = @(x)median(x);
end
sizeY = size(imageIn,1);
sizeX = size(imageIn,2);
sizeZ = size(imageIn,3);
imageOut = uint8(zeros( floor(sizeY/NeighborhoodY),...
floor(sizeX/NeighborhoodX) , floor(sizeZ/NeighborhoodZ) ));
if (useMatlab)
for indY = 1:floor(sizeY/NeighborhoodY)
for indX = 1:floor(sizeX/NeighborhoodX)
for indZ = 1:floor(sizeZ/NeighborhoodZ)
indexY = (indY-1)*NeighborhoodY+1:min(indY*NeighborhoodY+1,sizeY);
indexX = (indX-1)*NeighborhoodX+1:min(indX*NeighborhoodX+1,sizeX);
indexZ = (indZ-1)*NeighborhoodZ+1:min(indZ*NeighborhoodZ+1,sizeZ);
tmp = imageIn(indexY,indexX,indexZ);
imageOut(indY,indX,indZ) = uint8(fhandleInput(tmp(:)));
end
end
end
else
imageOut = CudaMex('ReduceImage',imageIn,[reductionFactorX,reductionFactorY,reductionFactorZ],[method],device);
end
end
\ No newline at end of file
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