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]>
Cc: EPICS Tech Talk <[email protected]>
Date: Tue, 1 May 2012 14:38:20 +0000
areaDetector uses ordinary EPICS waveforms for images.  It just uses a naming convention for the waveform record and a few other records that describe the waveform.  If you name your records with this convention then you can use the ImageJ plugin to view the images.

The naming convention is:
PVPrefix + "ArrayData"
PVPrefix + "ArraySize0_RBV"
PVPrefix + "ArraySize1_RBV"
PVPrefix + "ArraySize2_RBV"
PVPrefix + "ColorMode_RBV"
PVPrefix + "UniqueId_RBV"

ArrayData is the waveform PV.  It can be any supported EPICS waveform record data type except "STRING" or "ENUM".

ArraySize0_RBV is the first dimension (fastest changing) of the array
ArraySize1_RBV is the second dimension of the array
ArraySize2_RBV is the third dimension (slowest changing) of the array.  This dimension is only used for color images.

ColorMode_RBV is an enum with the following values:
typedef enum
{
    NDColorModeMono,    /**< Monochromatic image */
    NDColorModeBayer,   /**< Bayer pattern image, 1 value per pixel but with color filter on detector */
    NDColorModeRGB1,    /**< RGB image with pixel color interleave, data array is [3, NX, NY] */
    NDColorModeRGB2,    /**< RGB image with row color interleave, data array is [NX, 3, NY]  */
    NDColorModeRGB3,    /**< RGB image with plane color interleave, data array is [NX, NY, 3]  */
    NDColorModeYUV444,  /**< YUV image, 3 bytes encodes 1 RGB pixel */
    NDColorModeYUV422,  /**< YUV image, 4 bytes encodes 2 RGB pixel */
    NDColorModeYUV411   /**< YUV image, 6 bytes encodes 4 RGB pixels */
} NDColorMode_t;

ColorMode_RBV=0 is a monochrome image and ArrayData has dimensions [ArraySize0_RBV, ArraySize1_RBV]

ColorMode_RBV=2 is an RGB color image and ArrayData has dimensions [ArraySize0_RBV=3, ArraySize1_RBV, ArraySize2_RBV]

The ImageJ plugin supports all of these color modes except the YUV ones.

UniqueId_RBV is a uniqueId for each image.  The ImageJ plugin monitors this PV for changes, and whenever it changes it does a caget() on the ArrayData PV, but requesting only the number of elements that it calculates based upon the ColorMode_RBV and array dimensions.  It does this rather than putting a monitor on the ArrayData PV, because then it would have to change its subscription each time the ColorMode or array dimensions changed.

Mark



From: Pavel Masloff [mailto:[email protected]] 
Sent: Tuesday, May 01, 2012 8:44 AM
To: Mark Rivers
Cc: Matt Newville; EPICS Tech Talk
Subject: Re: [Scopes] BMP image record??

Should the Waveform PV be of areaDetector type? Or it can be an ordinary EPICS wafeform
On Tue, May 1, 2012 at 4:12 PM, Mark Rivers <[email protected]> wrote:
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



-- 
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


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
RE: [Scopes] BMP image record?? Mark Rivers
Re: [Scopes] BMP image record?? Pavel Masloff

Navigate by Date:
Prev: RE: [Scopes] BMP image record?? Chen, Xihui
Next: RE: [Scopes] BMP image record?? Chen, Xihui
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?? Chen, Xihui
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 ·