markdown
#說明
這部分是因為要將圖片投入深度學習,預先做影像處理,把不需要的雜訊去除,這邊是用mammography 的影像當作範例,因為觀察這類型的影像,經常會用白色的字體寫上擺位的英文字,所以要將這樣的英文字去除
#操作流程
##原始圖片
- 參考 :https://www.jmir.org/2019/7/e14464/
引用網站上這類型的影像檔案,取出其中一張的影像,如下圖
##Code
```
import os
import numpy as np
import cv2
num_files = 0
imgList = []
path='./old/'
OutputPath='./new/'
def cv_imread(filePath):
cv_img=cv2.imdecode(np.fromfile(filePath,dtype=np.uint8),-1)
return cv_img
for imgList in os.listdir(path):
img_path = str((path + '/' + imgList))
img = cv_imread(img_path)
row = img.shape[0] - 1
col = int(img.shape[1] - 1)
img_left = img[1:row, 1:int(col /2) ]
img_right = img[1:row, int(col /2):col]
if img_left.sum() > img_right.sum():
img_right = img[1:row, int(col*2/3):col]
for i in range(img_right.shape[0]-1):
for j in range(img_right.shape[1]-1):
if (img_right[i][j][1]) >= 200:
cv2.circle(img, (j+int(col*2/3), i), 5, (0, 0, 0), -1)
New_img_Name=OutputPath+str(imgList)
cv2.imwrite(New_img_Name, img)
else:
img_left = img[1:row, 1:int(col * 1 / 3)]
for i in range(img_left.shape[0]-1):
for j in range(img_left.shape[1]-1):
if (img_left[i][j][1]) >= 200:
cv2.circle(img, (j, i), 10, (0, 0, 0), -1)
New_img_Name=OutputPath+str(imgList)
cv2.imwrite(New_img_Name, img)
print("finish")
```
##DEMO
留言
張貼留言