I have two arrays like
red = np.array([0.3, 0.4, 0.3, 0.3, 0.6, 0.3, 0.3, 0.7, 0.8, 0.7, 0.4, 0.5, 0.6, 0.6])
blue = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.6, 0.9, 0.6, 0.2, 0.2, 0.2, 0.2])
The desired result is
red_out = np.array([0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0])
blue_out = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0])
In the actual task, those are two distinct segmentation masks for an image, hence those are 2d arrays.
Any value below 0.5 is set to 0.0 (part 1 on the plot) If only one of the arrays at this position is above 0.5: set this position to 1.0 (part 2 on the plot) If two values are above 0.5, then find max value in that area (part 3). Whichever array wins (in this case blue) is filled with 1.0 in positions where the original value was greater than 0.5. The "losing" array is filled with 0.0 unless it has a 'large enough' peak like 3c. Here large enough means "the maximal point of red array" is something like (max(re_in_a_patch) - 0.5) > 2 * (red_blue_intersection_level - 0.5).
What would be reasonable and simple to compute in Numpy criteria to
- Select points of the highest values in the overlaying region
- Extend the paramount peak to 0.5 sea level
- Ignore small enough spikes on the losing peak, but do select large enough peak
Update. I have several models for predicting acne on the images of a person's skin. Sometimes a model confuses pustules and papules on low quality images. A pustule is detected as a pustule (max confidence of 90%, blue line) and as a papule (max confidence at 70%, but much broader region, red line).
When I do simple voting for the region 3a I get a blue mask in the center (corresponding to pustule) that is surrounded by red mask (corresponding to papule false positive). This result is undesirable, so I want to extend the area of a pustule mask further down to 50+% confidence, even though 3b area has higher confidence in red than in blue.

- blue wins in the index-range 7 to 9. Why is that? Isn't red with 0.7 dominating over the blue entry 0.6 at index 7 and 9?
- What is the 'large enough' peak like '3c'?
– fabi Sep 17 '21 at 10:23