EP03_02 🔀 Alpha Blending of Two Images
In nuclear medicine, images from different modalities (computed tomography and magnetic resonance imaging) are fused to aid in diagnosis. Weighted blending (alpha blending ) is the fundamental operation of this process, allowing the radiologist to interactively control the weight of each modality in the displayed image.
See Figure 3.27 for a simulation of this EP.
📋 Implementation Guidelines
Dimensions: Read the integers \(L\) (rows) and \(C\) (columns).
Parameter: Read the real value \(\alpha \in [0, 1]\) .
Data: Read the integer values of matrix \(f_1\) (image 1) followed by those of matrix \(f_2\) (image 2).
Mapping: For each position \((i, j)\) , compute:
\[g(i,j) = \text{clip}\left(\text{round}\left(\alpha \cdot f_1(i,j) + (1-\alpha) \cdot f_2(i,j)\right)\right)\]
Output: Display the resulting \(L \times C\) matrix.
📌 Computational Constraints
Rounding: Apply round before converting to integer.
Saturation: Constrain to the interval \([0, 255]\) with \(\text{clip}(x) = \max(0, \min(255, x))\) .
Float operation: Perform the operation in floating point before rounding.
🧠 Theoretical Background
\(\alpha = 1.0\)
Only \(f_1\)
\(\alpha = 0.5\)
Arithmetic mean of \(f_1\) and \(f_2\)
\(\alpha = 0.0\)
Only \(f_2\)
📌 Examples
1
3
0.5
0 100 200
100 200 50
50 150 125
Mean between the two images
1
3
1.0
10 20 30
90 80 70
10 20 30
Only \(f_1\) (alpha=1)
Figure 3.27: Simulator EP03_02: Alpha Blending of Two Images (g = α·f1 + (1−α)·f2)
%% writefile EP03_02.cpp
// your solution
TestSuite("EP03_02.cpp" ).run()
✔️ EP03_02.cases already exists in casos/
📋 6 case(s) loaded from casos/EP03_02.cases
🔍 Testing C++: EP03_02.cpp
⚠️ EP03_02.cpp: Empty file (fewer than 3 lines). Tests skipped.