Setting particular pixel to specified color in the output of segmentation map

sparshgarg23: <p>I was able to run semantic segmentation on the below image.The problem is given all pixels belonging to the sky category I need to set them to white<br>
.<br>
For this my approach is as follows</p>
<ol>
<li>obtain semantic map output</li>
<li>then find  all pixels belonging to the sky class[which in this case have their color value set to 6,230,230]</li>
<li>And then set them all to 255.</li>
</ol>
<p>The original image<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/0/d0a8df601ba03a67d885a1db93ba3703ebff1fc1.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/d0a8df601ba03a67d885a1db93ba3703ebff1fc1" title="ADE_val_00000004"><img src="https://discuss.pytorch.org/uploads/default/original/3X/d/0/d0a8df601ba03a67d885a1db93ba3703ebff1fc1.jpeg" alt="ADE_val_00000004" data-base62-sha1="tLT7xBqy9RIe9tESy7FbMIeIX9D" width="666" height="500" data-dominant-color="848F82"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">ADE_val_00000004</span><span class="informations">683×512 45.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>And its  semantic map output is as follows<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/f/9/f9fa960f278a3cf0cfb71ee24414191890ad4114.png" alt="res_img" data-base62-sha1="zFpLEeLcd28Nu2UM6DwYd4zVj6I" width="640" height="479"></p>
<p>This is what i have tried</p>
<pre><code class="lang-auto">indice_r=np.where(image[:,:,0]==6)
indice_g=np.where(image[:,:,1]==230)
indice_b=np.where(image[:,:,2]==230)
#Set the pixel value for those found indices(here we are performing this across B ) to 0
#The same step is done twice for R and G respectively
for i in range(len(indice_b[0])):
  for j in range(len(indice_b[1])):
    new_img[i,j,2]=255

</code></pre>
<p>Unfortunately this approach didn’t work as it only made a small section on the top left white<br>
So i was wondering is this really the right approach and how can I generalize this to handle any class rather than sky.For example what if we want to set the pixels belonging to the person to white.</p>
<p>Note in all images the sky class has been color coded as [6,230,230 This is the standard choice of the semantic pallete  chosen in the ADE dataset.</p>
<p>Another approach is to use bitwise_and to select the blue regions in the semantic map and then subtract that from the original image.However that requires a lower and upper range which may differ from image to image.</p>
<p>In case it’s not clear why my first approach to setting pixels to white isn’t working.<br>
this is the result for the first approach<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/4/5/45798b96a44362652119f83410f779a35cc28a03.png" alt="wrong_result" data-base62-sha1="9UBm0BjUUJBJ0e6Q7SVSN0khPWP" width="640" height="479"></p>
<p>So i tried using the bitwise idea.<br>
Here i converted the image to hsv to get a better understanding of which pixels are set to blue or light blue<br>
The HSV plot is shown below<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/0/7/0701ea6754f562b06bb17a19fdbfbe6561479272.png" alt="hsv_ade" data-base62-sha1="ZZrGsTFgJB9NUydHwpwDOwMXey" width="411" height="397"></p>
<p>from this i think the light blue lower and upper ranges are<br>
(77,90,0) and (125,250,225)<br>
Using this i created the bitwise mask and obtained this beauty<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/5/5/5585169fa1b54a28043c12d1b21681c8093672f6.png" alt="bitwise_mask" data-base62-sha1="ccxIYS268HQJTePzBXMJIOZvBdA" width="552" height="217"></p>
<p>Code for masking</p>
<pre><code class="lang-auto">mask = cv2.inRange(hsv_img, light_b, high_b)
result = cv2.bitwise_and(img, img, mask=mask)
plt.subplot(1, 2, 1)
plt.imshow(mask, cmap="gray")
plt.subplot(1, 2, 2)
plt.imshow(result)
plt.show()
</code></pre>
<p>Not sure why the sky is jet black here.</p>
<p>Would appreciate it if some kind soul could help me</p>