红色绿色和蓝色通道上的扩张和侵蚀,以去除特定结构,然后组合通道以形成rgb图像

时间:2014-07-14 13:40:08

标签: python-2.7 opencv image-processing

我正在使用opencv python中的图像,通过拍摄图像的红色,绿色和蓝色通道从图像中移除血管,然后应用扩张,然后在每个通道上进行侵蚀..当我组合这些通道时我也在图像上得到一个绿色的斑点。任何人请帮我解决为什么我结合3个频道后我的图像上得到这个绿色blob? 这是我的代码:

# imports
import cv2 
from skimage.morphology import erosion, dilation, opening, closing, white_tophat
from skimage.morphology import disk

circle = disk(10)
# =====  blue =====
# import the picture
img_array = cv2.imread('im0006.ppm')
# note that [:,:,0] is blue, [:,:,1] is green, [:,:,2] is red
img_array[:,:,1] = 0
img_array[:,:,2] = 0
# write the image
cv2.imwrite('b.jpg',img_array) #blue channel image

# ===== green =====

img_array = cv2.imread('im0006.ppm') 
img_array[:,:,0] = 0
img_array[:,:,2] = 0
cv2.imwrite('g.jpg', img_array)

# ===== red =====
img_array = cv2.imread('im0006.ppm')
img_array[:,:,0] = 0
img_array[:,:,1] = 0
cv2.imwrite('r.jpg', img_array)

#############operation on blue channel###########
image=cv2.imread('b.jpg')
#cv2.imshow('ero',image)

dilation = cv2.dilate(image,circle,iterations = 1)
eroded = cv2.erode(dilation,circle,iterations = 1)
cv2.imshow('eroded_blue',eroded)

#############operation on green channel###########
image1=cv2.imread('g.jpg')
#cv2.imshow('ero1',image1)
cir = disk(12)
#element = cv2.getStructuringElement(circle,(7,7) )
dilation1 = cv2.dilate(image1,cir,iterations = 1)
eroded1 = cv2.erode(dilation1,cir,iterations = 1)
cv2.imshow('eroded_green',eroded1)
cv2.imwrite('veinless_g.jpg',eroded1)

#############operation on red channel###########
image2=cv2.imread('r.jpg')
#cv2.imshow('ero2',image1)
dilation2 = cv2.dilate(image2,circle,iterations = 1)
eroded2 = cv2.erode(dilation2,circle,iterations = 1)
cv2.imshow('eroded_red',eroded2)

result=eroded+eroded1+eroded2
cv2.imshow('result',result)
cv2.imwrite('result.jpg',result)

cv2.waitKey(0)
cv2.destroyAllWindows()

0 个答案:

没有答案