2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

問題を解決した

Last updated at Posted at 2021-07-23

#問題提出:
路面のセグメンテーション画像があります。真ん中には赤い車線分割線があり、両側に道路標示があります。反対側の車線の路面標示を隠したい(つまり、車線分割線の右側の路面標示を削除する)。
image.png
#問題解決
image.png
##コード

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()

基本的な手順は、各行の区画線(赤い線)の一番右のピクセルの座標を確定します。次に、各行で区画線の一番右のピクセルの右側にあるピクセルを全部黒にします。

2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?