語義分割標注labelme圖片處理過程


 

過程(前提是labelme已經安裝好)

1在終端輸入:

2點擊左側Open Dir選擇需要標注的數據文件夾

3制作圖像分割的數據,選擇多邊形,點擊左側的 create polygons ,回到圖片,按下鼠標左鍵會生成一個點,完成標注后會形成一個標注區域,同時彈出labelme的框,鍵入標簽名字,點擊 OK或者回車完成標注。

 

4標注完成后,點擊save保存成同名的.json文件,然后在終端輸入以下語句(具體來說,在激活labelme的環境下,進入labelme_json_to_dataset.exe所在文件夾,將需要操作的json文件都放入該路徑下,然后輸入python labelme_json_to_dataset.exe 文件名.json,就OK了。):

  會生成json文件夾,里面有五個文件,其中label.png和info.yaml使我們需要的

5圖片變化的過程:

 

 

 merge.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import cv2
import gdal

input_file_path = "mayd.tif"
output_file_path = "mayd_new.png"

dataset = gdal.Open(input_file_path)

im_width = dataset.RasterXSize
im_height = dataset.RasterYSize
im_bands = dataset.RasterCount

im = dataset.ReadAsArray(0,0,im_width,im_height)

print("before merge:",im.shape)

b = im[0,:,:]
g = im[1,:,:]
r = im[2,:,:]

merged = cv2.merge([b,g,r])

print("after merge:",merged.shape)

cv2.imwrite(output_file_path,merged)

whi_bla.py文件

#!/usr/bin/env python3
# -*- coding: utf-8 -*-


import cv2
import numpy as np

def whi_bla(color,img):
    print(img.shape)
    img_ = np.zeros([img.shape[0],img.shape[1]])
    for i in range(img.shape[0]):
        for j in range(img.shape[1]):
            if img[i,j,0]==color[0] and img[i,j,1]==color[1] and img[i,j,2]==color[2]:
                img_[i,j]=255
            else:
                img_[i,j]=0
        print(i,' is ok')
    return img_

if __name__=="__main__":
    img = cv2.imread("label7.png")
    print(img.shape)
    color = [0,0,128]                 #根據具體的圖像設置color的值,bgr
    img_ = whi_bla(color,img)
    print(img_.shape)
    cv2.imwrite("7_0.png",img_)

 

為了防止自己再次忘記,所以把過程寫下來,我寫的這個是按着自己的情況來的,僅供參考,不具有普遍性。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM