目錄
一、安裝
二、使用
1. 載入包
2. 圖片增強
3. 影像輸出
一、安裝
pip install Augmentor
二、使用
1. 載入包
注意此處兩個檔案夾中圖片名必須完全一致,包括后綴名,這樣的話對原圖進行了操作也會同步對掩碼影像進行操作(要是jpg都得是jpg,要是png都得是png,本人用的labelme后josn檔案轉的png,是將jpg的原圖轉化成png,而不是對掩碼影像進行修改)
import Augmentor
#注意此處兩個檔案夾中圖片名必須完全一致,包括后綴名
p = Augmentor.Pipeline('./images') #images中是原影像
p.ground_truth('./labels') #labels中是掩碼影像
2. 圖片增強
基于現在網上關于Augmentor的使用方法不多,很多功能都沒有被列出來,可以使用help去查看一下里面包含的各種用法,
help(Augmentor)
Methods inherited from Pipeline:
|
| __call__(self, augmentor_image)
| Function used by the ThreadPoolExecutor to process the pipeline
| using multiple threads. Do not call directly.
|
| This function does nothing except call :func:`_execute`, rather
| than :func:`_execute` being called directly in :func:`sample`.
| This makes it possible for the procedure to be *pickled* and
| therefore suitable for multi-threading.
|
| :param augmentor_image: The image to pass through the pipeline.
| :return: None
|
| black_and_white(self, probability, threshold=128)
| Convert images to black and white. In other words convert the image
| to use a 1-bit, binary palette. The threshold defaults to 128,
| but can be controlled using the :attr:`threshold` parameter.
|
| .. seealso:: The :func:`greyscale` function.
|
| :param probability: A value between 0 and 1 representing the
| probability that the operation should be performed. For resizing,
| it is recommended that the probability be set to 1.
| :param threshold: A value between 0 and 255 which controls the
| threshold point at which each pixel is converted to either black
| or white. Any values above this threshold are converted to white, and
| any values below this threshold are converted to black.
| :type probability: Float
| :type threshold: Integer
| :return: None
里面有大量關于Augmentor用法,可以自己去查找,下面列舉了一些我自己常用的方法,
# 影像旋轉,按照0.5的概率,最大左旋轉角度20,右旋轉角度10
# 左右的角度必須在25之內
p.rotate(probability=.5, max_left_rotation=20, max_right_rotation=10)
# 影像左右、上下、隨機左右上下翻轉
p.flip_left_right(probability=0.5)
p.flip_top_bottom(probability=0.5)
p.flip_random(probability=1)
# 旋轉90
p.rotate90(probability=0.5)
# # 影像放大縮小,按照概率為0.5,面積為原來的0.9倍
p.zoom_random(probability=.5, percentage_area=0.9)
# # 裁剪
p.crop_random(probability=.5, percentage_area=0.8)
# 亮度
p.random_brightness(probability=.2, min_factor=0.1, max_factor=0.9)
雖然這些方法都應該可以使用,但我在跑代碼以后,出現了部分操作掩碼影像生成以后是全黑的情況,經過排查只要有關于大小變動的好像都不能進行好掩碼圖的操作,所以本人直接放棄了部分操作,(我的資料集只需要進行簡單的增強)
3. 影像輸出
兩種操作過后都會在images檔案夾下生成output檔案夾,生成的結果都存在里面了,
第一種生成影像存在重復影像過多和部分影像刪減沒了的問題,因此我用的一般都是第二種,
# 最終擴充的樣本數量
p.sample(6)
# 對檔案夾中每個圖片進行一次操作
p.process()
這樣基本上就可以解決大部分的語意分割影像增強的問題了,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/339295.html
標籤:其他
