Back to list
smith6jt-cop

deconvolution-intensity-scaling

by smith6jt-cop

Using skills repo for AI memory management.

0🍴 0📅 Jan 23, 2026

SKILL.md


name: deconvolution-intensity-scaling description: "KINTSUGI deconvolution: Output scaling must preserve original intensity relationships for quantitative analysis. Trigger: deconvolution saturates at 65535, channel intensity ratios inverted, hist_clip scaling issues." author: KINTSUGI Team date: 2026-01-15

Deconvolution Intensity Scaling - Preserving Quantitative Relationships

Experiment Overview

ItemDetails
Date2026-01-15
GoalFix pixel range scaling errors that break quantitative marker analysis
EnvironmentKINTSUGI KDecon module, HiPerGator, CuPy GPU
StatusRESOLVED

Context

After deconvolution, all channels were saturating at 65535 (max uint16) regardless of their original intensity ranges. This caused:

  • Artificial clipping of bright regions
  • Inverted relative intensity relationships between channels
  • Broken quantitative marker expression analysis

Root Cause

The histogram clipping and rescaling logic in notebooks/Kdecon/main.py (lines 265-289) always stretched output to full 16-bit range:

# BROKEN CODE (before fix)
if raw_max <= 65535:
    scale = 65535  # <-- Always stretched to full range!
else:
    scale = raw_max
result = result * scale

Impact Analysis

ChannelStageMeanMaxProblem
CH2 (weak)Stitched28041,620-
CH2 (weak)Deconvolved11,10965,53539.7x mean inflation!
CH1 (DAPI)Stitched3,99858,214-
CH1 (DAPI)Deconvolved7,92765,5351.98x mean inflation

Critical: The CH1/CH2 intensity ratio was inverted from 14.28 to 0.71.

Solution

Change the scaling to preserve original intensity relationships:

# FIXED CODE
# Scale to output range - preserve original intensity scale
# Using raw_max maintains relative intensity relationships between channels,
# which is critical for quantitative analysis of marker expression
scale = raw_max

result = result * scale

Fixed Results

MetricBrokenFixed
CH2 max65,535 (saturated)41,620 (preserved)
CH1 max65,535 (saturated)58,214 (preserved)
CH1/CH2 ratio0.71 (inverted!)1.00 (consistent)

Failed Attempts (Critical)

AttemptWhy it FailedLesson Learned
Assuming 65535 scaling was intentionalDestroyed quantitative relationshipsAlways check if scaling preserves relative intensities
Only checking max valuesMissed the mean inflation and ratio inversionCheck both absolute AND relative intensity metrics
Ignoring hist_clip parameterIt normalizes to 0-1 then rescalesUnderstand the full pipeline before diagnosing
Looking only at single channelIssue only visible when comparing channelsMulti-channel analysis reveals scaling bugs

Diagnostic Checklist

When deconvolved images show intensity issues:

  1. Check for saturation: np.sum(img >= 65535) should be near zero
  2. Compare channel ratios: Before/after deconvolution should be similar
  3. Check mean inflation: Deconvolved mean shouldn't be dramatically higher than input
  4. Trace the scaling pipeline: Input → deconv → clip → normalize → scale → output

Key Parameters

ParameterValueDescription
hist_clip0.01Histogram clipping percentage (clips 0.01% at each end)
raw_maxvariesMaximum value from input image (used for output scaling)

Key Insights

  • Histogram clipping normalizes to 0-1: The hist_clip parameter clips percentiles, then normalizes the result to 0-1 range. The final scaling determines the output range.
  • Weak channels are most affected: Channels with low mean intensity show the largest inflation when stretched to full range.
  • Relative relationships matter for quantitative analysis: Marker expression comparisons require consistent scaling across channels.
  • Test with multiple channels: Single-channel testing won't reveal ratio inversion bugs.

Files Modified

  • notebooks/Kdecon/main.py: Lines 283-288 (scaling logic)
  • CLAUDE.md: Added documentation in Recent Enhancements section

References

  • notebooks/Kdecon/main.py: KDecon class and decon() function
  • notebooks/2_Cycle_Processing.ipynb: Deconvolution workflow
  • Related skill: lightsheet-psf-deconvolution (PSF-related deconvolution issues)

Score

Total Score

40/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon