Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
hydra-image-processor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenSource
hydra-image-processor
Commits
234a7966
Commit
234a7966
authored
9 years ago
by
sundar
Browse files
Options
Downloads
Patches
Plain Diff
ReduceImage implementation : Mean, median, min and max
parent
f2197d8e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/MATLAB/ReduceImage.m
+57
-0
57 additions, 0 deletions
src/MATLAB/ReduceImage.m
with
57 additions
and
0 deletions
src/MATLAB/ReduceImage.m
0 → 100644
+
57
−
0
View file @
234a7966
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment