"""Image raw statistics. Threshold profiles and content acceptance belong to consumers.""" import numpy as np def image_statistics(rgb,depth,previous): valid=np.isfinite(depth)&(depth>0);h,w=depth.shape center=depth[h//3:2*h//3,w//3:2*w//3];cv=np.isfinite(center)&(center>0) luma=rgb.astype(np.float32)@np.array([.2126,.7152,.0722],np.float32) if previous is not None: difference=np.subtract(rgb,previous,dtype=np.int16) np.abs(difference,out=difference) mad=float(difference.mean()) else:mad=np.nan return dict(luma_mean=float(luma.mean()),luma_std=float(luma.std()), previous_frame_mad=mad, invalid_depth_fraction=float(1-valid.mean()),min_valid_depth_m=float(depth[valid].min()) if valid.any() else np.nan, center_depth_median_m=float(np.median(center[cv])) if cv.any() else np.nan, **{'near_fraction_'+str(d).replace('.','_')+'m':float((valid&(depth