Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QcmpCompressionLibrary
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
BioinformaticDataCompression
QcmpCompressionLibrary
Commits
e79d3f27
Commit
e79d3f27
authored
4 years ago
by
Vojtech Moravec
Browse files
Options
Downloads
Patches
Plain Diff
Small improvement in EntropyCalculation.
parent
675735d8
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/main/java/cz/it4i/qcmp/DataCompressor.java
+14
-11
14 additions, 11 deletions
src/main/java/cz/it4i/qcmp/DataCompressor.java
src/main/java/cz/it4i/qcmp/cli/functions/EntropyCalculation.java
+17
-9
17 additions, 9 deletions
...n/java/cz/it4i/qcmp/cli/functions/EntropyCalculation.java
with
31 additions
and
20 deletions
src/main/java/cz/it4i/qcmp/DataCompressor.java
+
14
−
11
View file @
e79d3f27
...
...
@@ -9,12 +9,9 @@ import cz.it4i.qcmp.cli.functions.EntropyCalculation;
import
cz.it4i.qcmp.compression.ImageCompressor
;
import
cz.it4i.qcmp.compression.ImageDecompressor
;
import
cz.it4i.qcmp.fileformat.FileExtensions
;
import
cz.it4i.qcmp.utilities.ColorConsole
;
import
cz.it4i.qcmp.utilities.Stopwatch
;
import
org.apache.commons.cli.*
;
import
java.io.IOException
;
import
java.util.concurrent.TimeUnit
;
public
class
DataCompressor
{
public
static
void
main
(
final
String
[]
args
)
{
...
...
@@ -55,23 +52,28 @@ public class DataCompressor {
case
Compress:
{
final
String
label
=
compressionOptionsCLIParsed
.
getQuantizationType
().
toString
()
+
" "
+
compressionOptionsCLIParsed
.
getQuantizationVector
().
toString
();
final
Stopwatch
stopwatch
=
Stopwatch
.
startNew
();
//
final Stopwatch stopwatch = Stopwatch.startNew();
final
ImageCompressor
compressor
=
new
ImageCompressor
(
compressionOptionsCLIParsed
);
if
(!
compressor
.
compress
())
{
System
.
err
.
println
(
"Errors occurred during compression."
);
}
stopwatch
.
stop
();
ColorConsole
.
printf
(
ColorConsole
.
Color
.
Green
,
label
);
ColorConsole
.
printf
(
ColorConsole
.
Color
.
Green
,
"Compression completed in %d ms."
,
stopwatch
.
getElapsedInUnit
(
TimeUnit
.
MILLISECONDS
));
//
stopwatch.stop();
//
ColorConsole.printf(ColorConsole.Color.Green, label);
//
ColorConsole.printf(ColorConsole.Color.Green,
//
"Compression completed in %d ms.",
//
stopwatch.getElapsedInUnit(TimeUnit.MILLISECONDS));
}
break
;
case
Decompress:
{
// final Stopwatch stopwatch = Stopwatch.startNew();
final
ImageDecompressor
decompressor
=
new
ImageDecompressor
(
compressionOptionsCLIParsed
);
if
(!
decompressor
.
decompressToFile
())
{
System
.
err
.
println
(
"Errors occurred during decompression."
);
}
// stopwatch.stop();
// ColorConsole.printf(ColorConsole.Color.Green,
// "Decompression completed in %d ms.",
// stopwatch.getElapsedInUnit(TimeUnit.MILLISECONDS));
}
break
;
...
...
@@ -90,8 +92,9 @@ public class DataCompressor {
// NOTE(Moravec): Custom function class here |
// V
//CustomFunctionBase customFunction = new MeasurePlaneErrorFunction(parsedCliOptions);
final
CustomFunctionBase
customFunction
=
new
EntropyCalculation
(
compressionOptionsCLIParsed
);
if
(!
customFunction
.
run
())
{
// final CustomFunctionBase customFunction = new EntropyCalculation(compressionOptionsCLIParsed);
final
CustomFunctionBase
cf
=
new
EntropyCalculation
(
compressionOptionsCLIParsed
);
if
(!
cf
.
run
())
{
System
.
err
.
println
(
"Errors occurred during custom function."
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/cz/it4i/qcmp/cli/functions/EntropyCalculation.java
+
17
−
9
View file @
e79d3f27
...
...
@@ -6,7 +6,9 @@ import cz.it4i.qcmp.io.loader.IPlaneLoader;
import
cz.it4i.qcmp.io.loader.PlaneLoaderFactory
;
import
cz.it4i.qcmp.utilities.Utils
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStreamWriter
;
public
class
EntropyCalculation
extends
CustomFunctionBase
{
/**
...
...
@@ -20,6 +22,7 @@ public class EntropyCalculation extends CustomFunctionBase {
@Override
public
boolean
run
()
{
System
.
out
.
println
(
"Running EntropyCalculation for "
+
options
.
getInputDataInfo
().
getCacheFileName
());
final
IPlaneLoader
loader
;
try
{
loader
=
PlaneLoaderFactory
.
getPlaneLoaderForInputFile
(
options
.
getInputDataInfo
());
...
...
@@ -28,19 +31,24 @@ public class EntropyCalculation extends CustomFunctionBase {
return
false
;
}
for
(
int
planeIndex
=
0
;
planeIndex
<
options
.
getInputDataInfo
().
getDimensions
().
getZ
();
planeIndex
++)
{
final
int
[]
planeData
;
try
{
planeData
=
loader
.
loadPlaneData
(
planeIndex
);
}
catch
(
final
IOException
e
)
{
System
.
err
.
printf
(
"Failed to load plane %d data. %s"
,
planeIndex
,
e
.
getMessage
());
return
false
;
try
(
final
FileOutputStream
fos
=
new
FileOutputStream
(
options
.
getOutputFilePath
(),
false
);
final
OutputStreamWriter
reportWriter
=
new
OutputStreamWriter
(
fos
))
{
reportWriter
.
write
(
"Plane;Entropy\n"
);
for
(
int
planeIndex
=
0
;
planeIndex
<
options
.
getInputDataInfo
().
getDimensions
().
getZ
();
planeIndex
++)
{
final
int
[]
planeData
=
loader
.
loadPlaneData
(
planeIndex
);
final
double
planeEntropy
=
Utils
.
calculateEntropy
(
planeData
);
reportWriter
.
write
(
String
.
format
(
"%d;%.4f\n"
,
planeIndex
,
planeEntropy
));
}
final
double
planeEntropy
=
Utils
.
calculateEntropy
(
planeData
);
System
.
out
.
printf
(
"P: %d\tE: %.4f\n"
,
planeIndex
,
planeEntropy
);
}
catch
(
final
IOException
e
)
{
e
.
printStackTrace
();
return
false
;
}
return
true
;
}
}
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