前提
Random_Erasingする際の画像とマスクを合成したあとの画像が、元の画像に霧がかかっているような画像になってしまうため霧がからないようにしたいです。
実現したいこと
図1 元の画像
図2 Random_Erasingした画像
図3 被マスク画像の値
・図1にRandom_Erasingするだけで図2のようなRandom_Erasing+霧がかったような画像にはしたくないです。
該当のソースコード
python
1def random_erasing(img, p=1.0, sl=0.02, sh=0.4, r1=0.3, r2=3.3): 2 target_img = img.copy() 3 4 if p < np.random.rand(): 5 # RandomErasingを実行しない 6 return target_img 7 8 H, W, _ = target_img.shape 9 S = H * W 10 11 while True: 12 Se = np.random.uniform(sl, sh) * S # 画像に重畳する矩形の面積 13 re = np.random.uniform(r1, r2) # 画像に重畳する矩形のアスペクト比 14 15 He = int(np.sqrt(Se * re)) # 画像に重畳する矩形のHeight 16 We = int(np.sqrt(Se / re)) # 画像に重畳する矩形のWidth 17 18 xe = np.random.randint(0, W) # 画像に重畳する矩形のx座標 19 ye = np.random.randint(0, H) # 画像に重畳する矩形のy座標 20 21 if xe + We <= W and ye + He <= H: 22 # 画像に重畳する矩形が画像からはみ出していなければbreak 23 break 24 mask = np.random.randint(0, 255, (He, We, 3)) # 矩形がを生成 矩形内の値はランダム値 25 target_img[ye:ye + He, xe:xe+ We,:] = mask# 画像に矩形を重畳 26 27 return target_img
試したこと
上記のコードは、https://qiita.com/takurooo/items/a3cba475a3db2c7272fe
のコピペです。
原因がtarget_img[ye:0 + He, xe:0 + We,:] = maskにあると考え、別の合成方法を模索しましたができませんでした。
このような状態になっている記事もないため、もしかしたら私の環境が悪いのでしょうか。
補足情報(FW/ツールのバージョンなど)
windows11(64bit)
anacondaを使用
python 3.8.13
TensorFlow 2.3
Spyder 5.3.3を利用

回答1件
あなたの回答
tips
プレビュー