| 7 | MAX_DEPTH = 50 # Unit: meter |
| 8 | |
| 9 | def depth2disp(normalized_dep,min_depth=MIN_DEPTH,max_depth=MAX_DEPTH): |
| 10 | assert normalized_dep.max() <= 1.0, 'depth array should be normalized into the range of 0~1' |
| 11 | # min disparity = 0 when depth > MAX_DEPTH |
| 12 | # max disparity = 1 when depth < MIN_DEPTH |
| 13 | |
| 14 | # Convert Depth to true-scale |
| 15 | truescale_dep = max_depth * normalized_dep.astype('float32') # unit: meter |
| 16 | clipped_truescale_dep = np.clip(truescale_dep,a_min=min_depth,a_max=max_depth) |
| 17 | clipped_normalized_dep = clipped_truescale_dep/max_depth # range MIN_DEPTH/MAX_DEPTH ~ 1 |
| 18 | disp = 1/(clipped_normalized_dep) # range 1 ~ MAX_DEPTH/MIN_DEPTH |
| 19 | norm_disp = (MIN_DEPTH/MAX_DEPTH) * disp # range MIN_DEPTH/MAX_DEPTH ~ 1 |
| 20 | |
| 21 | return norm_disp |
| 22 | |
| 23 | # Load PNG Depth image (Max depth=50M when val=255, Min depth=0M when val=0) |
| 24 | normalized_dep = Image.open('../../Dataset/Mapping/StorageHouse/Room_1/Seq_0/depth/326.png') |