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

AreaDetector_Display not showing image (16bit data) #14

Open
zunbeltz opened this issue Jun 10, 2015 · 4 comments
Open

AreaDetector_Display not showing image (16bit data) #14

zunbeltz opened this issue Jun 10, 2015 · 4 comments

Comments

@zunbeltz
Copy link

Dear Matt,

I would like to customise the AreaDetector application to do some image processing "on the fly."
At the moment the application connects to the camera and the "acquisition start/stop" works properly.
Unfortunately the image is not show in the frame (just black).
I looked to the code and I think that this is due to the fact that my raw data is of type uint16 and mono.
In this case ad_display.py lines 866--876, sets im_mode to 'I' and convert to uint32.
But in the DataToImage method I couldn't find the code lines that convert the data to an image.
As far as I understand from the documentation neither the python Image library 'image.frombuffernor 'wx.ImageFromData support this kind of data. Am I correct?
Does this mean that the only way to go is to scale down the rawdata to uint8? or is there other ways to plot the uint16 data?

Thanks

ps. I used some print statement, so the line numbers above may be a bit shifted.

@newville
Copy link
Member

@zunbeltz Hmm, I'm not completely sure. It turns out that I've been playing with the AreaDetector image display code, and trying to update it. So, I'll try to look into this over the next couple days...
I suspect that what may be needed is approximately

        # default mode and size
        im_mode = 'L'
        im_size = (arrsize[0], arrsize[1])
        dsize = arrsize[0]*arrsize[1]
        if colormode == 2:     # color image
            im_mode = 'RGB'
            im_size = (arrsize[1], arrsize[2])
            dsize *= arrsize[2]

        rawdata = ad_img.PV('ArrayData').get(count=dsize)
        if (colormode == 0 and isinstance(rawdata, np.ndarray) and 
           rawdata.dtype != np.uint8):
            im_mode = 'I'
            rawdata = rawdata.astype(np.uint32)
        if im_mode in ('L', 'I'):
            wximage = wx.EmptyImage(width, height)
            imbuff = Image.frombuffer(im_mode, im_size, rawdata,
                                      'raw', im_mode, 0, 1)
            wximage.SetData(imbuff.convert('RGB').tostring())
        elif im_mode == 'RGB':
            rawdata = rawdata.astype(np.uint32)
            rawdata.shape = (3, width, height)
            wximage = wx.ImageFromData(width, height, rawdata)
        wximage = wximage.Scale(int(scale*width), int(scale*height))

but that is not actually tested. Again, I'll try this out over the next couple days....

@zunbeltz
Copy link
Author

@newville Just updating to the last commits has solved the problem here.
Thanks.

@newville
Copy link
Member

@zunbeltz -- Glad it works! Can you clarify whether you mean the most recent version of the code works, or was the code snippet I posted needed?

@zunbeltz
Copy link
Author

I made a new clone of the project which includes commits from yesterday. I
did not need to ise the code snippet.
El 11/06/2015 14:08, "Matt Newville" notifications@github.com escribió:

@zunbeltz https://github.com/zunbeltz -- Glad it works! Can you clarify
whether you mean the most recent version of the code works, or was the code
snippet I posted needed?


Reply to this email directly or view it on GitHub
#14 (comment).

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

No branches or pull requests

2 participants