Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Zellige-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IdA Public
Zellige-core
Commits
19651fcd
Commit
19651fcd
authored
4 years ago
by
Céline TREBEAU
Browse files
Options
Downloads
Patches
Plain Diff
documentation
parent
df29f70a
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!10
Surface reconstruction Refactoring
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/fr/pasteur/ida/zellige/utils/LocalOtsuClassification.java
+65
-27
65 additions, 27 deletions
...fr/pasteur/ida/zellige/utils/LocalOtsuClassification.java
with
65 additions
and
27 deletions
src/main/java/fr/pasteur/ida/zellige/utils/LocalOtsu.java
→
src/main/java/fr/pasteur/ida/zellige/utils/LocalOtsu
Classification
.java
+
65
−
27
View file @
19651fcd
...
@@ -16,76 +16,114 @@ import net.imglib2.view.Views;
...
@@ -16,76 +16,114 @@ import net.imglib2.view.Views;
import
java.util.List
;
import
java.util.List
;
/**
public
class
LocalOtsu
*
*/
public
class
LocalOtsuClassification
{
{
/**
public
static
<
T
extends
RealType
<
T
>
&
NativeType
<
T
>
>
Img
<
BitType
>
find
(
final
Img
<
T
>
source
,
double
percent
)
*
* @param input the input {@link Img}
* @param percent the percentage of global otsu value
* @param <T> the type on the input
* @return a 3D binary {@link Img<BitType>}
*/
public
static
<
T
extends
RealType
<
T
>
&
NativeType
<
T
>
>
Img
<
BitType
>
find
(
final
Img
<
T
>
input
,
double
percent
)
{
{
// Prepare output.
// Prepare output.
final
ImgFactory
<
BitType
>
factory
=
Util
.
getArrayOrCellImgFactory
(
source
,
new
BitType
()
);
final
ImgFactory
<
BitType
>
factory
=
Util
.
getArrayOrCellImgFactory
(
input
,
new
BitType
()
);
Img
<
BitType
>
binary
=
factory
.
create
(
source
);
Img
<
BitType
>
binary
=
factory
.
create
(
input
);
new
OtsuThreshold
<>(
source
,
binary
,
percent
);
new
OtsuThreshold
<>(
input
,
binary
,
percent
);
return
binary
;
return
binary
;
}
}
/**
*
* @param <T>
*/
private
static
final
class
OtsuThreshold
<
T
extends
RealType
<
T
>
&
NativeType
<
T
>
>
private
static
final
class
OtsuThreshold
<
T
extends
RealType
<
T
>
&
NativeType
<
T
>
>
{
{
private
final
Img
<
T
>
source
;
private
final
Img
<
T
>
source
;
private
final
Img
<
T
>
output
;
private
final
Img
<
T
>
grid
;
private
final
Img
<
BitType
>
binary
;
private
final
Img
<
BitType
>
binary
;
private
final
double
percent
;
private
final
double
percent
;
/**
*
* @param source the input {@link Img}
* @param binary the resulting binary image as a {@link Img<BitType> }
* @param percent the percentage of global otsu value
*/
private
OtsuThreshold
(
final
Img
<
T
>
source
,
final
Img
<
BitType
>
binary
,
double
percent
)
private
OtsuThreshold
(
final
Img
<
T
>
source
,
final
Img
<
BitType
>
binary
,
double
percent
)
{
{
this
.
source
=
source
;
this
.
source
=
source
;
this
.
binary
=
binary
;
this
.
binary
=
binary
;
this
.
percent
=
percent
;
this
.
percent
=
percent
;
final
ImgFactory
<
T
>
factory
=
Util
.
getArrayOrCellImgFactory
(
source
,
Util
.
getTypeFromInterval
(
source
)
);
final
ImgFactory
<
T
>
factory
=
Util
.
getArrayOrCellImgFactory
(
source
,
Util
.
getTypeFromInterval
(
source
)
);
this
.
output
=
factory
.
create
(
source
);
this
.
grid
=
factory
.
create
(
source
);
run
();
run
();
}
}
/**
*
*/
public
void
run
()
public
void
run
()
{
{
computeLocalThreshold
(
source
,
output
);
computeLocalThreshold
(
source
,
grid
);
applyLocalThreshold
(
source
,
output
,
binary
,
percent
);
applyLocalThreshold
(
source
,
grid
,
binary
,
percent
);
}
}
public
Img
<
BitType
>
getOutput
()
/**
*
* @return the image containing the grid of local thresholds
*/
public
Img
<
BitType
>
getGrid
()
{
{
return
binary
;
return
binary
;
}
}
/**
*
* @param input the input {@link Img}
* @param grid the image containing the grid of local thresholds
* @param <T> the type on the input
*/
public
static
<
T
extends
RealType
<
T
>
&
NativeType
<
T
>
>
void
public
static
<
T
extends
RealType
<
T
>
&
NativeType
<
T
>
>
void
computeLocalThreshold
(
Img
<
T
>
source
,
Img
<
T
>
output
)
computeLocalThreshold
(
Img
<
T
>
input
,
Img
<
T
>
grid
)
{
{
long
X
=
source
.
dimension
(
0
);
long
X
=
input
.
dimension
(
0
);
long
Y
=
source
.
dimension
(
1
);
long
Y
=
input
.
dimension
(
1
);
long
Z
=
source
.
dimension
(
2
);
long
Z
=
input
.
dimension
(
2
);
List
<
Interval
>
intervals
=
Grids
.
collectAllContainedIntervals
(
new
long
[]{
X
,
Y
,
Z
},
List
<
Interval
>
intervals
=
Grids
.
collectAllContainedIntervals
(
new
long
[]{
X
,
Y
,
Z
},
new
int
[]{
50
,
50
,
3
}
);
//TODO Size of a grid cube ?
new
int
[]{
50
,
50
,
3
}
);
//TODO Size of a grid cube ?
for
(
Interval
interval
:
intervals
)
for
(
Interval
interval
:
intervals
)
{
{
IntervalView
<
T
>
viewSource
=
Views
.
offsetInterval
(
source
,
interval
);
IntervalView
<
T
>
viewSource
=
Views
.
offsetInterval
(
input
,
interval
);
IntervalView
<
T
>
view
Output
=
Views
.
offsetInterval
(
output
,
interval
);
IntervalView
<
T
>
view
Grid
=
Views
.
offsetInterval
(
grid
,
interval
);
T
threshold
=
Otsu
.
getThreshold
(
viewSource
);
T
threshold
=
Otsu
.
getThreshold
(
viewSource
);
view
Output
.
forEach
(
pixel
->
pixel
.
set
(
threshold
)
);
view
Grid
.
forEach
(
pixel
->
pixel
.
set
(
threshold
)
);
}
}
}
}
/**
*
* @param input the input {@link Img}
* @param grid the image containing the grid of local thresholds
* @param binary the resulting binary image as a {@link Img<BitType> }
* @param percent the percentage of global otsu value
* @param <T> the input type
*/
public
static
<
T
extends
RealType
<
T
>
&
NativeType
<
T
>
>
void
public
static
<
T
extends
RealType
<
T
>
&
NativeType
<
T
>
>
void
applyLocalThreshold
(
Img
<
T
>
source
,
Img
<
T
>
output
,
Img
<
BitType
>
binary
,
double
percent
)
applyLocalThreshold
(
Img
<
T
>
input
,
Img
<
T
>
grid
,
Img
<
BitType
>
binary
,
double
percent
)
{
{
double
threshold
=
Threshold
.
getThreshold
(
source
,
percent
).
getRealDouble
();
double
threshold
=
Threshold
.
getThreshold
(
input
,
percent
).
getRealDouble
();
Utils
.
gaussConvolution
(
output
.
copy
(),
output
,
new
double
[]{
5
,
5
,
1
}
);
Utils
.
gaussConvolution
(
grid
.
copy
(),
grid
,
new
double
[]{
5
,
5
,
1
}
);
ImageJFunctions
.
show
(
output
.
copy
(),
"grid"
);
ImageJFunctions
.
show
(
grid
.
copy
(),
"grid"
);
Cursor
<
T
>
sourceCursor
=
source
.
localizingCursor
();
Cursor
<
T
>
sourceCursor
=
input
.
localizingCursor
();
Cursor
<
T
>
outputCursor
=
output
.
cursor
();
Cursor
<
T
>
outputCursor
=
grid
.
cursor
();
RandomAccess
<
BitType
>
randomAccess
=
binary
.
randomAccess
();
RandomAccess
<
BitType
>
randomAccess
=
binary
.
randomAccess
();
while
(
sourceCursor
.
hasNext
())
while
(
sourceCursor
.
hasNext
())
{
{
...
...
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