Convert any array to an RGBA array. RGBA arrays have 3 dimensions where the last represents the channels. If an Alpha channel needs to be added it will be made completely opaque. Returns ------- 3D RGBA unsigned 8-bit array
(data_in: ArrayLike)
| 61 | |
| 62 | |
| 63 | def make_rgba(data_in: ArrayLike) -> ArrayLike: |
| 64 | """Convert any array to an RGBA array. |
| 65 | |
| 66 | RGBA arrays have 3 dimensions where the last represents the channels. If |
| 67 | an Alpha channel needs to be added it will be made completely opaque. |
| 68 | |
| 69 | Returns |
| 70 | ------- |
| 71 | 3D RGBA unsigned 8-bit array |
| 72 | |
| 73 | """ |
| 74 | max_val = max_for_dtype(data_in.dtype) |
| 75 | if data_in.ndim == 3 and data_in.shape[-1] == 1: |
| 76 | data_in = data_in.squeeze() |
| 77 | |
| 78 | if data_in.ndim == 2: |
| 79 | out = np.stack([data_in] * 4, axis=2) |
| 80 | out[:, :, 3] = max_val |
| 81 | elif data_in.shape[-1] == 3: |
| 82 | out = np.concatenate((data_in, np.ones((*data_in.shape[:2], 1)) * max_val), axis=2) |
| 83 | else: |
| 84 | out = data_in |
| 85 | return np.round((out.astype(np.float32) * 255 / max_val)).astype(np.uint8) |
no test coverage detected
searching dependent graphs…