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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IdA Public
Zellige-core
Commits
d20015e8
Commit
d20015e8
authored
8 months ago
by
Céline TREBEAU
Browse files
Options
Downloads
Patches
Plain Diff
Feature : new class to unbinned the raw height map
parent
f262fb94
No related branches found
No related tags found
1 merge request
!41
Resolve "Consider rescaling (binning) large images"
Pipeline
#141854
passed
8 months ago
Stage: build
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/fr/pasteur/ida/zellige/steps/selection/util/Unbinning.java
+139
-0
139 additions, 0 deletions
...r/pasteur/ida/zellige/steps/selection/util/Unbinning.java
with
139 additions
and
0 deletions
src/main/java/fr/pasteur/ida/zellige/steps/selection/util/Unbinning.java
0 → 100644
+
139
−
0
View file @
d20015e8
package
fr.pasteur.ida.zellige.steps.selection.util
;
import
io.scif.img.ImgOpener
;
import
net.imagej.ImageJ
;
import
net.imglib2.RandomAccess
;
import
net.imglib2.RandomAccessibleInterval
;
import
net.imglib2.img.Img
;
import
net.imglib2.img.ImgFactory
;
import
net.imglib2.img.display.imagej.ImageJFunctions
;
import
net.imglib2.type.NativeType
;
import
net.imglib2.type.numeric.RealType
;
import
net.imglib2.type.numeric.integer.UnsignedByteType
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
static
fr
.
pasteur
.
ida
.
zellige
.
steps
.
Utils
.
setPosition
;
import
static
fr
.
pasteur
.
ida
.
zellige
.
steps
.
Utils
.
setPositionAndGet
;
/**
* Generates an unbinned image, according to the input image and bin value. Only for 2D images.
* @param <T> the image type
*/
public
class
Unbinning
<
T
extends
RealType
<
T
>
&
NativeType
<
T
>
>
{
private
final
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
Unbinning
.
class
);
private
final
Img
<
T
>
output
;
private
final
RandomAccessibleInterval
<
T
>
binned
;
private
final
int
bin
;
/**
*
* @param input a binned image
* @param factory the input image factory
* @param bin the bin size
* @return the input image unbinned
* @param <T> input and output image type
*/
public
static
<
T
extends
RealType
<
T
>
&
NativeType
<
T
>
>
Img
<
T
>
run
(
RandomAccessibleInterval
<
T
>
input
,
ImgFactory
<
T
>
factory
,
int
bin
)
{
Img
<
T
>
output
=
factory
.
create
(
input
.
dimension
(
0
)
*
bin
,
input
.
dimension
(
1
)
*
bin
);
Unbinning
<
T
>
unbinning
=
new
Unbinning
<>(
input
,
bin
,
output
);
unbinning
.
run
();
return
output
;
}
/**
* Constructor
* @param input a binned image
* @param bin the bin size
* @param output he input image unbinned
*/
public
Unbinning
(
RandomAccessibleInterval
<
T
>
input
,
int
bin
,
Img
<
T
>
output
)
{
this
.
binned
=
input
;
this
.
bin
=
bin
;
this
.
output
=
output
;
}
/**
* Parses the binned image and assign the corresponding values to the unbinned image.
*/
public
void
run
()
{
LOGGER
.
debug
(
"Starting process..."
);
double
startTime
=
System
.
currentTimeMillis
();
RandomAccess
<
T
>
binnedAccess
=
binned
.
randomAccess
();
RandomAccess
<
T
>
outputAccess
=
output
.
randomAccess
();
for
(
int
y
=
0
;
y
<
binned
.
dimension
(
1
)
;
y
++
)
{
for
(
int
x
=
0
;
x
<
binned
.
dimension
(
0
);
x
++)
{
T
value
=
setPositionAndGet
(
binnedAccess
,
x
,
y
);
applyValueToGrid
(
x
,
y
,
bin
,
outputAccess
,
value
);
}
}
double
endTime
=
System
.
currentTimeMillis
();
LOGGER
.
debug
(
"Process completed in {}s"
,
(
endTime
-
startTime
)/
1000
);
}
/**
*
* @param X the starting x value
* @param Y the starting y value
* @param bin the bin size
* @param access the unbinned image {@link RandomAccess<T>}
* @param value the pixel value to assign
*/
private
void
applyValueToGrid
(
int
X
,
int
Y
,
int
bin
,
RandomAccess
<
T
>
access
,
T
value
)
{
for
(
int
y
=
Y
*
bin
;
y
<
Y
*
bin
+
bin
;
y
++
)
{
for
(
int
x
=
X
*
bin
;
x
<
X
*
bin
+
bin
;
x
++
)
{
setPosition
(
access
,
x
,
y
);
access
.
get
().
set
(
value
);
}
}
}
public
static
void
main
(
String
[]
args
)
{
ImageJ
ij
=
new
ImageJ
();
ij
.
launch
(
args
);
final
ImgOpener
io
=
new
ImgOpener
();
@SuppressWarnings
(
"unchecked"
)
final
Img
<
UnsignedByteType
>
kernel
=
(
Img
<
UnsignedByteType
>
)
io
.
openImgs
(
"doc/Scan1_volume_crop.tif"
).
get
(
0
);
ImageJFunctions
.
show
(
kernel
,
"original"
);
double
time1
=
System
.
currentTimeMillis
();
int
bin
=
4
;
Img
<
UnsignedByteType
>
output
=
Binning
.
binning
(
kernel
,
bin
);
double
time2
=
System
.
currentTimeMillis
();
LOGGER
.
debug
(
"Multithreading time = {}s"
,
(
time2
-
time1
)
/
1000
);
assert
output
!=
null
;
ImageJFunctions
.
show
(
output
,
"output "
);
Img
<
UnsignedByteType
>
i
=
kernel
.
factory
().
create
(
output
.
dimension
(
0
),
output
.
dimension
(
1
)
);
RandomAccess
<
UnsignedByteType
>
access
=
i
.
randomAccess
();
RandomAccess
<
UnsignedByteType
>
cursor
=
output
.
randomAccess
();
for
(
int
y
=
0
;
y
<
i
.
dimension
(
1
);
y
++
)
{
for
(
int
x
=
0
;
x
<
i
.
dimension
(
0
);
x
++
)
{
setPosition
(
access
,
x
,
y
);
access
.
get
().
setReal
(
setPositionAndGet
(
cursor
,
x
,
y
).
getRealDouble
()
);
}
}
Img
<
UnsignedByteType
>
output_unbinned
=
Unbinning
.
run
(
i
,
i
.
factory
(),
bin
);
ImageJFunctions
.
show
(
output_unbinned
,
"unbinned 1"
);
}
}
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