{
  "id": 679379,
  "title": "Z Compression Experiments",
  "url": "/competitions/vesuvius-challenge-surface-detection/discussion/679379",
  "author_name": "",
  "post_date": "2026-03-01T01:16:32.741644400Z",
  "votes": 2,
  "comment_count": 2,
  "views": 0,
  "content": "<h1>Reversibility of Z-axis Compression</h1>\n<h2>Background</h2>\n<p>In my <a href=\"https://www.kaggle.com/competitions/vesuvius-challenge-surface-detection/writeups/18th-median-filter-x-7-post-processing-is-very-s\" target=\"_blank\">solution</a>, I used Z compression to speed things up.\nI also ran some basic experiments to confirm that using Z compression wouldn’t cause any issues, so I’m sharing the results here.</p>\n<p>3D training with nnU-Net is extremely computationally expensive. The Host Baseline (160x160x160 patch, ResidualEncoderUNet) takes approximately 165-200 seconds per epoch, making it difficult to compete with a single RTX 5090.</p>\n<p>We considered an approach of <strong>compressing the Z-axis by 1/2 for training and inference, then restoring to the original resolution</strong>. To assess feasibility, we first quantitatively evaluated how much information is lost by compression and restoration alone (without any model), using the official metrics.</p>\n<h2>Experimental Design</h2>\n<p>We compressed and restored GT labels (3D binary masks), then compared them against the original GT. Since no model prediction is involved, the results represent the <strong>theoretical upper bound</strong> of what a compression-based approach can achieve.</p>\n<pre><code>GT (320³) ──→ Z-axis 1/2 compression (160x320x320) ──→ Restore to original size (320³) ──→ Compare with GT\n</code></pre>\n<p>We used <code>scipy.ndimage.zoom</code> for compression, progressively improving the interpolation method, label format, and post-processing.</p>\n<h3>Evaluation Metrics</h3>\n<p>We used the official metrics (Combined Score = 0.30 × TopoScore + 0.35 × SurfaceDice + 0.35 × VOI Score). Perfect reversibility would yield Combined = 1.0.</p>\n<h3>Data</h3>\n<p>We sampled 5 volumes per scroll ID from the training data (three volume sizes exist: 320³: 738 samples, 256³: 47 samples, 384³: 1 sample).</p>\n<h2>Results</h2>\n<h3>Step 1: Nearest Neighbor (Baseline)</h3>\n<p>As the simplest approach, we performed compression and restoration using Nearest Neighbor interpolation (<code>order=0</code>).</p>\n<table>\n<thead>\n<tr>\n<th>Combined</th>\n<th>SDice</th>\n<th>VOI</th>\n<th>Topo</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>0.435</td>\n<td>0.962</td>\n<td>0.265</td>\n<td>0.020</td>\n</tr>\n</tbody>\n</table>\n<p>SDice was a reasonable 0.96, but <strong>TopoScore was nearly zero at 0.02</strong>. Nearest Neighbor discards alternating slices during compression and duplicates them during restoration, significantly altering the 3D connectivity structure.</p>\n<h3>Step 2: Linear Interpolation + Soft Labels</h3>\n<p>To address the Nearest Neighbor issues, we switched to Linear interpolation (<code>order=1</code>). Here, a critical design decision arose:</p>\n<p><strong>Should we binarize after compression (Hard), or preserve probability values (Soft)?</strong></p>\n<pre><code>Hard: GT → Linear compress → Binarize at threshold 0.5 → Linear restore → Threshold 0.5\nSoft: GT → Linear compress → Keep as probabilities (0.0-1.0) → Linear restore → Threshold 0.5\n</code></pre>\n<p>The Hard approach discards information at the compression stage and degrades again through thresholding during restoration. The Soft approach preserves the intermediate representation and only binarizes at the final stage.</p>\n<table>\n<thead>\n<tr>\n<th>Method</th>\n<th>Combined</th>\n<th>SDice</th>\n<th>VOI</th>\n<th>Topo</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Nearest Neighbor</td>\n<td>0.435</td>\n<td>0.962</td>\n<td>0.265</td>\n<td>0.020</td>\n</tr>\n<tr>\n<td>Linear (Hard)</td>\n<td>0.435</td>\n<td>0.962</td>\n<td>0.265</td>\n<td>0.020</td>\n</tr>\n<tr>\n<td><strong>Linear (Soft)</strong></td>\n<td><strong>0.810</strong></td>\n<td><strong>1.000</strong></td>\n<td><strong>0.844</strong></td>\n<td><strong>0.550</strong></td>\n</tr>\n</tbody>\n</table>\n<p>Linear (Hard) produced exactly the same scores as Nearest Neighbor. In contrast, <strong>simply preserving soft labels jumped Combined from 0.44 to 0.81</strong>. SDice reached a perfect 1.000, and VOI was a strong 0.84. Soft label preservation was the single biggest breakthrough in this experiment.</p>\n<p>However, TopoScore remained at 0.55, leaving room for improvement.</p>\n<h3>Step 3: Boundary Frame Preservation</h3>\n<p><code>scipy.ndimage.zoom</code> has a known issue where boundary frames collapse (the last frame becomes 0). In our data, the first and last 3 pixels along the Z-axis are ignore regions, so we overwrote these boundary frames with the original data after compression.</p>\n<pre><code>comp[0] = orig[0]        # ignore start\ncomp[1] = orig[3]        # valid region boundary (preserve binary)\ncomp[-2] = orig[-4]      # valid region boundary (preserve binary)\ncomp[-1] = orig[-1]      # ignore end\n</code></pre>\n<p>The results in Step 2's table (Combined 0.810) already include this boundary preservation.</p>\n<h3>Step 4: Morphological Topology Repair</h3>\n<p>We investigated why TopoScore remained at 0.55 after Steps 2-3. Linear interpolation generates intermediate values (0.3-0.7), and thresholding at 0.5 creates tiny holes. In 3D, these holes form <strong>loop structures (B1 tunnels)</strong> that are invisible in 2D slices but change the 3D topology.</p>\n<p>We applied <strong>dilation followed by erosion (Closing)</strong> to repair these artifacts.</p>\n<pre><code>from scipy.ndimage import binary_dilation, binary_erosion\npred_fixed = binary_erosion(binary_dilation(pred, iterations=1), iterations=1)\n</code></pre>\n<p>The effect varied dramatically by data size.</p>\n<p><strong>Size 320 (738 samples, GT tunnel count B1=0, simple structure):</strong></p>\n<table>\n<thead>\n<tr>\n<th>Processing</th>\n<th>Combined</th>\n<th>Topo</th>\n<th>B1 Change</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Soft + Boundary</td>\n<td>0.798</td>\n<td>0.550</td>\n<td>0→3</td>\n</tr>\n<tr>\n<td>+ Closing</td>\n<td>0.798</td>\n<td>0.550</td>\n<td>0→3</td>\n</tr>\n</tbody>\n</table>\n<p>No effect on size 320. The 3 B1 tunnels introduced by compression-restoration could not be removed by closing.</p>\n<p><strong>Size 256 (47 samples, GT tunnel count B1≈40, complex branching structure):</strong></p>\n<table>\n<thead>\n<tr>\n<th>Processing</th>\n<th>Combined</th>\n<th>Topo</th>\n<th>B1 Change</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Soft + Boundary</td>\n<td>0.752</td>\n<td>0.474</td>\n<td>40→2919</td>\n</tr>\n<tr>\n<td><strong>+ Closing</strong></td>\n<td><strong>0.888</strong></td>\n<td><strong>0.899</strong></td>\n<td><strong>40→50</strong></td>\n</tr>\n</tbody>\n</table>\n<p>For size 256, B1 had exploded from 40 to 2,919, but closing suppressed it to 50, resulting in a <strong>massive TopoScore improvement from 0.47 to 0.90</strong>.</p>\n<h3>Step 5: Compression Ratio Comparison (1/2 vs 1/3)</h3>\n<p>We also tested 1/3 compression for further speedup.</p>\n<p><strong>Size 320:</strong></p>\n<table>\n<thead>\n<tr>\n<th>Ratio</th>\n<th>Compressed Z</th>\n<th>Combined</th>\n<th>VOI</th>\n<th>Topo</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>1/2</td>\n<td>160</td>\n<td>0.798</td>\n<td>0.809</td>\n<td>0.550</td>\n</tr>\n<tr>\n<td>1/3</td>\n<td>106</td>\n<td>0.685</td>\n<td>0.566</td>\n<td>0.456</td>\n</tr>\n</tbody>\n</table>\n<p><strong>Size 256 (after closing):</strong></p>\n<table>\n<thead>\n<tr>\n<th>Ratio</th>\n<th>Compressed Z</th>\n<th>Combined</th>\n<th>VOI</th>\n<th>Topo</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>1/2</td>\n<td>128</td>\n<td><strong>0.888</strong></td>\n<td>0.765</td>\n<td><strong>0.899</strong></td>\n</tr>\n<tr>\n<td>1/3</td>\n<td>85</td>\n<td>0.614</td>\n<td>0.485</td>\n<td>0.314</td>\n</tr>\n</tbody>\n</table>\n<p>1/3 compression caused significant Combined drops: -0.11 for size 320 and -0.27 for size 256. <strong>1/2 is the practical limit</strong>.</p>\n<h2>Analysis of Remaining TopoScore Degradation</h2>\n<p>We investigated the remaining TopoScore = 0.55 issue for size 320. Examining the Betti Matching breakdown:</p>\n<table>\n<thead>\n<tr>\n<th>Betti Number</th>\n<th>GT</th>\n<th>Restored</th>\n<th>Matched</th>\n<th>F1</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>B0 (connected components)</td>\n<td>17</td>\n<td>19</td>\n<td>17</td>\n<td>0.94</td>\n</tr>\n<tr>\n<td>B1 (tunnels)</td>\n<td>0</td>\n<td>3</td>\n<td>0</td>\n<td>0.14</td>\n</tr>\n</tbody>\n</table>\n<p>B0 (component count) is nearly perfectly preserved (F1=0.94). The problem lies in B1: 3 tunnels appear where there were originally 0. Since TopoScore averages the F1 of B0 and B1, the B1 F1 of 0.14 drags the overall score down to 0.55.</p>\n<p>These 3 B1 tunnels are tiny loops created by the threshold processing during compression-restoration, and could not be removed by morphological closing. However, this is an error of \"3 tunnels added to a perfectly clean GT\" --- in practice, model predictions contain far more topological errors, so this is not a concern for real-world use.</p>\n<h2>Summary</h2>\n<p>Z-axis 1/2 compression is <strong>nearly reversible</strong> when combining soft label preservation + boundary preservation + morphological closing.</p>\n<table>\n<thead>\n<tr>\n<th>Data</th>\n<th>Combined</th>\n<th>SDice</th>\n<th>VOI</th>\n<th>Topo</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Size 320 (738 samples)</td>\n<td>0.810</td>\n<td>1.000</td>\n<td>0.844</td>\n<td>0.550</td>\n</tr>\n<tr>\n<td>Size 256 (47 samples) + post-processing</td>\n<td>0.888</td>\n<td>1.000</td>\n<td>0.765</td>\n<td>0.899</td>\n</tr>\n</tbody>\n</table>\n<table>\n<thead>\n<tr>\n<th>Improvement Step</th>\n<th>Effect</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Nearest Neighbor → Linear (Soft)</td>\n<td>Combined +0.37 (largest gain)</td>\n</tr>\n<tr>\n<td>+ Boundary preservation</td>\n<td>Boundary artifact elimination</td>\n</tr>\n<tr>\n<td>+ Morphological closing</td>\n<td>Size 256 Topo +0.43</td>\n</tr>\n</tbody>\n</table>\n<p>SDice and VOI are sufficiently high, indicating minimal geometric degradation from compression. The information loss from compression-restoration is judged to be small relative to model prediction errors, confirming the feasibility of compressed training. However, since top solutions achieved their scores with full-resolution training, further validation is needed to determine whether this method can reach gold-medal territory.</p>",
  "messages": [
    {
      "id": "3415527",
      "postDate": "03/01/2026 01:16:32",
      "content": "<h1>Reversibility of Z-axis Compression</h1>\n<h2>Background</h2>\n<p>In my <a href=\"https://www.kaggle.com/competitions/vesuvius-challenge-surface-detection/writeups/18th-median-filter-x-7-post-processing-is-very-s\" target=\"_blank\">solution</a>, I used Z compression to speed things up.\nI also ran some basic experiments to confirm that using Z compression wouldn’t cause any issues, so I’m sharing the results here.</p>\n<p>3D training with nnU-Net is extremely computationally expensive. The Host Baseline (160x160x160 patch, ResidualEncoderUNet) takes approximately 165-200 seconds per epoch, making it difficult to compete with a single RTX 5090.</p>\n<p>We considered an approach of <strong>compressing the Z-axis by 1/2 for training and inference, then restoring to the original resolution</strong>. To assess feasibility, we first quantitatively evaluated how much information is lost by compression and restoration alone (without any model), using the official metrics.</p>\n<h2>Experimental Design</h2>\n<p>We compressed and restored GT labels (3D binary masks), then compared them against the original GT. Since no model prediction is involved, the results represent the <strong>theoretical upper bound</strong> of what a compression-based approach can achieve.</p>\n<pre><code>GT (320³) ──→ Z-axis 1/2 compression (160x320x320) ──→ Restore to original size (320³) ──→ Compare with GT\n</code></pre>\n<p>We used <code>scipy.ndimage.zoom</code> for compression, progressively improving the interpolation method, label format, and post-processing.</p>\n<h3>Evaluation Metrics</h3>\n<p>We used the official metrics (Combined Score = 0.30 × TopoScore + 0.35 × SurfaceDice + 0.35 × VOI Score). Perfect reversibility would yield Combined = 1.0.</p>\n<h3>Data</h3>\n<p>We sampled 5 volumes per scroll ID from the training data (three volume sizes exist: 320³: 738 samples, 256³: 47 samples, 384³: 1 sample).</p>\n<h2>Results</h2>\n<h3>Step 1: Nearest Neighbor (Baseline)</h3>\n<p>As the simplest approach, we performed compression and restoration using Nearest Neighbor interpolation (<code>order=0</code>).</p>\n<table>\n<thead>\n<tr>\n<th>Combined</th>\n<th>SDice</th>\n<th>VOI</th>\n<th>Topo</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>0.435</td>\n<td>0.962</td>\n<td>0.265</td>\n<td>0.020</td>\n</tr>\n</tbody>\n</table>\n<p>SDice was a reasonable 0.96, but <strong>TopoScore was nearly zero at 0.02</strong>. Nearest Neighbor discards alternating slices during compression and duplicates them during restoration, significantly altering the 3D connectivity structure.</p>\n<h3>Step 2: Linear Interpolation + Soft Labels</h3>\n<p>To address the Nearest Neighbor issues, we switched to Linear interpolation (<code>order=1</code>). Here, a critical design decision arose:</p>\n<p><strong>Should we binarize after compression (Hard), or preserve probability values (Soft)?</strong></p>\n<pre><code>Hard: GT → Linear compress → Binarize at threshold 0.5 → Linear restore → Threshold 0.5\nSoft: GT → Linear compress → Keep as probabilities (0.0-1.0) → Linear restore → Threshold 0.5\n</code></pre>\n<p>The Hard approach discards information at the compression stage and degrades again through thresholding during restoration. The Soft approach preserves the intermediate representation and only binarizes at the final stage.</p>\n<table>\n<thead>\n<tr>\n<th>Method</th>\n<th>Combined</th>\n<th>SDice</th>\n<th>VOI</th>\n<th>Topo</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Nearest Neighbor</td>\n<td>0.435</td>\n<td>0.962</td>\n<td>0.265</td>\n<td>0.020</td>\n</tr>\n<tr>\n<td>Linear (Hard)</td>\n<td>0.435</td>\n<td>0.962</td>\n<td>0.265</td>\n<td>0.020</td>\n</tr>\n<tr>\n<td><strong>Linear (Soft)</strong></td>\n<td><strong>0.810</strong></td>\n<td><strong>1.000</strong></td>\n<td><strong>0.844</strong></td>\n<td><strong>0.550</strong></td>\n</tr>\n</tbody>\n</table>\n<p>Linear (Hard) produced exactly the same scores as Nearest Neighbor. In contrast, <strong>simply preserving soft labels jumped Combined from 0.44 to 0.81</strong>. SDice reached a perfect 1.000, and VOI was a strong 0.84. Soft label preservation was the single biggest breakthrough in this experiment.</p>\n<p>However, TopoScore remained at 0.55, leaving room for improvement.</p>\n<h3>Step 3: Boundary Frame Preservation</h3>\n<p><code>scipy.ndimage.zoom</code> has a known issue where boundary frames collapse (the last frame becomes 0). In our data, the first and last 3 pixels along the Z-axis are ignore regions, so we overwrote these boundary frames with the original data after compression.</p>\n<pre><code>comp[0] = orig[0]        # ignore start\ncomp[1] = orig[3]        # valid region boundary (preserve binary)\ncomp[-2] = orig[-4]      # valid region boundary (preserve binary)\ncomp[-1] = orig[-1]      # ignore end\n</code></pre>\n<p>The results in Step 2's table (Combined 0.810) already include this boundary preservation.</p>\n<h3>Step 4: Morphological Topology Repair</h3>\n<p>We investigated why TopoScore remained at 0.55 after Steps 2-3. Linear interpolation generates intermediate values (0.3-0.7), and thresholding at 0.5 creates tiny holes. In 3D, these holes form <strong>loop structures (B1 tunnels)</strong> that are invisible in 2D slices but change the 3D topology.</p>\n<p>We applied <strong>dilation followed by erosion (Closing)</strong> to repair these artifacts.</p>\n<pre><code>from scipy.ndimage import binary_dilation, binary_erosion\npred_fixed = binary_erosion(binary_dilation(pred, iterations=1), iterations=1)\n</code></pre>\n<p>The effect varied dramatically by data size.</p>\n<p><strong>Size 320 (738 samples, GT tunnel count B1=0, simple structure):</strong></p>\n<table>\n<thead>\n<tr>\n<th>Processing</th>\n<th>Combined</th>\n<th>Topo</th>\n<th>B1 Change</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Soft + Boundary</td>\n<td>0.798</td>\n<td>0.550</td>\n<td>0→3</td>\n</tr>\n<tr>\n<td>+ Closing</td>\n<td>0.798</td>\n<td>0.550</td>\n<td>0→3</td>\n</tr>\n</tbody>\n</table>\n<p>No effect on size 320. The 3 B1 tunnels introduced by compression-restoration could not be removed by closing.</p>\n<p><strong>Size 256 (47 samples, GT tunnel count B1≈40, complex branching structure):</strong></p>\n<table>\n<thead>\n<tr>\n<th>Processing</th>\n<th>Combined</th>\n<th>Topo</th>\n<th>B1 Change</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Soft + Boundary</td>\n<td>0.752</td>\n<td>0.474</td>\n<td>40→2919</td>\n</tr>\n<tr>\n<td><strong>+ Closing</strong></td>\n<td><strong>0.888</strong></td>\n<td><strong>0.899</strong></td>\n<td><strong>40→50</strong></td>\n</tr>\n</tbody>\n</table>\n<p>For size 256, B1 had exploded from 40 to 2,919, but closing suppressed it to 50, resulting in a <strong>massive TopoScore improvement from 0.47 to 0.90</strong>.</p>\n<h3>Step 5: Compression Ratio Comparison (1/2 vs 1/3)</h3>\n<p>We also tested 1/3 compression for further speedup.</p>\n<p><strong>Size 320:</strong></p>\n<table>\n<thead>\n<tr>\n<th>Ratio</th>\n<th>Compressed Z</th>\n<th>Combined</th>\n<th>VOI</th>\n<th>Topo</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>1/2</td>\n<td>160</td>\n<td>0.798</td>\n<td>0.809</td>\n<td>0.550</td>\n</tr>\n<tr>\n<td>1/3</td>\n<td>106</td>\n<td>0.685</td>\n<td>0.566</td>\n<td>0.456</td>\n</tr>\n</tbody>\n</table>\n<p><strong>Size 256 (after closing):</strong></p>\n<table>\n<thead>\n<tr>\n<th>Ratio</th>\n<th>Compressed Z</th>\n<th>Combined</th>\n<th>VOI</th>\n<th>Topo</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>1/2</td>\n<td>128</td>\n<td><strong>0.888</strong></td>\n<td>0.765</td>\n<td><strong>0.899</strong></td>\n</tr>\n<tr>\n<td>1/3</td>\n<td>85</td>\n<td>0.614</td>\n<td>0.485</td>\n<td>0.314</td>\n</tr>\n</tbody>\n</table>\n<p>1/3 compression caused significant Combined drops: -0.11 for size 320 and -0.27 for size 256. <strong>1/2 is the practical limit</strong>.</p>\n<h2>Analysis of Remaining TopoScore Degradation</h2>\n<p>We investigated the remaining TopoScore = 0.55 issue for size 320. Examining the Betti Matching breakdown:</p>\n<table>\n<thead>\n<tr>\n<th>Betti Number</th>\n<th>GT</th>\n<th>Restored</th>\n<th>Matched</th>\n<th>F1</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>B0 (connected components)</td>\n<td>17</td>\n<td>19</td>\n<td>17</td>\n<td>0.94</td>\n</tr>\n<tr>\n<td>B1 (tunnels)</td>\n<td>0</td>\n<td>3</td>\n<td>0</td>\n<td>0.14</td>\n</tr>\n</tbody>\n</table>\n<p>B0 (component count) is nearly perfectly preserved (F1=0.94). The problem lies in B1: 3 tunnels appear where there were originally 0. Since TopoScore averages the F1 of B0 and B1, the B1 F1 of 0.14 drags the overall score down to 0.55.</p>\n<p>These 3 B1 tunnels are tiny loops created by the threshold processing during compression-restoration, and could not be removed by morphological closing. However, this is an error of \"3 tunnels added to a perfectly clean GT\" --- in practice, model predictions contain far more topological errors, so this is not a concern for real-world use.</p>\n<h2>Summary</h2>\n<p>Z-axis 1/2 compression is <strong>nearly reversible</strong> when combining soft label preservation + boundary preservation + morphological closing.</p>\n<table>\n<thead>\n<tr>\n<th>Data</th>\n<th>Combined</th>\n<th>SDice</th>\n<th>VOI</th>\n<th>Topo</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Size 320 (738 samples)</td>\n<td>0.810</td>\n<td>1.000</td>\n<td>0.844</td>\n<td>0.550</td>\n</tr>\n<tr>\n<td>Size 256 (47 samples) + post-processing</td>\n<td>0.888</td>\n<td>1.000</td>\n<td>0.765</td>\n<td>0.899</td>\n</tr>\n</tbody>\n</table>\n<table>\n<thead>\n<tr>\n<th>Improvement Step</th>\n<th>Effect</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Nearest Neighbor → Linear (Soft)</td>\n<td>Combined +0.37 (largest gain)</td>\n</tr>\n<tr>\n<td>+ Boundary preservation</td>\n<td>Boundary artifact elimination</td>\n</tr>\n<tr>\n<td>+ Morphological closing</td>\n<td>Size 256 Topo +0.43</td>\n</tr>\n</tbody>\n</table>\n<p>SDice and VOI are sufficiently high, indicating minimal geometric degradation from compression. The information loss from compression-restoration is judged to be small relative to model prediction errors, confirming the feasibility of compressed training. However, since top solutions achieved their scores with full-resolution training, further validation is needed to determine whether this method can reach gold-medal territory.</p>",
      "rawMarkdown": "# Reversibility of Z-axis Compression\n\n## Background\nIn my [solution](https://www.kaggle.com/competitions/vesuvius-challenge-surface-detection/writeups/18th-median-filter-x-7-post-processing-is-very-s), I used Z compression to speed things up.\nI also ran some basic experiments to confirm that using Z compression wouldn’t cause any issues, so I’m sharing the results here.\n\n\n3D training with nnU-Net is extremely computationally expensive. The Host Baseline (160x160x160 patch, ResidualEncoderUNet) takes approximately 165-200 seconds per epoch, making it difficult to compete with a single RTX 5090.\n\nWe considered an approach of **compressing the Z-axis by 1/2 for training and inference, then restoring to the original resolution**. To assess feasibility, we first quantitatively evaluated how much information is lost by compression and restoration alone (without any model), using the official metrics.\n\n## Experimental Design\n\nWe compressed and restored GT labels (3D binary masks), then compared them against the original GT. Since no model prediction is involved, the results represent the **theoretical upper bound** of what a compression-based approach can achieve.\n\n```\nGT (320³) ──→ Z-axis 1/2 compression (160x320x320) ──→ Restore to original size (320³) ──→ Compare with GT\n```\n\nWe used `scipy.ndimage.zoom` for compression, progressively improving the interpolation method, label format, and post-processing.\n\n### Evaluation Metrics\n\nWe used the official metrics (Combined Score = 0.30 × TopoScore + 0.35 × SurfaceDice + 0.35 × VOI Score). Perfect reversibility would yield Combined = 1.0.\n\n### Data\n\nWe sampled 5 volumes per scroll ID from the training data (three volume sizes exist: 320³: 738 samples, 256³: 47 samples, 384³: 1 sample).\n\n## Results\n\n### Step 1: Nearest Neighbor (Baseline)\n\nAs the simplest approach, we performed compression and restoration using Nearest Neighbor interpolation (`order=0`).\n\n| Combined | SDice | VOI | Topo |\n|----------|-------|-----|------|\n| 0.435 | 0.962 | 0.265 | 0.020 |\n\nSDice was a reasonable 0.96, but **TopoScore was nearly zero at 0.02**. Nearest Neighbor discards alternating slices during compression and duplicates them during restoration, significantly altering the 3D connectivity structure.\n\n### Step 2: Linear Interpolation + Soft Labels\n\nTo address the Nearest Neighbor issues, we switched to Linear interpolation (`order=1`). Here, a critical design decision arose:\n\n**Should we binarize after compression (Hard), or preserve probability values (Soft)?**\n\n```\nHard: GT → Linear compress → Binarize at threshold 0.5 → Linear restore → Threshold 0.5\nSoft: GT → Linear compress → Keep as probabilities (0.0-1.0) → Linear restore → Threshold 0.5\n```\n\nThe Hard approach discards information at the compression stage and degrades again through thresholding during restoration. The Soft approach preserves the intermediate representation and only binarizes at the final stage.\n\n| Method | Combined | SDice | VOI | Topo |\n|--------|----------|-------|-----|------|\n| Nearest Neighbor | 0.435 | 0.962 | 0.265 | 0.020 |\n| Linear (Hard) | 0.435 | 0.962 | 0.265 | 0.020 |\n| **Linear (Soft)** | **0.810** | **1.000** | **0.844** | **0.550** |\n\nLinear (Hard) produced exactly the same scores as Nearest Neighbor. In contrast, **simply preserving soft labels jumped Combined from 0.44 to 0.81**. SDice reached a perfect 1.000, and VOI was a strong 0.84. Soft label preservation was the single biggest breakthrough in this experiment.\n\nHowever, TopoScore remained at 0.55, leaving room for improvement.\n\n### Step 3: Boundary Frame Preservation\n\n`scipy.ndimage.zoom` has a known issue where boundary frames collapse (the last frame becomes 0). In our data, the first and last 3 pixels along the Z-axis are ignore regions, so we overwrote these boundary frames with the original data after compression.\n\n```python\ncomp[0] = orig[0]        # ignore start\ncomp[1] = orig[3]        # valid region boundary (preserve binary)\ncomp[-2] = orig[-4]      # valid region boundary (preserve binary)\ncomp[-1] = orig[-1]      # ignore end\n```\n\nThe results in Step 2's table (Combined 0.810) already include this boundary preservation.\n\n### Step 4: Morphological Topology Repair\n\nWe investigated why TopoScore remained at 0.55 after Steps 2-3. Linear interpolation generates intermediate values (0.3-0.7), and thresholding at 0.5 creates tiny holes. In 3D, these holes form **loop structures (B1 tunnels)** that are invisible in 2D slices but change the 3D topology.\n\nWe applied **dilation followed by erosion (Closing)** to repair these artifacts.\n\n```python\nfrom scipy.ndimage import binary_dilation, binary_erosion\npred_fixed = binary_erosion(binary_dilation(pred, iterations=1), iterations=1)\n```\n\nThe effect varied dramatically by data size.\n\n**Size 320 (738 samples, GT tunnel count B1=0, simple structure):**\n\n| Processing | Combined | Topo | B1 Change |\n|------------|----------|------|-----------|\n| Soft + Boundary | 0.798 | 0.550 | 0→3 |\n| + Closing | 0.798 | 0.550 | 0→3 |\n\nNo effect on size 320. The 3 B1 tunnels introduced by compression-restoration could not be removed by closing.\n\n**Size 256 (47 samples, GT tunnel count B1≈40, complex branching structure):**\n\n| Processing | Combined | Topo | B1 Change |\n|------------|----------|------|-----------|\n| Soft + Boundary | 0.752 | 0.474 | 40→2919 |\n| **+ Closing** | **0.888** | **0.899** | **40→50** |\n\nFor size 256, B1 had exploded from 40 to 2,919, but closing suppressed it to 50, resulting in a **massive TopoScore improvement from 0.47 to 0.90**.\n\n### Step 5: Compression Ratio Comparison (1/2 vs 1/3)\n\nWe also tested 1/3 compression for further speedup.\n\n**Size 320:**\n\n| Ratio | Compressed Z | Combined | VOI | Topo |\n|-------|-------------|----------|-----|------|\n| 1/2 | 160 | 0.798 | 0.809 | 0.550 |\n| 1/3 | 106 | 0.685 | 0.566 | 0.456 |\n\n**Size 256 (after closing):**\n\n| Ratio | Compressed Z | Combined | VOI | Topo |\n|-------|-------------|----------|-----|------|\n| 1/2 | 128 | **0.888** | 0.765 | **0.899** |\n| 1/3 | 85 | 0.614 | 0.485 | 0.314 |\n\n1/3 compression caused significant Combined drops: -0.11 for size 320 and -0.27 for size 256. **1/2 is the practical limit**.\n\n## Analysis of Remaining TopoScore Degradation\n\nWe investigated the remaining TopoScore = 0.55 issue for size 320. Examining the Betti Matching breakdown:\n\n| Betti Number | GT | Restored | Matched | F1 |\n|-------------|---:|--------:|--------:|---:|\n| B0 (connected components) | 17 | 19 | 17 | 0.94 |\n| B1 (tunnels) | 0 | 3 | 0 | 0.14 |\n\nB0 (component count) is nearly perfectly preserved (F1=0.94). The problem lies in B1: 3 tunnels appear where there were originally 0. Since TopoScore averages the F1 of B0 and B1, the B1 F1 of 0.14 drags the overall score down to 0.55.\n\nThese 3 B1 tunnels are tiny loops created by the threshold processing during compression-restoration, and could not be removed by morphological closing. However, this is an error of \"3 tunnels added to a perfectly clean GT\" --- in practice, model predictions contain far more topological errors, so this is not a concern for real-world use.\n\n## Summary\n\nZ-axis 1/2 compression is **nearly reversible** when combining soft label preservation + boundary preservation + morphological closing.\n\n| Data | Combined | SDice | VOI | Topo |\n|------|----------|-------|-----|------|\n| Size 320 (738 samples) | 0.810 | 1.000 | 0.844 | 0.550 |\n| Size 256 (47 samples) + post-processing | 0.888 | 1.000 | 0.765 | 0.899 |\n\n| Improvement Step | Effect |\n|-----------------|--------|\n| Nearest Neighbor → Linear (Soft) | Combined +0.37 (largest gain) |\n| + Boundary preservation | Boundary artifact elimination |\n| + Morphological closing | Size 256 Topo +0.43 |\n\nSDice and VOI are sufficiently high, indicating minimal geometric degradation from compression. The information loss from compression-restoration is judged to be small relative to model prediction errors, confirming the feasibility of compressed training. However, since top solutions achieved their scores with full-resolution training, further validation is needed to determine whether this method can reach gold-medal territory.",
      "votes": null
    },
    {
      "id": "3415764",
      "postDate": "03/01/2026 09:26:59",
      "content": "<p>This is very interesting, thank you!</p>\n<p>My question regarding an analysis was also related to a preference in the axis (Z rather than other ones) because, even if we scan the scrolls vertically, some regions can heavily fold!</p>",
      "rawMarkdown": "This is very interesting, thank you!\n\nMy question regarding an analysis was also related to a preference in the axis (Z rather than other ones) because, even if we scan the scrolls vertically, some regions can heavily fold!",
      "votes": null
    },
    {
      "id": "3416070",
      "postDate": "03/02/2026 02:10:54",
      "content": "<p>Thank you for your comment!!!\nSorry—I may not have fully understood the intent of your question.</p>\n<p>I tried testing compression along the XY, XZ, and YZ axes. When using XY as the vertical/horizontal directions, I often found that the XZ/YZ plane intersects a wide surface area in certain slices, so I judged that compression along the other axes could be risky.</p>\n<p>That said, given that my model is not currently in the gold range, it’s possible there are issues in the area you pointed out.</p>",
      "rawMarkdown": "Thank you for your comment!!!\nSorry—I may not have fully understood the intent of your question.\n\nI tried testing compression along the XY, XZ, and YZ axes. When using XY as the vertical/horizontal directions, I often found that the XZ/YZ plane intersects a wide surface area in certain slices, so I judged that compression along the other axes could be risky.\n\nThat said, given that my model is not currently in the gold range, it’s possible there are issues in the area you pointed out.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 3415764,
      "author_name": "giorgioangelotti",
      "author_url": "",
      "post_date": "03/01/2026 09:26:59",
      "content": "<p>This is very interesting, thank you!</p>\n<p>My question regarding an analysis was also related to a preference in the axis (Z rather than other ones) because, even if we scan the scrolls vertically, some regions can heavily fold!</p>",
      "votes": null,
      "replies": [
        {
          "id": 3416070,
          "author_name": "sugupoko",
          "author_url": "",
          "post_date": "03/02/2026 02:10:54",
          "content": "<p>Thank you for your comment!!!\nSorry—I may not have fully understood the intent of your question.</p>\n<p>I tried testing compression along the XY, XZ, and YZ axes. When using XY as the vertical/horizontal directions, I often found that the XZ/YZ plane intersects a wide surface area in certain slices, so I judged that compression along the other axes could be risky.</p>\n<p>That said, given that my model is not currently in the gold range, it’s possible there are issues in the area you pointed out.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "3415527": "# Reversibility of Z-axis Compression\n\n## Background\nIn my [solution](https://www.kaggle.com/competitions/vesuvius-challenge-surface-detection/writeups/18th-median-filter-x-7-post-processing-is-very-s), I used Z compression to speed things up.\nI also ran some basic experiments to confirm that using Z compression wouldn’t cause any issues, so I’m sharing the results here.\n\n\n3D training with nnU-Net is extremely computationally expensive. The Host Baseline (160x160x160 patch, ResidualEncoderUNet) takes approximately 165-200 seconds per epoch, making it difficult to compete with a single RTX 5090.\n\nWe considered an approach of **compressing the Z-axis by 1/2 for training and inference, then restoring to the original resolution**. To assess feasibility, we first quantitatively evaluated how much information is lost by compression and restoration alone (without any model), using the official metrics.\n\n## Experimental Design\n\nWe compressed and restored GT labels (3D binary masks), then compared them against the original GT. Since no model prediction is involved, the results represent the **theoretical upper bound** of what a compression-based approach can achieve.\n\n```\nGT (320³) ──→ Z-axis 1/2 compression (160x320x320) ──→ Restore to original size (320³) ──→ Compare with GT\n```\n\nWe used `scipy.ndimage.zoom` for compression, progressively improving the interpolation method, label format, and post-processing.\n\n### Evaluation Metrics\n\nWe used the official metrics (Combined Score = 0.30 × TopoScore + 0.35 × SurfaceDice + 0.35 × VOI Score). Perfect reversibility would yield Combined = 1.0.\n\n### Data\n\nWe sampled 5 volumes per scroll ID from the training data (three volume sizes exist: 320³: 738 samples, 256³: 47 samples, 384³: 1 sample).\n\n## Results\n\n### Step 1: Nearest Neighbor (Baseline)\n\nAs the simplest approach, we performed compression and restoration using Nearest Neighbor interpolation (`order=0`).\n\n| Combined | SDice | VOI | Topo |\n|----------|-------|-----|------|\n| 0.435 | 0.962 | 0.265 | 0.020 |\n\nSDice was a reasonable 0.96, but **TopoScore was nearly zero at 0.02**. Nearest Neighbor discards alternating slices during compression and duplicates them during restoration, significantly altering the 3D connectivity structure.\n\n### Step 2: Linear Interpolation + Soft Labels\n\nTo address the Nearest Neighbor issues, we switched to Linear interpolation (`order=1`). Here, a critical design decision arose:\n\n**Should we binarize after compression (Hard), or preserve probability values (Soft)?**\n\n```\nHard: GT → Linear compress → Binarize at threshold 0.5 → Linear restore → Threshold 0.5\nSoft: GT → Linear compress → Keep as probabilities (0.0-1.0) → Linear restore → Threshold 0.5\n```\n\nThe Hard approach discards information at the compression stage and degrades again through thresholding during restoration. The Soft approach preserves the intermediate representation and only binarizes at the final stage.\n\n| Method | Combined | SDice | VOI | Topo |\n|--------|----------|-------|-----|------|\n| Nearest Neighbor | 0.435 | 0.962 | 0.265 | 0.020 |\n| Linear (Hard) | 0.435 | 0.962 | 0.265 | 0.020 |\n| **Linear (Soft)** | **0.810** | **1.000** | **0.844** | **0.550** |\n\nLinear (Hard) produced exactly the same scores as Nearest Neighbor. In contrast, **simply preserving soft labels jumped Combined from 0.44 to 0.81**. SDice reached a perfect 1.000, and VOI was a strong 0.84. Soft label preservation was the single biggest breakthrough in this experiment.\n\nHowever, TopoScore remained at 0.55, leaving room for improvement.\n\n### Step 3: Boundary Frame Preservation\n\n`scipy.ndimage.zoom` has a known issue where boundary frames collapse (the last frame becomes 0). In our data, the first and last 3 pixels along the Z-axis are ignore regions, so we overwrote these boundary frames with the original data after compression.\n\n```python\ncomp[0] = orig[0]        # ignore start\ncomp[1] = orig[3]        # valid region boundary (preserve binary)\ncomp[-2] = orig[-4]      # valid region boundary (preserve binary)\ncomp[-1] = orig[-1]      # ignore end\n```\n\nThe results in Step 2's table (Combined 0.810) already include this boundary preservation.\n\n### Step 4: Morphological Topology Repair\n\nWe investigated why TopoScore remained at 0.55 after Steps 2-3. Linear interpolation generates intermediate values (0.3-0.7), and thresholding at 0.5 creates tiny holes. In 3D, these holes form **loop structures (B1 tunnels)** that are invisible in 2D slices but change the 3D topology.\n\nWe applied **dilation followed by erosion (Closing)** to repair these artifacts.\n\n```python\nfrom scipy.ndimage import binary_dilation, binary_erosion\npred_fixed = binary_erosion(binary_dilation(pred, iterations=1), iterations=1)\n```\n\nThe effect varied dramatically by data size.\n\n**Size 320 (738 samples, GT tunnel count B1=0, simple structure):**\n\n| Processing | Combined | Topo | B1 Change |\n|------------|----------|------|-----------|\n| Soft + Boundary | 0.798 | 0.550 | 0→3 |\n| + Closing | 0.798 | 0.550 | 0→3 |\n\nNo effect on size 320. The 3 B1 tunnels introduced by compression-restoration could not be removed by closing.\n\n**Size 256 (47 samples, GT tunnel count B1≈40, complex branching structure):**\n\n| Processing | Combined | Topo | B1 Change |\n|------------|----------|------|-----------|\n| Soft + Boundary | 0.752 | 0.474 | 40→2919 |\n| **+ Closing** | **0.888** | **0.899** | **40→50** |\n\nFor size 256, B1 had exploded from 40 to 2,919, but closing suppressed it to 50, resulting in a **massive TopoScore improvement from 0.47 to 0.90**.\n\n### Step 5: Compression Ratio Comparison (1/2 vs 1/3)\n\nWe also tested 1/3 compression for further speedup.\n\n**Size 320:**\n\n| Ratio | Compressed Z | Combined | VOI | Topo |\n|-------|-------------|----------|-----|------|\n| 1/2 | 160 | 0.798 | 0.809 | 0.550 |\n| 1/3 | 106 | 0.685 | 0.566 | 0.456 |\n\n**Size 256 (after closing):**\n\n| Ratio | Compressed Z | Combined | VOI | Topo |\n|-------|-------------|----------|-----|------|\n| 1/2 | 128 | **0.888** | 0.765 | **0.899** |\n| 1/3 | 85 | 0.614 | 0.485 | 0.314 |\n\n1/3 compression caused significant Combined drops: -0.11 for size 320 and -0.27 for size 256. **1/2 is the practical limit**.\n\n## Analysis of Remaining TopoScore Degradation\n\nWe investigated the remaining TopoScore = 0.55 issue for size 320. Examining the Betti Matching breakdown:\n\n| Betti Number | GT | Restored | Matched | F1 |\n|-------------|---:|--------:|--------:|---:|\n| B0 (connected components) | 17 | 19 | 17 | 0.94 |\n| B1 (tunnels) | 0 | 3 | 0 | 0.14 |\n\nB0 (component count) is nearly perfectly preserved (F1=0.94). The problem lies in B1: 3 tunnels appear where there were originally 0. Since TopoScore averages the F1 of B0 and B1, the B1 F1 of 0.14 drags the overall score down to 0.55.\n\nThese 3 B1 tunnels are tiny loops created by the threshold processing during compression-restoration, and could not be removed by morphological closing. However, this is an error of \"3 tunnels added to a perfectly clean GT\" --- in practice, model predictions contain far more topological errors, so this is not a concern for real-world use.\n\n## Summary\n\nZ-axis 1/2 compression is **nearly reversible** when combining soft label preservation + boundary preservation + morphological closing.\n\n| Data | Combined | SDice | VOI | Topo |\n|------|----------|-------|-----|------|\n| Size 320 (738 samples) | 0.810 | 1.000 | 0.844 | 0.550 |\n| Size 256 (47 samples) + post-processing | 0.888 | 1.000 | 0.765 | 0.899 |\n\n| Improvement Step | Effect |\n|-----------------|--------|\n| Nearest Neighbor → Linear (Soft) | Combined +0.37 (largest gain) |\n| + Boundary preservation | Boundary artifact elimination |\n| + Morphological closing | Size 256 Topo +0.43 |\n\nSDice and VOI are sufficiently high, indicating minimal geometric degradation from compression. The information loss from compression-restoration is judged to be small relative to model prediction errors, confirming the feasibility of compressed training. However, since top solutions achieved their scores with full-resolution training, further validation is needed to determine whether this method can reach gold-medal territory.",
    "3415764": "This is very interesting, thank you!\n\nMy question regarding an analysis was also related to a preference in the axis (Z rather than other ones) because, even if we scan the scrolls vertically, some regions can heavily fold!",
    "3416070": "Thank you for your comment!!!\nSorry—I may not have fully understood the intent of your question.\n\nI tried testing compression along the XY, XZ, and YZ axes. When using XY as the vertical/horizontal directions, I often found that the XZ/YZ plane intersects a wide surface area in certain slices, so I judged that compression along the other axes could be risky.\n\nThat said, given that my model is not currently in the gold range, it’s possible there are issues in the area you pointed out."
  },
  "source": "meta"
}