I am new to image manipulation in python and would appreciate some advice on 2 problems.
I have an image: and its mask:
and open it as follows:
import cv2
import matplotlib.pyplot as plt
mask = cv2.imread('img_mask.jpg')
img = cv2.imread('img.jpg')
1) I have the following (x,y) pixel locations:
pt1 = 43.35, 22.49
pt2 = 49.035, 46.985
pt3 = 18.326, 21.822
On the mask, the pixel value at pt1
and pt2
is 0
and at pt3
it is 16
. Given the three (x,y) pixel locations as a list, as well as the mask, as provided. How can I efficiently filter the locations whose value is 0
on the mask ?
2) How can I efficiently create a new thresholded masked image
, then overlay it on the original image, such that the thresholded mask image
is an image where the mask only has a value of 16 as obtained from pixel locations in the original mask where the values are 16.