In [1]:
import numpy as np
def rectangle(s, r, c):
rows, cols = s[0], s[1]
rrows, rcols = r[0], r[1]
rr0, cc0 = c[0], c[1]
rr, cc = np.meshgrid(np.arange(rows), np.arange(cols), indexing='ij')
min_row, max_row = rr0-rrows//2, rr0+rrows//2
min_col, max_col = cc0-rcols//2, cc0+rcols//2
g1 = (min_row <= rr) & (max_row > rr)
g2 = (min_col <= cc) & (max_col > cc)
g = g1 & g2
return g
In [1]:
testing = (__name__ == "__main__")
if testing:
! jupyter nbconvert --to python rectangle.ipynb
import numpy as np
import sys,os
ia898path = os.path.abspath('../../')
if ia898path not in sys.path:
sys.path.append(ia898path)
import ia898.src as ia
In [2]:
if testing:
F = ia.rectangle([7,9], [3,2], [3,4])
print(F)
In [3]:
if testing:
F = ia.rectangle([200,300], [90,120], [70,120])
ia.adshow(ia.normalize(F))