Make sure the texture is a rgb image (not gray one and no alpha channel). Args: img: input texture image Returns: img: ensure the output texture image has size (:,:,3)
(img: T.Union[o3d.geometry.Image, np.ndarray])
| 37 | |
| 38 | |
| 39 | def clean_texture(img: T.Union[o3d.geometry.Image, np.ndarray]) -> T.Union[o3d.geometry.Image, np.ndarray]: |
| 40 | """ |
| 41 | Make sure the texture is a rgb image (not gray one and no alpha channel). |
| 42 | |
| 43 | Args: |
| 44 | img: input texture image |
| 45 | |
| 46 | Returns: |
| 47 | img: ensure the output texture image has size (:,:,3) |
| 48 | """ |
| 49 | img_type = type(img) |
| 50 | # convert to np array |
| 51 | img = np.asarray(img) |
| 52 | assert len(img.shape) == 2 or len(img.shape) == 3, "wrong image size" |
| 53 | |
| 54 | if len(img.shape) == 2: # gray image |
| 55 | img = np.tile(np.expand_dims(img, axis=2), (1, 1, 3)) |
| 56 | elif img.shape[2] == 2: # gray image with alpha |
| 57 | img = np.tile(np.expand_dims(img[:, :, 0], axis=2), (1, 1, 3)) |
| 58 | elif img.shape[2] == 4: # rgb image with alpha |
| 59 | img = img[:, :, :3] |
| 60 | |
| 61 | # need to copy to a new image, or it would cause problem when convert |
| 62 | # to o3d.cpu.pybind.geometry.Image |
| 63 | img1 = copy.deepcopy(img) |
| 64 | |
| 65 | # convert back |
| 66 | if img_type == o3d.geometry.Image: |
| 67 | img1 = o3d.geometry.Image(img1) |
| 68 | return img1 |
| 69 | |
| 70 | |
| 71 | def preprocess_mesh( |