Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can i know if there are white pixels in a binary image in some coordinates (stored in a list) in python?
    primarykey
    data
    text
    <p>I have a <a href="http://i.imgur.com/grnpDpP.jpg" rel="nofollow">numpy array binary</a> (black and white) image and coordinates in a list of tuples like:</p> <pre><code>coordlist =[(110, 110), (110, 111), (110, 112), (110, 113), (110, 114), (110, 115), (110, 116), (110, 117), (110, 118), (110, 119), (110, 120), (100, 110), (101, 111), (102, 112), (103, 113), (104, 114), (105, 115), (106, 116), (107, 117), (108, 118), (109, 119), (110, 120)] </code></pre> <p>or as:</p> <pre><code>coordx = [110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110] coordy = [110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120] </code></pre> <p>How can i check if there is a "white" pixel in the image with that coordinates list? I also would like check the white pixels that are around 3 pixels range far from that coordinates list.</p> <p>i.e.:</p> <pre><code>for i, j in coordx, coordy: for k in a range (k-3, k + 3) for l in a range (l-3, l + 3) #checking white pixels also for pixel near coordinates list </code></pre> <p>I thought about "where" function.</p> <pre><code>from skimage import morphology import numpy as np path = 'image/a.jpg' col = mh.imread(path) bn0 = col[:,:,0] bn = (bn0 &lt; 127) bnsk = morphology.skeletonize(bn) bnskInt = np.array(bnsk, dtype=np.uint8) #finding if there are white pixel in the coord list and around that in a 5 pixel range for i in coordlist: np.where(?) </code></pre> <p><strong>UPDATE</strong>.</p> <p>I tried to use shape (128, 128) instead of (128, 128, 3) because my image have this shape: (a,b) but now it does not find the white pixels! Why in this way does it find anything?</p> <pre><code> white_pixel = np.array([255, 255]) img = np.random.randint(0, 256, (128, 128)) print(img[150]) print(img.shape) img[110, 110] = 255 img[109, 110] = 255 mask = np.zeros((128, 128), dtype=bool) mask[coordx, coordy] = 1 #structure = np.ones((3, 3, 1)) #mask = scipy.ndimage.morphology.binary_dilation(mask, structure) is_white = np.all((img * mask) == white_pixel, axis=-1) # This will tell you which pixels are white print np.where(is_white) # This will tell you if any pixels are white print np.any(is_white) </code></pre> <p>output:</p> <pre><code>(array([], dtype=int32),) False </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload