#問題提出:
路面のセグメンテーション画像があります。真ん中には赤い車線分割線があり、両側に道路標示があります。反対側の車線の路面標示を隠したい(つまり、車線分割線の右側の路面標示を削除する)。
#問題解決
##コード
import matplotlib.pyplot as plt
file_pth = "./data/3.png"
img = plt.imread(file_pth)
target = (0.5019608, 0, 0, 1)
width = img.shape[1]
height = img.shape[0]
x = []
y = []
for i in range(height):
for j in range(width):
if abs(img[i, j, 0]-target[0])<0.01 and abs(img[i, j, 1]-target[1])<0.01 and abs(img[i, j, 2]-target[2])<0.01 and img[i,j,3] == target[3]:
x.append(i)
y.append(j)
l = len(x)
plt.subplot(121)
plt.imshow(img)
for i in range(l-1):
if i != l-1 and x[i] == x[i+1]:
continue
for j in range(y[i], width):
img[x[i], j, 0] = 0
img[x[i], j, 1] = 0
img[x[i], j, 2] = 0
plt.subplot(122)
plt.imshow(img)
plt.show()
基本的な手順は、各行の区画線(赤い線)の一番右のピクセルの座標を確定します。次に、各行で区画線の一番右のピクセルの右側にあるピクセルを全部黒にします。