1

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

  1. Select points of the highest values in the overlaying region
  2. Extend the paramount peak to 0.5 sea level
  3. Ignore small enough spikes on the losing peak, but do select large enough peak

enter image description here

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.

Stepan
  • 1,093
  • didnt quite get it. please clarify two things for me:
    1. 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?
    2. What is the 'large enough' peak like '3c'?
    – fabi Sep 17 '21 at 10:23
  • @fabi I have updated the question. – Stepan Sep 20 '21 at 11:17
  • sounds like a blue peak should fractionally contribute to its surrounding area like a high temperature heating near areas as well with a decreasing effect with increasing distance. Is that right? as far my understanding goes, I would search for every blue entry in its neighborhood for a peak (greater value than itself and max neighbor) and add a fraction of that peak to its value. the fraction should be depending on that condition you gave ($max(\text{red_patch}) - 0.5 > 2 * ... $). then do the simple test for the minimum sea level and the max of blue or red entries. – fabi Sep 23 '21 at 10:32
  • to be precisely on that fraction I got one more question: what is red_blue_intersection_level in case 3c and what exactly is re_in_a_patch? and what is a patch? – fabi Sep 23 '21 at 10:36

0 Answers0