Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert_color_space should return copy of array #1974

Closed
prathod9 opened this issue Dec 11, 2023 · 4 comments
Closed

convert_color_space should return copy of array #1974

prathod9 opened this issue Dec 11, 2023 · 4 comments

Comments

@prathod9
Copy link

Is your feature request related to a problem? Please describe.
When i use convert_color_space function, for converting YBR_FULL_422 to RGB it modifies the input original array i.e dataset.pixel_array

Describe the solution you'd like
Can it just return a copy ?

@scaramallion
Copy link
Member

scaramallion commented Dec 11, 2023

Re-using the input array occurs by default when you have multiple frames to minimise the memory usage. If you had an input array with lots of frames then by creating a new array of equal size you may exceed your memory limits or result in a large slowdown (which is what happened for a couple of users, so we changed the behaviour). If your input array isn't that large you can pass per_frame=False which should return a new array without modifying the original.

If you're converting only a single frame then a new array is returned. The behaviour is a bit inconsistent and it could be better explained in the documentation.

@prathod9
Copy link
Author

I have frames between 50-100 for my particular work.
I am passing per_frame=True
The problem is when i do id(original_array) and id (new_array)
It returns same id.
Which is what got me confused as it is not supposed to modify the original array.

This is quite unexpected

@scaramallion
Copy link
Member

scaramallion commented Dec 12, 2023

Why is it not supposed to modify the original array? You mean because the id is the same? The input object is the same object returned when per_frame=True, just with different values (but the same dtype).

Also, as an aside, in CPython id is the memory address of the array. And it's definitely possible (I have seen it happen) that when an ndarray goes out of scope the memory can be reused if the replacement array has the same/smaller shape and dtype and therefore has the same id even though its a new object.

@prathod9
Copy link
Author

We can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants