[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ccp4bb]: Diffraction images to gif/jpg



***  For details on how to be removed from this list visit the  ***
***          CCP4 home page http://www.ccp4.ac.uk         ***

Alternatively, you can rename the diffraction image extension to .RAW and 
import it with Photoshop.  You may have to specify the pixel dimensions 
of the image.  Photoshop should import it just fine.  Then change the 
Mode from 16-bit to 8-bit grayscale and save as a .jpg.  You won't get as 
much information from the .jpg as the original image of course, but this 
works fine for giving an example image.

Darrell Hurt

On Thu, 3 Oct 2002, Nicholas K. Sauter wrote:

> >
> > Does anyone have code to convert diffraction images to graphics format
> > (gif/jpg etc)? Maybe an addon to MOSFLM?
> 
> You can do everything with a python script.  I routinely convert ADSC
> detector images; you need to download and install Python 2.2.1 from
> python.org, plus the freeware 3rd party modules Numeric 21.0 and the
> Python Imaging Library 1.1.3.
> 
> Here's the whole program; it takes about 5 seconds on my 1.4 GHz Linux
> box:
> 
> import Image,Numeric,re
> 
> def ReadADSCImage(filename):
>   rawdata = open(filename,"rb").read()
>   headeropen = rawdata.index("{")
>   headerclose= rawdata.index("}")
>   header = rawdata[headeropen+1:headerclose-headeropen]
> 
>   parameters={}
>   for item in ['HEADER_BYTES','SIZE1','SIZE2']:
>     pattern = re.compile(item+'='+r'(.*);')
>     match = pattern.search(header)
>     parameters[item] = int(match.group(1))
>   ptr = parameters['HEADER_BYTES']
> 
>   numrawdata = Numeric.array(rawdata)
>   bigendchar =
> numrawdata[ptr:ptr+2*parameters['SIZE1']*parameters['SIZE2']:2]
>   bigend = bigendchar.astype(Numeric.UnsignedInt8)
>   smallendchar =
> numrawdata[ptr+1:ptr+2*parameters['SIZE1']*parameters['SIZE2']+1:2]
>   smallend = smallendchar.astype(Numeric.UnsignedInt8)
>   linearintdata = 256*bigend+smallend
>   return parameters,linearintdata
> 
> def writeJPEG(filein,fileout):
>   params, linearintdata = ReadADSCImage(filein)
>   adjust = 256-linearintdata # to make pretty grayscale
>   imageout = Image.new("L",(params['SIZE1'],params['SIZE2']),0.5)
>   imageout.putdata(adjust)
>   imageout.save(fileout,"JPEG")
> 
> writeJPEG("./adscimage_1_001.img","./x.jpg")
> 
> 
> --
> Nicholas K. Sauter, Ph.D.
> Lawrence Berkeley National Lab
> 1 Cyclotron Road, Bldg 4R0230
> Berkeley, CA 94720-8235
> 
> nksauter@lbl.gov
> Voice: 510-486-5713
> Fax: 510-486-5909
> 
>