Skip to content

Replace np.resize with np.reshape to avoid silent image corruption #27

@SaFE-APIOpt

Description

@SaFE-APIOpt

output = np.resize((output * 255), (512, 512))

Current code:
output = np.resize((output * 255), (512, 512))

Proposed replacement:
output = (output * 255).reshape(512, 512)
Behavioral difference:

np.reshape only works if the number of elements matches the new shape. If not, it raises an error, making shape mismatches explicit.

np.resize always returns the requested shape, but if the target has more elements, it repeats data; if fewer, it truncates. In image data, this silently produces corrupted results that may still “look” valid.

Performance: reshape is faster and typically returns a view without copying.

Robustness: For images, preserving pixel integrity is critical — silent repetition/truncation from resize can cause serious bugs in downstream tasks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions