Skip to content

Commit

Permalink
Fix truncation issue in downsampling calculation
Browse files Browse the repository at this point in the history
Adds toString method to directory entry
change maxResolution calculation location (it was wrongly initialised before)
  • Loading branch information
NicoKiaru committed Dec 18, 2023
1 parent ffd16f3 commit b3ebfa2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1161,8 +1161,6 @@ protected void initFile(String id) throws FormatException, IOException {

nPhases = maxValuePerDimension.containsKey("H")? maxValuePerDimension.get("H")+1:1;

maxResolution = maxValuePerDimension.containsKey(RESOLUTION_LEVEL_DIMENSION)? maxValuePerDimension.get(RESOLUTION_LEVEL_DIMENSION):0; // Used only for auto-determination of the fill color

int nChannels = maxValuePerDimension.containsKey("C")? maxValuePerDimension.get("C")+1:1;

int nSlices = maxValuePerDimension.containsKey("Z")? maxValuePerDimension.get("Z")+1:1;
Expand Down Expand Up @@ -1198,7 +1196,7 @@ protected void initFile(String id) throws FormatException, IOException {
cziPartToSegments.forEach((part, cziSegments) -> { // For each part
Arrays.asList(cziSegments.subBlockDirectory.data.entries).forEach( // and each entry
entry -> {
int downscalingFactor = entry.getDimension("X").size/entry.getDimension("X").storedSize;
int downscalingFactor = (int) Math.round((double)(entry.getDimension("X").size)/(double)(entry.getDimension("X").storedSize));
if ((downscalingFactor==1)||(allowAutostitching())) {
// Split by resolution level if flattenedResolutions is true
ModuloDimensionEntries moduloEntry = new ModuloDimensionEntries(entry,
Expand All @@ -1219,9 +1217,11 @@ protected void initFile(String id) throws FormatException, IOException {
});
});

maxResolution = maxValuePerDimension.containsKey(RESOLUTION_LEVEL_DIMENSION)? maxValuePerDimension.get(RESOLUTION_LEVEL_DIMENSION):0; // Used only for auto-determination of the fill color

// Sort them
List<CoreSignature> orderedCoreSignatureList = coreSignatureToBlocks.keySet().stream().sorted().collect(Collectors.toList());

// orderedCoreSignatureList.forEach(System.out::println);
// We now know how many core index are present in the image... except for extra images!

core = new ArrayList<>();
Expand Down Expand Up @@ -1871,7 +1871,6 @@ static class ModuloDimensionEntries {
ms0.moduloT.type = FormatTools.PHASE;
ms0.sizeT *= phases;
*/

final List<ModuloDimensionEntry> entryList = new ArrayList<>();
final int nRotations, nIlluminations, nPhases, filePart;

Expand All @@ -1883,8 +1882,9 @@ public ModuloDimensionEntries(LibCZI.SubBlockDirectorySegment.SubBlockDirectoryS
this.nPhases = nPhases;
this.pixelType = entry.getPixelType();
this.compression = entry.getCompression();
this.downSampling = entry.getDimension("X").size/entry.getDimension("X").storedSize;
this.downSampling = (int) Math.round((double)(entry.getDimension("X").size)/(double)(entry.getDimension("X").storedSize));
this.filePosition = entry.getFilePosition();
//System.out.println(entry);

int iRotation = 0;
int iIllumination = 0;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/ch/epfl/biop/formats/in/libczi/LibCZI.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,18 @@ public static class SubBlockDirectorySegmentData {
public SubBlockDirectoryEntry[] entries;

public static class SubBlockDirectoryEntry {
@Override
public String toString() {
if (entryDV!=null) {
StringBuilder sb = new StringBuilder();
sb.append("pixelType "+this.getPixelType()+" compression = "+getCompression()+"\n");
for (SubBlockSegment.SubBlockSegmentData.SubBlockDirectoryEntryDV.DimensionEntry entry: getDimensionEntries()) {
sb.append(entry+"\n");
}
return sb.toString();
} else return "entryDE not supported";
}

public SubBlockSegment.SubBlockSegmentData.SubBlockDirectoryEntryDV entryDV;
public SubBlockSegment.SubBlockSegmentData.SubBlockDirectoryEntryDE entryDE;

Expand Down

0 comments on commit b3ebfa2

Please sign in to comment.