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

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



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

begin:vcard 
n:Sauter;Nicholas
tel;fax:510-486-5909
tel;home:415-564-5061
tel;work:510-486-5713
x-mozilla-html:FALSE
org:Lawrence Berkeley National Lab;Computational Crystallography Initiative
adr:;;1 Cyclotron Road Mailstop 4-230;Berkeley;CA;94720;USA
version:2.1
email;internet:nksauter@lbl.gov
title:Computer Scientist
fn:Nicholas K. Sauter
end:vcard