复合分层区域的图像分割

时间:2019-08-29 22:05:45

标签: python opencv image-segmentation

研究项目的一部分是正确地测量钻孔的分层区域,如图所示。 DRILLED HOLE

要实现此目的,我需要设法开发一种图像分割算法/方法,以识别孔周围分层区域的轮廓,以便获得与下图类似的结果。

EXPECTED RESULT

基于本文的图片-> Paper

分层区域的附加图像。 Delamination damaged area

我正在使用python和openCV进行图像处理任务。到目前为止,我已经在灰度图像和单独的HSV通道中尝试了几种方法,例如阈值(THRESH_BINARY,THRESH_OTSU,计算图片的平均像素值,然后应用阈值...)。我也尝试过cv2.equalizeHist(gray),但是这些方法似乎只能分割出轮廓复杂的孔复合工件(希望获得孔直径),但是我们主要需要计算损坏面积。

对此图像进行良好的分层损伤分割的最佳方法是什么?

### IMAGES ARE RESIZED FOR BETTER VISUALIZATION IN SCREEN, BUT IMAGE PROCESSING OPERATIONS ARE DONE WITH NORMAL SIZE PICTURES ###

import numpy as np
import cv2
import matplotlib.pyplot as plt

img = cv2.imread('2.jpg')
imageRe = cv2.resize(img,None,fx=0.6,fy=0.6)
cv2.imshow('Hole Imported Picture.', imageRe)

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

#histogram calculation GRAY SCALED IMAGE
hist = cv2.calcHist([gray],[0],None,[256],[0,256])
plt.hist(gray.ravel(),256,[0,256]); plt.show()


imageRe = cv2.resize(gray,None,fx=0.6,fy=0.6)
cv2.imshow('Gray scale image.', imageRe)


ecualized_img = cv2.equalizeHist(gray)
cv2.imwrite('ecualized_img.jpg', ecualized_img)
imageRe = cv2.resize(ecualized_img,None,fx=0.6,fy=0.6)
cv2.imshow('Ecualized image.', imageRe)

##################
img = gray
# global thresholding
ret1,th1 = cv2.threshold(img,70,255,cv2.THRESH_BINARY)  #Threshold set in 127 by default
# Otsu's thresholding
ret2,th2 = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
# Otsu's thresholding after Gaussian filtering
blur = cv2.GaussianBlur(img,(5,5),0)
ret3,th3 = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
# plot all the images and their histograms
images = [img, 0, th1,
          img, 0, th2,
          blur, 0, th3]
titles = ['Original Noisy Image','Histogram','Global Thresholding (v=127)',
          'Original Noisy Image','Histogram',"Otsu's Thresholding",
          'Gaussian filtered Image','Histogram',"Otsu's Thresholding"]

imageRe = cv2.resize(th1,None,fx=0.6,fy=0.6)
cv2.imshow('Normal Thresholding image.', imageRe)

imageRe = cv2.resize(th2,None,fx=0.6,fy=0.6)
cv2.imshow('Otsus Thresholding image.', imageRe)


for i in range(3):
    plt.subplot(3,3,i*3+1),plt.imshow(images[i*3],'gray')
    plt.title(titles[i*3]), plt.xticks([]), plt.yticks([])
    plt.subplot(3,3,i*3+2),plt.hist(images[i*3].ravel(),256)
    plt.title(titles[i*3+1]), plt.xticks([]), plt.yticks([])
    plt.subplot(3,3,i*3+3),plt.imshow(images[i*3+2],'gray')
    plt.title(titles[i*3+2]), plt.xticks([]), plt.yticks([])
plt.show()
###################

src = img
ddepth = cv2.CV_16S
kernel_size = 3

ecualized_img = cv2.GaussianBlur(ecualized_img, (3, 3), 0)
    # [reduce_noise]
    # Convert the image to grayscale
#src_gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
    # [convert_to_gray]
    # [laplacian]
    # Apply Laplace function
dst = cv2.Laplacian(ecualized_img, ddepth, ksize=3)
    # [laplacian]
    # [convert]
    # converting back to uint8
abs_dst = cv2.convertScaleAbs(dst)
    # [convert]
    # [display]
imageRe = cv2.resize(abs_dst,None,fx=0.6,fy=0.6)
cv2.imshow('Laplacian of Gaussian (LoG)', imageRe)

#retVal, t = cv2.threshold(ecualized_img, 90, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
#t = cv2.threshold( ecualized_img, 0, 255, cv2.THRESH_OTSU );
#imageRe = cv2.resize(t,None,fx=0.6,fy=0.6)
#cv2.imshow('Ecualized + THRESH_OTSU image.', imageRe)




cv2.waitKey(0)
cv2.destroyAllWindows()

0 个答案:

没有答案