Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nerfstudio/data/utils/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def pil_to_numpy(im: PILImage) -> np.ndarray:

# Unpack data
e = Image._getencoder(im.mode, "raw", im.mode)
e.setimage(im.im)
e.setimage(im.im, (0, 0) + im.size)

# NumPy buffer for the result
shape, typestr = Image._conv_type_shape(im)
Expand Down
38 changes: 38 additions & 0 deletions tests/utils/test_data_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2026 the Regents of the University of California, Nerfstudio Team and contributors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np
import pytest
from PIL import Image

from nerfstudio.data.utils.data_utils import pil_to_numpy


@pytest.mark.parametrize(
"values",
[
np.array([[1, 2], [3, 4]], dtype=np.uint8),
np.array(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]],
dtype=np.uint8,
),
],
)
def test_pil_to_numpy(values):
image = Image.fromarray(values)

result = pil_to_numpy(image)

np.testing.assert_array_equal(result, values)
assert result.flags.writeable
Loading