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

ndarray from image ? #2

Closed
iabdalkader opened this issue Oct 29, 2019 · 7 comments
Closed

ndarray from image ? #2

iabdalkader opened this issue Oct 29, 2019 · 7 comments
Assignees
Labels
enhancement New feature or request question Further information is requested
Milestone

Comments

@iabdalkader
Copy link

How can I create an ndarray of shape (w, h, c) from a C array of pixels (uint8_t) ? I can create 1D arrays by implementing getiter and unary_op, do I need to return an iter as the items of the first iter and so on ?

@v923z
Copy link
Owner

v923z commented Oct 29, 2019

Sorry, I don't understand the question: you don't have to implement anything, if the array is one-, or two-dimensional. Do you want to have a three-dimensional array?
The title of your question indicates that you want to work with images. But those are just 2D objects. It is a different matter, whether there are facilities to read your particular format into a matrix, and there might not be. I am not sure I see what the goal is. Can you elaborate?

@v923z v923z added the question Further information is requested label Oct 29, 2019
@iabdalkader
Copy link
Author

Hi, the image array is one dimensional but in numpy, opencv etc.. it's typically loaded as a three-dimensional array (height, width, depth), the third dimension is the depth/channels (RGB), for example:

import cv2
im = cv2.imread("test.png")
print(im.shape)
>>> (300, 300, 3)

Is there a way to achieve this with ulab ?

@v923z
Copy link
Owner

v923z commented Oct 29, 2019

The short answer is no. The slightly longer one is it is not trivial at all. Third, you also have to read the image itself. I mean the imread function. That is not trivial either, given that somehow you have to fit the png library onto the microcontroller. But if you implement that, you could easily return a 3-tuple with three two-dimensional ndarrays, each holding the data for one colour channel.

One more comment: as opposed to numpy, I tried to implement everything with minimal RAM overhead. That means that there are no auxiliary data holders. The downside of that is that tensor operations can't be scaled to arbitrary dimensions, you can't just say that a two-dimensional array is simply a bunch of one-dimensional arrays, and then you loop over them. That is not gonna work.

@iabdalkader
Copy link
Author

We do have some image loading functions, not png specifically but other formats, and we may have SDRAM on board at some point. Anyway thanks for the answers, and for this great library. I think I got my answer so I'll close this issue now.

@v923z
Copy link
Owner

v923z commented Dec 6, 2019

I am re-opening the issue, because I am working on an upgrade for ulab that would support images. In particular, the ndim branch has a skeleton implementation of arbitrary tensor ranks. The branch is not yet complete, but I think I should be done in a matter of weeks. I just wanted to indicate that this is really in the pipeline.

@v923z v923z reopened this Dec 6, 2019
@v923z v923z added the enhancement New feature or request label Dec 6, 2019
@iabdalkader
Copy link
Author

Awesome! Please let me know when it's ready and I'll help test it, thanks!

@v923z
Copy link
Owner

v923z commented Dec 8, 2019

Awesome! Please let me know when it's ready and I'll help test it, thanks!

Help with testing would be fantastic. I assign you to this issue, then.

jepler added a commit to jepler/circuitpython-ulab that referenced this issue Feb 6, 2020
ulab.rst: Fix so it can be processed by sphinx in circuitpython
@v923z v923z added this to the 1.0 milestone Sep 21, 2020
@v923z v923z closed this as completed Jan 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants