python - Why morphological opening displace my image? -
i have picure microscope. want quantify number of cellular nucli (blue ovals - see picture original image)
for using python 2.7 opencv3.
first, load image in bgr, , extract blue layer
import cv2 import numpy np img = cv2.imread('image.jpg',1) img_gray = img[:,:,0] next, produce binary image , applied morphological opening, filling , measured contours (see picture: gray-after thresholding, op-n:after opening n times, 'filling holes' , 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 skiping filling , contours code.
you can see how contours shifted, shift right proportionality number of iterations during opening transformation.
opening should remove background pixels, doing, not shift pixels. going on? 
****edit****
didnt verify it, maybe it's because kernel of size? try odd kernel size please 3 or 5. – micka
you right! see pictures (both opening iterations=20):

Comments
Post a Comment