I want to implement cv.adaptiveThreshold
by cv.blur
, so I write following code:
import cv2 as cv
import numpy as np
src = cv.imread(r"pupil.jpg")
cv.imshow("src", src)
dst = cv.blur(src, (71, 71))
cv.imshow("dst", dst)
delta = src > dst
delta = delta.astype(np.uint8) # convert bool to 0 and 1
delta*=255
cv.imshow("compare", delta)
gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
thresh = cv.adaptiveThreshold(src=gray, maxValue=255, adaptiveMethod=cv.ADAPTIVE_THRESH_MEAN_C,
thresholdType=cv.THRESH_BINARY, blockSize=71, C=0)
cv.imshow("adaptiveThreshold", thresh)
cv.waitKey(0)
But I found these two results are a little diffrent on the edge part:
I guess it is due to the padding, so how to make these two method generate same result ?
Now I can align their result, I just need to change
dst = cv.blur(src, (71, 71))
to
dst = cv.blur(src, (71, 71), borderType=cv.BORDER_REPLICATE|cv.BORDER_ISOLATED)
, but what does cv.BORDER_REPLICATE|cv.BORDER_ISOLATED
mean ? How to understand the bar |
between cv.BORDER_REPLICATE
and cv.BORDER_ISOLATED
?
BORDER_ISOLATED
do not look outside of ROI
BORDER_REPLICATE: The row or column at the very edge of the original is replicated to the extra border.
| it’s a Bitwise operators OR in C++
google is your friend
Actually I know BORDER_REPLICATE
, |
, BORDER_ISOLATED
these three parts individually, I just don’t know what it mean when combine them together. In binary, cv::BORDER_REPLICATE = 1 = 0000 0001, cv::BORDER_ISOLATED = 16 = 0001 0000, apply bitwise OR on them is 0001 0001 = 17, but there is no cv::BorderTypes which equals 17
| both condition are verified