Segment image and highlight object border using python

0

I'm testing some algorithms to improve the image quality my hardware is getting. I have a vane in the image and would like to highlight the object contained in it.

Iusedthecodebelowtodotheequalizationoftheimage,butIdidnotsucceed.

importcv2importnumpyasnpdefhistogram_equalize(img):b,g,r=cv2.split(img)red=cv2.equalizeHist(r)green=cv2.equalizeHist(g)blue=cv2.equalizeHist(b)returncv2.merge((blue,green,red))img=cv2.imread('pos20.jpg')img_yuv=cv2.cvtColor(img,cv2.COLOR_BGR2YUV)#equalizethehistogramoftheYchannelimg_yuv[:,:,0]=cv2.equalizeHist(img_yuv[:,:,0])#converttheYUVimagebacktoRGBformatimg_output=cv2.cvtColor(img_yuv,cv2.COLOR_YUV2BGR)cv2.imshow('Colorinputimage',img)cv2.imshow('Histogramequalized',img_output)cv2.imwrite('20.jpg',img_output)cv2.waitKey(0)

Outputresult:

What is the best algorithm to improve image quality and highlight the edge of the object?

    
asked by anonymous 08.06.2017 / 21:08

1 answer

2

Really this image "is bone", and your question even more, :-), but perhaps applying something more related to segmentation, you can have better results.

import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('img1.jpg',0)
ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
ret,thresh2 = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)
ret,thresh3 = cv2.threshold(img,127,255,cv2.THRESH_TRUNC)
ret,thresh4 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO)
ret,thresh5 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO_INV)
titles = ['Original Image','BINARY','BINARY_INV','TRUNC','TOZERO','TOZERO_INV']
images = [img, thresh1, thresh2, thresh3, thresh4, thresh5]
for i in xrange(6):
    plt.subplot(2,3,i+1),plt.imshow(images[i],'gray')
    plt.title(titles[i])
    plt.xticks([]),plt.yticks([])
plt.show()

    
09.06.2017 / 16:15