天天看點

Matlab 圖像像素級标注一、Matlab 版本:2020a二、啟動 Image Labeler三、圖像像素級标注

目錄

一、Matlab 版本:2020a

二、啟動 Image Labeler

三、圖像像素級标注

1、Load 選擇一張圖像 設定ROI Labels 

2、标注結束,儲存檔案 Export Lables -->to files,

3、儲存檔案說明

4、标注儲存為csv檔案

5、檢視标注後的圖像

6、最終的效果

一、Matlab 版本:2020a

二、啟動 Image Labeler

matlab 指令行輸入 imageLabeler,回車,打開界面

Matlab 圖像像素級标注一、Matlab 版本:2020a二、啟動 Image Labeler三、圖像像素級标注
Matlab 圖像像素級标注一、Matlab 版本:2020a二、啟動 Image Labeler三、圖像像素級标注

三、圖像像素級标注

1、Load 選擇一張圖像 設定ROI Labels 

Matlab 圖像像素級标注一、Matlab 版本:2020a二、啟動 Image Labeler三、圖像像素級标注

2、标注結束,儲存檔案 Export Lables -->to files,

Matlab 圖像像素級标注一、Matlab 版本:2020a二、啟動 Image Labeler三、圖像像素級标注

3、儲存檔案說明

儲存路徑下有兩個檔案,在檔案夾中打開Label_1.png 會是一張黑色的圖像,要在matlab 中打開。

Matlab 圖像像素級标注一、Matlab 版本:2020a二、啟動 Image Labeler三、圖像像素級标注

4、标注儲存為csv檔案

輕按兩下Label.png 圖像,彈出對話框點選完成

Matlab 圖像像素級标注一、Matlab 版本:2020a二、啟動 Image Labeler三、圖像像素級标注

在工作去會顯示Lable_1 和圖像的尺寸,标注(背景為0 ,分類标注1,2,.....)

輕按兩下打開,再ctrl+A全選,複制到 excel檔案中,另存為csv就可以了。

Matlab 圖像像素級标注一、Matlab 版本:2020a二、啟動 Image Labeler三、圖像像素級标注

5、檢視标注後的圖像

def csv2Img(csvFile,colorKey=None,filePath=None):
    '''
    将标記的csv轉換成圖像
    --------
    :param csvFile: 标注的檔案路徑
    :param colorKey: 類對應的RGB值
    :param filePath: 圖檔儲存路徑
    :return: None

    '''
    if colorKey==None:
        colorKey = {1: [0, 0, 255], 2: [0, 255, 0], 3: [255, 0, 0], 4: [128, 128, 128]}  
    # Colour key
    ground_truth = np.loadtxt(open(csvFile, "rb"), delimiter=',', skiprows=0)
    csv_shape = ground_truth.shape
    imgPlace = np.zeros(shape=(csv_shape[0], csv_shape[1], 3))
    for x in range(0, csv_shape[1]):
        for y in range(0, csv_shape[0]):
            if ground_truth[y][x]==1:
                print()
            color = colorKey.get(ground_truth[y][x])
            imgPlace[y, x, :] = color

    cv2.imshow(filePath, imgPlace)
    cv2.imwrite(filePath, imgPlace)
    cv2.waitKey(0)

    print("csv to img finish 。。。。path:"+filePath)
# 根據自己的類,設定colourkey 值
colourkey = {1: [234, 217, 153], 2: [0, 242, 255], 3:[128, 128, 128]}
csv2Img("imge_lable.csv", colorKey=colourkey,filePath="test.png")
           

6、最終的效果

原始圖像:

Matlab 圖像像素級标注一、Matlab 版本:2020a二、啟動 Image Labeler三、圖像像素級标注

像素标注的圖像:

Matlab 圖像像素級标注一、Matlab 版本:2020a二、啟動 Image Labeler三、圖像像素級标注

繼續閱讀