EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: [Scopes] BMP image record??
From: Mark Rivers <[email protected]>
To: Pavel Masloff <[email protected]>, Matt Newville <[email protected]>
Cc: EPICS Tech Talk <[email protected]>
Date: Tue, 1 May 2012 12:12:10 +0000
The intensity widget only supports monochrome, with color lookup tables within BOY.  It does not support true color, i.e. RGB images or images with their own color maps.

Hopefully it will be added in the future, because we would like to use BOY with color cameras.

There is an ImageJ plugin in the EPICS areaDetector package that does support both true color and monochrome images in waveform records.

Mark

________________________________
From: [email protected] [[email protected]] on behalf of Pavel Masloff [[email protected]]
Sent: Tuesday, May 01, 2012 1:57 AM
To: Matt Newville
Cc: EPICS Tech Talk
Subject: Re: [Scopes] BMP image record??

Alright!
Cancel my last message!

I should have used gif files when I tried bmps. SO the intensity widget supports monochrome images. And what about colorful images?

On Tue, May 1, 2012 at 10:30 AM, Pavel Masloff <[email protected]<mailto:[email protected]>> wrote:
Matt that's an exhaustive explanation! Thanks.
Still I can't get a decent picture in BOY :((


On Tue, May 1, 2012 at 5:15 AM, Matt Newville <[email protected]<mailto:[email protected]>> wrote:
Hi Pavel,

On Mon, Apr 30, 2012 at 3:20 PM, Pavel Masloff <[email protected]<mailto:[email protected]>> wrote:
> Hey Matt,
>
> Thanks for sharing! I can't make your code work, though. Every time I get
> some gibberish image, You might have forgotten to convert int to string?
> I am using the following script.
> Image file -> waveform:
>
> import Image
> import StringIO
>
> from epics import PV
> f = open('hello.bmp')  # source image file
> data = f.read()
> chan = PV ('file')
> chan.put(data)

Sorry, I think I may have misunderstood your intent.  Your script
takes the contents of the file and puts it into a waveform PV.  That's
a fine thing to do, but it is not putting the image data to the
waveform PV.  It's an interesting approach... one could do the same
with any file, as long as the consumer of the PV knows what format the
file is meant to be.

> Waveform -> image file:
>
> import os, sys
> import Image
> import StringIO
> from epics import PV
>
> chan = PV ('file')     #waveform pv
> data = chan.get()      #waveform.val
>
>
> sdata = ''.join(chr(x) for x in data)
> sfile = StringIO.StringIO(sdata)
> im = Image.open(sfile)
> im.save("yoyo.bmp")
> im.show()
>

Right - That should work, reading the waveform data as the file
contents, and interpreting it as an image file (not the data of an
image).

> Another thing I can't understand - the Intensity widget in BOY. I don't know
> how to set its properties. I set PV name, Data height, Data width, Max, Min.
> And get an ugly image.

Probably because your waveform record holds the bytes of the image
file, not the image data.

> Could you also explain to me how the trasformation image binary file ->
> waveform and back happens? As I understand an image is roughly a set of
> pixels each with its own color. There is also a header (which we don't
> need?) Then we read the file and forward every byte into the waveform record
> which is of type unsigned char (integers 0-255) with a size = 1byte. So in
> order to get an image out of the waveform we should break the waveform N
> times with an interval M (if our image dimensions are N*M). There is also a
> Color map which specifies what color our integers equal to.
> Now when we want to convert our waveform back to file we are using the
> chr(x) function, I don't know why.

Your method is definitely sending the BMP header information.  That
should be OK, but it means the consumers have to know they're getting
a BMP file, not image data.    I think that might be the issue.   You
could try something like this (untested!) to have the waveform hold
the image data:

:: Image file -> waveform:

   import Image
   import numpy as np
   from epics import PV

   chan = PV ('file')

   im = Image.open('hello.bmp')
   chan.put(im.getdata())
   # or, if that complains, perhaps
   # chan.put(np.array(im.getdata(), dtype='uint8').flatten())

That will post the image data to the waveform, and should work with
any image file, though you might have to play with the conversion
depending on what's in the image file.  The advantage is that any CA
client (say, BOY or Python) should be able to read the waveform as
image data and know what to do with it.  You might want to add a
couple auxiliary PVs where you can put the image size NX, and NY and
format (8-bit greyscale, RGBA, etc) from your Image file-> waveform
publishing script.  This is what AreaDetector does, and it allows
clients to look up the sizes and formatting without guessing.

A consumer script then might then look more like I suggested earlier:

:: Waveform -> image file:
   import Image
   from epics import PV

   chan = PV ('file')
   data = chan.get()
   im = Image.frombuffer('L', (nx, ny), data, 'raw', 'L', 0, 1)
   im.show()

   im.save("yoyo.bmp") # or 'yoyo.png', .jpg, etc

Again, you might need to carefully check the details of your bitmap
file, as bitmaps can vary, with palettes, etc.., and other formats can
have other sorts of issues.  If you assume it's 8-bit greyscale (as
'L' here does) and you get wonky looking images, you might need to
adjust that, or better yet, adjust the image you post so that the
posted data can be consumed easily as an 8-bit greyscale or RGB color
image, or whatever is appropriate.

> Next thing as you mentioned is the NELM field and EPICS_CA_MAX_ARRAY_BYTE
> variable. So if our image is say 400*300 24 bit BMP image, does it mean we
> should set NELM=400*300 and EPICS_CA_MAX_ARRAY_BYTE=400*300*24?

EPICS_CA_MAX_ARRAY_BYTES (With 'S') should exceed 400*300*3.  If you
make your 'file' PV larger than you actually need, the put() will fill
in the first part of the waveform and leave the rest untouched.  You
can count down on network traffic by asking for the appropriate size
instead of the full waveform.  Whether that matters depends, of
course.

Hope that helps,

--Matt



--
Best regards,


Pavel Maslov, MS
Controls Engineer at Pulsed power Lab
Efremov Institute for Electro-Physical Apparatus
St. Petersburg, Russia

Mobile: +7 (951) 672 22 19
Landline: +7 (812) 461 01 01



--
Best regards,


Pavel Maslov, MS
Controls Engineer at Pulsed power Lab
Efremov Institute for Electro-Physical Apparatus
St. Petersburg, Russia

Mobile: +7 (951) 672 22 19
Landline: +7 (812) 461 01 01


Replies:
Re: [Scopes] BMP image record?? Pavel Masloff
References:
[Scopes] BMP image record?? Pavel Masloff
RE: [Scopes] BMP image record?? Mark Rivers
Re: [Scopes] BMP image record?? Pavel Masloff
RE: [Scopes] BMP image record?? Mark Rivers
Re: [Scopes] BMP image record?? Pavel Masloff
RE: [Scopes] BMP image record?? Mark Rivers
Re: [Scopes] BMP image record?? Pavel Masloff
RE: [Scopes] BMP image record?? Wang Xiaoqiang
Re: [Scopes] BMP image record?? Pavel Masloff
Re: [Scopes] BMP image record?? Matt Newville
Re: [Scopes] BMP image record?? Pavel Masloff
Re: [Scopes] BMP image record?? Matt Newville
Re: [Scopes] BMP image record?? Pavel Masloff
Re: [Scopes] BMP image record?? Pavel Masloff

Navigate by Date:
Prev: RE: AreaDetector Roper or PVCam IOC link problem giles.knap
Next: Re: [Scopes] BMP image record?? Pavel Masloff
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: [Scopes] BMP image record?? Pavel Masloff
Next: Re: [Scopes] BMP image record?? Pavel Masloff
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 18 Nov 2013 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·