image arithmetic - lesson 5 of Harrisons openCV tut

by: skypickle, 9 years ago


I tried to reproduce harrison's example in lesson 5 using a different mask. Instead of the python logo I used this image

http://s16.postimg.org/kpumk9v85/helloo.png


import cv2
import numpy as np

# Load two images
img1 = cv2.imread('3D-Matplotlib.png')
img3 = cv2.imread('helloo.png')

#select the ROI
rows3,cols3,channels3 = img3.shape
roi3 = img1[50:rows3+50, 50:cols3+50 ]
print(rows3,cols3)

img3gray = cv2.cvtColor(img3,cv2.COLOR_BGR2GRAY)

ret3, mask3 = cv2.threshold(img3gray, 220, 255, cv2.THRESH_BINARY_INV)
cv2.imshow('m3', mask3)
mask_inv3 = cv2.bitwise_not(mask3)

img3_bg = cv2.bitwise_and(roi3,roi3,mask = mask_inv3)
img3_fg = cv2.bitwise_and(img3,img3,mask = mask3)

dst3 = cv2.add(img3_bg,img3_fg)
img1[50:rows3+50, 50:cols3+50 ] = dst3

cv2.imshow('i',mask_inv3)
cv2.imshow('1',img3_bg)
cv2.imshow('2',img3_fg)
cv2.imshow('d',dst3)
cv2.imshow('r1',img1)


cv2.waitKey(0)
cv2.destroyAllWindows()


I get colorful antialiasing around the boundaries of the outline. It's most clearly seen in the variable named, img3_fg , which is the result of the bitwise_and of the png to be used as a mask and the actual mask of that png.

  Why?





You must be logged in to post. Please login or register an account.



Because your image has colorful antialiasing around the boundaries of the outline :P. Open your image up in the browser and zoom in, or open in some other image editing software and zoom in.

edit: actually, the plot really thickens... since you're thresholding. I really don't know to be honest. Shouldn't be there, but maybe it does have something to do with the original image having it?

-Harrison 9 years ago
Last edited 9 years ago

You must be logged in to post. Please login or register an account.


Indeed! you are correct. I simply used the word 'Helloo' typed into a drawing and saved into a .png. The computer antialiased the black text with colorful edges!

-skypickle 9 years ago

You must be logged in to post. Please login or register an account.