python - Get Laplacian pyramid using opencv -
i'm trying layer of laplacian pyramid using opencv functions: pyrup
, pyrdown
.
in documentation , in more detail in book, found i-th laplacian layer should obtained following expression:
li = gi - pyrdown(gi+1)
where gi i-th layer of gaussian pyramid.
what i've tried is:
def get_laplacian_pyramid_layer(img, n): gi = img in range(n): gi_prev = gi gi = cv2.pyrdown(gi_prev) pyrup = cv2.pyrup(gi) return cv2.addweighted(gi_prev, 1.5, pyrup, -0.5, 0)
but different sizes of images involved in substraction. don't understand because pyrup
suppposed invert process of gaussian pyramid, i.e. pyrdown (with lose of information of course should not affect size, right?).
update
i refactored code to:
def get_laplacian_pyramid_layer(img, n): '''returns n-th layer of laplacian pyramid''' currimg, = img, 0 while < n: # , currimg.size > max_level (83) down, = new_empty_img(img.shape), new_empty_img(img.shape) down = cv2.pyrdown(img) = cv2.pyrup(down, dstsize=currimg.shape) lap = currimg - currimg = down += 1 return lap
as can see, force destination image of same size of source parameter dstsize
of pyrup
function.
however, code gives me error when when executing pyrup
function. message of error is:
opencv error: assertion failed (std::abs(dsize.width - ssize.width*2) == dsize.width % 2 && std::abs(dsize.height - ssize.height*2) == dsize.height % 2) in pyrup_,
in debug mode checked expression of assertion with:
up.shape[1]-down.shape[1]*2 == up.shape[1] %2 , up.shape[0]-down.shape[0]*2 == up.shape[0] %2
and satisfied.
so, don't have clue of happening.
as far can see use pyrdown on input image img in every iteration
down = cv2.pyrdown(img)
i suggest change line to
down = cv2.pyrdown(currimg)
so compute next pyramid layer.
the reason error down image. shape width/2 x height/2 compared input image
down = cv2.pyrdown(img)
yet try store pyrup result (width * height) in smaller image shape beeing smaller (width/2 x height/2) due
up = cv2.pyrup(down, dstsize=currimg.shape) ... currimg = down
even if answer late, maybe else
Comments
Post a Comment