python - Project a circle onto a square? -
i have numpy array contains circle.
array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 1., 0., 0., 0., 0.], [ 0., 0., 1., 1., 1., 1., 1., 0., 0.], [ 0., 0., 1., 1., 1., 1., 1., 0., 0.], [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], [ 0., 0., 1., 1., 1., 1., 1., 0., 0.], [ 0., 0., 1., 1., 1., 1., 1., 0., 0.], [ 0., 0., 0., 0., 1., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
this represent gray scale image (ei. it's bigger, , values aren't 1.
). centered in array. how can project circle (stretch somehow?) becomes square without being cropped?
so looks this:
array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
what i'm looking python implementation of conformal transformations, seen in image
you can use maximum , minimum indices of none-zero elements in row , column scope of 1's fill array indices based on scope :
>>> a=np.array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0.], ... [ 0., 0., 0., 0., 1., 0., 0., 0., 0.], ... [ 0., 0., 1., 1., 1., 1., 1., 0., 0.], ... [ 0., 0., 1., 1., 1., 1., 1., 0., 0.], ... [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], ... [ 0., 0., 1., 1., 1., 1., 1., 0., 0.], ... [ 0., 0., 1., 1., 1., 1., 1., 0., 0.], ... [ 0., 0., 0., 0., 1., 0., 0., 0., 0.], ... [ 0., 0., 0., 0., 0., 0., 0., 0., 0.]]) >>> >>> (min_row,max_row),(min_col,max_col)=map(lambda x :(np.min(x),np.max(x)),np.nonzero(a)) >>> a[min_row:max_row+1,min_col:max_col+1]=1 >>> array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], [ 0., 1., 1., 1., 1., 1., 1., 1., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
Comments
Post a Comment