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
3c4cc139
Commit
3c4cc139
authored
8 years ago
by
Eric Wait
Browse files
Options
Downloads
Patches
Plain Diff
Resize now works for mean reductions
parent
13fc7a93
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/c/Cuda/CudaResize.cuh
+35
-31
35 additions, 31 deletions
src/c/Cuda/CudaResize.cuh
src/c/MexResize.cpp
+1
-1
1 addition, 1 deletion
src/c/MexResize.cpp
with
36 additions
and
32 deletions
src/c/Cuda/CudaResize.cuh
+
35
−
31
View file @
3c4cc139
...
@@ -33,35 +33,35 @@ __device__ double cudaGetInterpValue_device(CudaImageContainer<PixelType> imageI
...
@@ -33,35 +33,35 @@ __device__ double cudaGetInterpValue_device(CudaImageContainer<PixelType> imageI
Vec
<
size_t
>
minPos
(
0
,
0
,
0
);
Vec
<
size_t
>
minPos
(
0
,
0
,
0
);
Vec
<
size_t
>
curPos
=
Vec
<
size_t
>
(
i
,
j
,
k
);
Vec
<
size_t
>
curPos
=
Vec
<
size_t
>
(
i
,
j
,
k
);
if
(
curPos
>
minPos
&&
curPos
<
imageIn
.
getDims
())
if
(
curPos
>
=
minPos
&&
curPos
<
imageIn
.
getDims
())
val
+=
(
1
-
alpha
)
*
(
1
-
beta
)
*
(
1
-
gamma
)
*
imageIn
[
curPos
];
val
+=
(
1
-
alpha
)
*
(
1
-
beta
)
*
(
1
-
gamma
)
*
imageIn
[
curPos
];
curPos
=
Vec
<
size_t
>
(
i
+
1
,
j
,
k
);
curPos
=
Vec
<
size_t
>
(
i
+
1
,
j
,
k
);
if
(
curPos
>
minPos
&&
curPos
<
imageIn
.
getDims
())
if
(
curPos
>
=
minPos
&&
curPos
<
imageIn
.
getDims
())
val
+=
alpha
*
(
1
-
beta
)
*
(
1
-
gamma
)
*
imageIn
[
curPos
];
val
+=
alpha
*
(
1
-
beta
)
*
(
1
-
gamma
)
*
imageIn
[
curPos
];
curPos
=
Vec
<
size_t
>
(
i
,
j
+
1
,
k
);
curPos
=
Vec
<
size_t
>
(
i
,
j
+
1
,
k
);
if
(
curPos
>
minPos
&&
curPos
<
imageIn
.
getDims
())
if
(
curPos
>
=
minPos
&&
curPos
<
imageIn
.
getDims
())
val
+=
(
1
-
alpha
)
*
beta
*
(
1
-
gamma
)
*
imageIn
[
curPos
];
val
+=
(
1
-
alpha
)
*
beta
*
(
1
-
gamma
)
*
imageIn
[
curPos
];
curPos
=
Vec
<
size_t
>
(
i
+
1
,
j
+
1
,
k
);
curPos
=
Vec
<
size_t
>
(
i
+
1
,
j
+
1
,
k
);
if
(
curPos
>
minPos
&&
curPos
<
imageIn
.
getDims
())
if
(
curPos
>
=
minPos
&&
curPos
<
imageIn
.
getDims
())
val
+=
alpha
*
beta
*
(
1
-
gamma
)
*
imageIn
[
curPos
];
val
+=
alpha
*
beta
*
(
1
-
gamma
)
*
imageIn
[
curPos
];
curPos
=
Vec
<
size_t
>
(
i
,
j
,
k
+
1
);
curPos
=
Vec
<
size_t
>
(
i
,
j
,
k
+
1
);
if
(
curPos
>
minPos
&&
curPos
<
imageIn
.
getDims
())
if
(
curPos
>
=
minPos
&&
curPos
<
imageIn
.
getDims
())
val
+=
(
1
-
alpha
)
*
(
1
-
beta
)
*
gamma
*
imageIn
[
curPos
];
val
+=
(
1
-
alpha
)
*
(
1
-
beta
)
*
gamma
*
imageIn
[
curPos
];
curPos
=
Vec
<
size_t
>
(
i
+
1
,
j
,
k
+
1
);
curPos
=
Vec
<
size_t
>
(
i
+
1
,
j
,
k
+
1
);
if
(
curPos
>
minPos
&&
curPos
<
imageIn
.
getDims
())
if
(
curPos
>
=
minPos
&&
curPos
<
imageIn
.
getDims
())
val
+=
alpha
*
(
1
-
beta
)
*
gamma
*
imageIn
[
curPos
];
val
+=
alpha
*
(
1
-
beta
)
*
gamma
*
imageIn
[
curPos
];
curPos
=
Vec
<
size_t
>
(
i
,
j
+
1
,
k
+
1
);
curPos
=
Vec
<
size_t
>
(
i
,
j
+
1
,
k
+
1
);
if
(
curPos
>
minPos
&&
curPos
<
imageIn
.
getDims
())
if
(
curPos
>
=
minPos
&&
curPos
<
imageIn
.
getDims
())
val
+=
(
1
-
alpha
)
*
beta
*
gamma
*
imageIn
[
curPos
];
val
+=
(
1
-
alpha
)
*
beta
*
gamma
*
imageIn
[
curPos
];
curPos
=
Vec
<
size_t
>
(
i
+
1
,
j
+
1
,
k
+
1
);
curPos
=
Vec
<
size_t
>
(
i
+
1
,
j
+
1
,
k
+
1
);
if
(
curPos
>
minPos
&&
curPos
<
imageIn
.
getDims
())
if
(
curPos
>
=
minPos
&&
curPos
<
imageIn
.
getDims
())
val
+=
alpha
*
beta
*
gamma
*
imageIn
[
curPos
];
val
+=
alpha
*
beta
*
gamma
*
imageIn
[
curPos
];
return
val
;
return
val
;
...
@@ -82,12 +82,12 @@ __global__ void cudaMeanResize(CudaImageContainer<PixelType> imageIn, CudaImageC
...
@@ -82,12 +82,12 @@ __global__ void cudaMeanResize(CudaImageContainer<PixelType> imageIn, CudaImageC
{
{
double
val
=
0
;
double
val
=
0
;
double
kernelFactor
=
0
;
double
kernelFactor
=
0
;
Vec
<
float
>
inputCenter
=
Vec
<
float
>
(
coordinateOut
)
*
resizeFactors
;
Vec
<
float
>
inputCenter
=
Vec
<
float
>
(
coordinateOut
+
0.5
)
/
resizeFactors
;
Vec
<
float
>
kernelCenter
=
kernelDims
/
2.0
f
;
Vec
<
float
>
kernelCenter
=
Vec
<
float
>
(
kernelDims
-
1
)
/
2.0
f
;
Vec
<
int
>
kernelStart
(
0
,
0
,
0
);
Vec
<
int
>
kernelStart
(
0
,
0
,
0
);
Vec
<
int
>
kernelEnd
(
0
,
0
,
0
);
Vec
<
int
>
kernelEnd
(
0
,
0
,
0
);
Vec
<
float
>
neighborhoodStart
=
inputCenter
-
kernelCenter
;
Vec
<
float
>
neighborhoodStart
=
inputCenter
-
Vec
<
float
>
(
kernelDims
)
/
2.0
f
;
// if the input start position is negative, we need to start further in on the kernel
// if the input start position is negative, we need to start further in on the kernel
kernelStart
.
x
=
(
neighborhoodStart
.
x
>=
0.0
f
)
?
(
0
)
:
(
ceil
(
-
neighborhoodStart
.
x
));
kernelStart
.
x
=
(
neighborhoodStart
.
x
>=
0.0
f
)
?
(
0
)
:
(
ceil
(
-
neighborhoodStart
.
x
));
kernelStart
.
y
=
(
neighborhoodStart
.
y
>=
0.0
f
)
?
(
0
)
:
(
ceil
(
-
neighborhoodStart
.
y
));
kernelStart
.
y
=
(
neighborhoodStart
.
y
>=
0.0
f
)
?
(
0
)
:
(
ceil
(
-
neighborhoodStart
.
y
));
...
@@ -95,26 +95,26 @@ __global__ void cudaMeanResize(CudaImageContainer<PixelType> imageIn, CudaImageC
...
@@ -95,26 +95,26 @@ __global__ void cudaMeanResize(CudaImageContainer<PixelType> imageIn, CudaImageC
neighborhoodStart
=
Vec
<
float
>::
max
(
Vec
<
float
>
(
0.0
f
,
0.0
f
,
0.0
f
),
neighborhoodStart
);
neighborhoodStart
=
Vec
<
float
>::
max
(
Vec
<
float
>
(
0.0
f
,
0.0
f
,
0.0
f
),
neighborhoodStart
);
// This is the last place to visit in the input (inclusive)
// This is the last place to visit in the input (inclusive)
Vec
<
float
>
neighborhoodEnd
=
inputCenter
+
kernelCenter
-
1
;
Vec
<
float
>
neighborhoodEnd
=
inputCenter
+
(
Vec
<
float
>
(
kernelDims
)
/
2.0
f
)
;
// if the input end position is outside the image, we need to end earlier in on the kernel
// if the input end position is outside the image, we need to end earlier in on the kernel
kernelEnd
.
x
=
(
neighborhoodEnd
.
x
<
image
Out
.
getDims
().
x
)
?
(
kernelDims
.
x
)
:
kernelEnd
.
x
=
(
neighborhoodEnd
.
x
<
=
image
In
.
getDims
().
x
)
?
(
kernelDims
.
x
)
:
(
kernelDims
.
x
-
(
neighborhoodEnd
.
x
-
image
Out
.
getDims
().
x
));
// will floor to int value
(
kernelDims
.
x
-
(
neighborhoodEnd
.
x
-
image
In
.
getDims
().
x
));
// will floor to int value
kernelEnd
.
y
=
(
neighborhoodEnd
.
y
<
image
Out
.
getDims
().
y
)
?
(
kernelDims
.
y
)
:
kernelEnd
.
y
=
(
neighborhoodEnd
.
y
<
=
image
In
.
getDims
().
y
)
?
(
kernelDims
.
y
)
:
(
kernelDims
.
y
-
(
neighborhoodEnd
.
y
-
image
Out
.
getDims
().
y
));
// will floor to int value
(
kernelDims
.
y
-
(
neighborhoodEnd
.
y
-
image
In
.
getDims
().
y
));
// will floor to int value
kernelEnd
.
z
=
(
neighborhoodEnd
.
z
<
image
Out
.
getDims
().
z
)
?
(
kernelDims
.
z
)
:
kernelEnd
.
z
=
(
neighborhoodEnd
.
z
<
=
image
In
.
getDims
().
z
)
?
(
kernelDims
.
z
)
:
(
kernelDims
.
z
-
(
neighborhoodEnd
.
z
-
image
Out
.
getDims
().
z
));
// will floor to int value
(
kernelDims
.
z
-
(
neighborhoodEnd
.
z
-
image
In
.
getDims
().
z
));
// will floor to int value
neighborhoodEnd
=
Vec
<
float
>::
min
(
image
Out
.
getDims
(),
neighborhoodEnd
);
neighborhoodEnd
=
Vec
<
float
>::
min
(
image
In
.
getDims
(),
neighborhoodEnd
);
Vec
<
int
>
curKernelPos
(
0
,
0
,
0
);
Vec
<
int
>
curKernelPos
(
0
,
0
,
0
);
Vec
<
int
>
curInPos
=
neighborhoodStart
;
Vec
<
int
>
curInPos
=
neighborhoodStart
;
for
(
curKernelPos
.
z
=
kernelStart
.
z
;
curKernelPos
.
z
<
=
kernelEnd
.
z
;
++
curKernelPos
.
z
)
for
(
curKernelPos
.
z
=
kernelStart
.
z
;
curKernelPos
.
z
<
kernelEnd
.
z
;
++
curKernelPos
.
z
)
{
{
curInPos
.
z
=
neighborhoodStart
.
z
+
curKernelPos
.
z
;
curInPos
.
z
=
neighborhoodStart
.
z
+
curKernelPos
.
z
;
for
(
curKernelPos
.
y
=
kernelStart
.
y
;
curKernelPos
.
y
<
=
kernelEnd
.
y
;
++
curKernelPos
.
y
)
for
(
curKernelPos
.
y
=
kernelStart
.
y
;
curKernelPos
.
y
<
kernelEnd
.
y
;
++
curKernelPos
.
y
)
{
{
curInPos
.
y
=
neighborhoodStart
.
y
+
curKernelPos
.
y
;
curInPos
.
y
=
neighborhoodStart
.
y
+
curKernelPos
.
y
;
for
(
curKernelPos
.
x
=
kernelStart
.
x
;
curKernelPos
.
x
<
=
kernelEnd
.
x
;
++
curKernelPos
.
x
)
for
(
curKernelPos
.
x
=
kernelStart
.
x
;
curKernelPos
.
x
<
kernelEnd
.
x
;
++
curKernelPos
.
x
)
{
{
curInPos
.
x
=
neighborhoodStart
.
x
+
curKernelPos
.
x
;
curInPos
.
x
=
neighborhoodStart
.
x
+
curKernelPos
.
x
;
double
imVal
=
cudaGetInterpValue_device
(
imageIn
,
curInPos
);
double
imVal
=
cudaGetInterpValue_device
(
imageIn
,
curInPos
);
...
@@ -124,9 +124,13 @@ __global__ void cudaMeanResize(CudaImageContainer<PixelType> imageIn, CudaImageC
...
@@ -124,9 +124,13 @@ __global__ void cudaMeanResize(CudaImageContainer<PixelType> imageIn, CudaImageC
}
}
}
}
double
meanVal
=
val
/
kernelFactor
;
double
meanVal
=
0
;
meanVal
=
(
meanVal
>
minVal
)
?
(
meanVal
)
:
((
double
)
minVal
);
if
(
kernelFactor
>
0
)
meanVal
=
(
meanVal
<
maxVal
)
?
(
meanVal
)
:
((
double
)
maxVal
);
{
meanVal
=
val
/
kernelFactor
;
meanVal
=
(
meanVal
>
minVal
)
?
(
meanVal
)
:
((
double
)
minVal
);
meanVal
=
(
meanVal
<
maxVal
)
?
(
meanVal
)
:
((
double
)
maxVal
);
}
imageOut
[
coordinateOut
]
=
(
PixelType
)
meanVal
;
imageOut
[
coordinateOut
]
=
(
PixelType
)
meanVal
;
}
}
...
@@ -142,6 +146,12 @@ PixelType* cResize(const PixelType* imageIn, Vec<size_t> dimsIn, Vec<double> res
...
@@ -142,6 +146,12 @@ PixelType* cResize(const PixelType* imageIn, Vec<size_t> dimsIn, Vec<double> res
dimsOut
=
Vec
<
size_t
>
(
Vec
<
double
>
(
dimsIn
)
*
resizeFactors
);
dimsOut
=
Vec
<
size_t
>
(
Vec
<
double
>
(
dimsIn
)
*
resizeFactors
);
double
memSizeRatio
=
(
double
)
dimsOut
.
product
()
/
(
double
)
dimsIn
.
product
();
bool
reduce
=
memSizeRatio
<
1
;
if
(
!
reduce
)
std
::
runtime_error
(
"Enlarging is currently not implemented."
);
PixelType
*
resizedImage
=
NULL
;
PixelType
*
resizedImage
=
NULL
;
if
(
imageOut
==
NULL
)
if
(
imageOut
==
NULL
)
resizedImage
=
new
PixelType
[
dimsOut
.
product
()];
resizedImage
=
new
PixelType
[
dimsOut
.
product
()];
...
@@ -180,12 +190,6 @@ PixelType* cResize(const PixelType* imageIn, Vec<size_t> dimsIn, Vec<double> res
...
@@ -180,12 +190,6 @@ PixelType* cResize(const PixelType* imageIn, Vec<size_t> dimsIn, Vec<double> res
HANDLE_ERROR
(
cudaMemcpyToSymbol
(
cudaConstKernel
,
hostKernel
,
sizeof
(
float
)
*
neighborhood
.
product
()));
HANDLE_ERROR
(
cudaMemcpyToSymbol
(
cudaConstKernel
,
hostKernel
,
sizeof
(
float
)
*
neighborhood
.
product
()));
}
}
double
memSizeRatio
=
(
double
)
dimsOut
.
product
()
/
(
double
)
dimsIn
.
product
();
bool
reduce
=
memSizeRatio
<
1
;
if
(
!
reduce
)
std
::
runtime_error
(
"Enlarging is currently not implemented."
);
Vec
<
size_t
>
bigDims
=
(
reduce
)
?
(
dimsIn
)
:
(
dimsOut
);
Vec
<
size_t
>
bigDims
=
(
reduce
)
?
(
dimsIn
)
:
(
dimsOut
);
Vec
<
size_t
>
smallDims
=
(
reduce
)
?
(
dimsOut
)
:
(
dimsIn
);
Vec
<
size_t
>
smallDims
=
(
reduce
)
?
(
dimsOut
)
:
(
dimsIn
);
memSizeRatio
=
(
reduce
)
?
(
memSizeRatio
)
:
(
1
/
memSizeRatio
);
// this will be in terms of the smaller image
memSizeRatio
=
(
reduce
)
?
(
memSizeRatio
)
:
(
1
/
memSizeRatio
);
// this will be in terms of the smaller image
...
...
This diff is collapsed.
Click to expand it.
src/c/MexResize.cpp
+
1
−
1
View file @
3c4cc139
...
@@ -55,7 +55,7 @@ void MexResize::execute(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs
...
@@ -55,7 +55,7 @@ void MexResize::execute(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs
{
{
unsigned
char
*
imageIn
,
*
imageOut
;
unsigned
char
*
imageIn
,
*
imageOut
;
setupInputPointers
(
prhs
[
0
],
&
imageInDims
,
&
imageIn
);
setupInputPointers
(
prhs
[
0
],
&
imageInDims
,
&
imageIn
);
imageOutDims
=
imageInDims
*
reductionFactors
;
imageOutDims
=
Vec
<
size_t
>
(
Vec
<
double
>
(
imageInDims
)
*
reductionFactors
)
;
setupOutputPointers
(
&
(
plhs
[
0
]),
imageOutDims
,
&
imageOut
);
setupOutputPointers
(
&
(
plhs
[
0
]),
imageOutDims
,
&
imageOut
);
resize
(
imageIn
,
imageInDims
,
reductionFactors
,
imageOutDims
,
mthd
,
&
imageOut
,
device
);
resize
(
imageIn
,
imageInDims
,
reductionFactors
,
imageOutDims
,
mthd
,
&
imageOut
,
device
);
...
...
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