python坐标轴拉伸_Numpy,Python中的“拉伸”直⽅图(级别)这是⼀种⽅法-
服务格言def stretch(a,lower_thresh,upper_thresh):
r = 255.0/(upper_thresh-lower_thresh+2) # unit of stretching
out = np.round(r*(a-lower_thresh+1)).astype(a.dtype) # stretched values
out[a
out[a>upper_thresh] = 255
return out
根据OP,设置的标准是:
>将246以上的每个像素“移动”到255,因此247及以上的像素应变为255.加速英文
> 186以下的每个像素都为零,因此185以下的像素应变为0.
凤凰神兽>因此,基于上述两个要求,186应该变为⼤于0的值,依此类推,直到246应该⼩于255.
施罗德
另外,我们也可以使⽤np.where使它更紧凑-
def stretch(a,upper_thresh):
抱团打天下r = 255.0/(upper_thresh-lower_thresh+2) # unit of stretching
out = np.round(r*np.where(a>=lower_thresh,a-lower_thresh+1,0)).clip(max=255)
溢价发行债券
return out.astype(a.dtype)
样品运⾏-
# check out first row input,output for variations
In [216]: a
陈嘉庚子女Out[216]:
array([[186,187,188,246,247],[251,195,103,9,211],[ 21,242,36,87,70]],dtype=uint8)
In [217]: stretch(a,lower_thresh=186,upper_thresh=246)
晕车穴位
Out[217]:
array([[ 4,8,12,251,255],[255,41,107],[ 0,234,0]],dtype=uint8)