Why morphological opening displace my image?

﹥>﹥吖頭↗ 提交于 2021-01-28 05:21:56

问题


I have a picure from a microscope. I want to quantify the number of cellular nucli (blue ovals - see picture original image)

For that I am using Python 2.7 with OpenCV3.

First, I load the image in BGR, and extract the blue layer

import cv2
import numpy as np

img = cv2.imread('image.jpg',1)
img_gray = img[:,:,0]

Next, I produce the BINARY image and then I applied morphological opening, filling and measured contours (see picture: GRAY-after thresholding, OP-n:after opening n times, 'filling holes' and measuring contours.

_, img_thres =  cv2.threshold(img_gray, 40, 255, cv2.THRESH_BINARY)

For iterations=2 see upper panels (OP-2)

kernel = np.ones((2,2),np.uint8)
img_op = cv2.morphologyEx(img_thres, cv2.MORPH_OPEN, kernel, iterations =2)

or

For iterations=20 see bottom panels (OP-20)

img_op = cv2.morphologyEx(img_thres, cv2.MORPH_OPEN, kernel, iterations =20)

For simplicity I am skiping the filling and contours code.

You can see how the contours are shifted, they shift to the right proportionality to the number of iterations during the opening transformation.

Opening should remove background pixels, as it is doing, but not shift the pixels. What is going on?

****EDIT****

didnt verify it, but maybe it's because your kernel is of even size? try an odd kernel size please like 3 or 5. – Micka

You are right! See pictures (both opening iterations=20):

来源:https://stackoverflow.com/questions/43285609/why-morphological-opening-displace-my-image

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!