-
Notifications
You must be signed in to change notification settings - Fork 22
Conversation
@@ -7,6 +7,7 @@ | |||
import random | |||
import string | |||
import tempfile | |||
import numpy as np |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We definitely don't want a hard dependency on numpy. Can we use a regular array for now, and we'll figure out a good general API to support numpy (hopefully w/o copying data to Python land first) later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I normally use numpy, so I have very little experience with the regular array. As long as you can write to a normal uint16
array from an iterator numpy isn't needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yah, I just meant a normal Python array. It won't be very efficient, but I've also opened an issue (#106) for discussing the best way to handle numpy support, which is something we want to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
II understand. Can you read from an iterator into such an array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, that should be fine. You won't be able to use the numpy methods to do it though; just regular iteration will work fine.
I've removed the numpy dependency and changed the error handling |
|
||
try: | ||
rawdata.color4_image.contents | ||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this makes sense, thanks! Let's catch the actual exception here though; bare excepts can have unintended side effects :)
) | ||
|
||
# make 2D list | ||
data = [[0 for i in range(iheight)] for j in range(iwidth)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be cleaner, no idea if there's a "standard" way to do this in Python:
data = [None] * iheight * iwidth
It might be a pre-mature optimization either way though. Or I may be completely wrong. Just thinking out loud. @campaul?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs to be 2D, or you'll have to pass height and width on, and let the calling function do the reshape.
From what I understood, list compression is the normal way of initialising this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good then. I think the above will make a 2d list too, but I could be mistaken. If we're going to have to iterate anyways though I think we might as well not preallocate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick quick test gives it as a 1D.
As for the preallocate, I like it due to the large lists being created, though I don't know what is fastest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to loop and append, 0's though we might as well just loop and append the data. I'm not sure this is actually an optimization, unless Python does some sort of optimization on simple list comprehensions that I don't know about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would probably be more efficient. I'll do some timings later and see for sure.
data = [[] for j in range(iwidth)]
for ii in range(iheight):
for jj in range(iwidth):
data[jj].append(data_pointer[ii * iwidth + jj])
|
||
for ii in range(iheight): | ||
for jj in range(iwidth): | ||
data[jj][ii] = data_pointer[ii * iwidth + jj] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still appears to be subscripting a 2D array; won't this be broken?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my test run this works as intended.
Though I'm not sure what you think would be broken?
Line 221 makes a 2D list, which one can index with [][] in line 225
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, yah, I was misunderstanding a large chunk of our discussion, sorry. I think it's best to make this a 1D list to match the data that we get from LibRaw / elsewhere in rawkit. Not sure though; will consider the API implications of doing this and get back to you. It's not super important right now.
# make 2D list | ||
data = [[0 for i in range(iheight)] for j in range(iwidth)] | ||
|
||
for ii in range(iheight): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change ii
and jj
to y
and x
respectively so we're working with Cartesian coordinates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't actually coordinates on the image though since there are multiple indexes per pixel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They will be coordinates, though you have to interpolate the image first, as in that loop they change between different colour channels.
@paalge if you go ahead and add a We'll be making some changes to the interface as time goes on, but I want to get the core functionality merged in so I can start playing with it. |
@campaul I've now added the requested method. I also fixed a lot of error in the original code. The returned image is the image excluding the calibration pixels (it could be possible to switch between this in an input flag). I've only tested the code one three types of images (ARW, NEF and three colour CR2). The three colour image is strange, as it includes a zero pixel. |
In general the code looks good, but the two functions are almost identical. Can you extract the shared code into a helper function so we aren't duplicating everything? |
I'm sorry for the late update. I've now moved the common code into a new function, though I'm unsure of how much better it is with respect to readability, as there where some subtle differences in the code. |
Oops, I didn't see the email from github for your last comment. I had already taken your commits and made the changes I wanted, as well as updated the tests, in #108. Could you take a look at that branch and let me know if you're still ok with how the code looks? If you're happy with things I'll merge that branch in and we should be good to go. |
This was included as part of #108. |
This is a method for exposing the raw data as a numpy array.
Not sure if this is exactly the way you want to do it, but it looks like it is working for me
Fixes #47