X-ray diffraction image --> .jpg  



ImageMagickで変換する by James Holton  

ImageMagickの汎用データ読み込みで変換が可能なようです。さすがはJames Holtonといったとろですね。

Believe it or not, you can do this with ImageMagick, which is already part of most linux distros :

convert -depth 16 -type Grayscale -colorspace GRAY -endian LSB -size 3072x3072+512 GRAY:test_0_001.img test_0_001.jpg

where this example turns a binned Q315 image (3072x3072 pixels) with a 512-byte header (almost always the case) that has "BYTE_ORDER=little_endian" into a jpg image. For a big_endian image, you change LSB to HSB in the above command.


You may notice that the image above compresses incredibly well (about 300 fold), but if you look at it, you will be very disappointed as it is almost totally black. This is because JPEG only uses the high-order byte of a 16-bit image. One could argue that this is perhaps the "right" way to look at diffraction patterns since the most important information is in the bright spots and not the noisy background, but if you want to render your *.img file in the "ADXV way", then this command is close:

convert -depth 16 -type Grayscale -colorspace GRAY -endian LSB -size 3072x3072+512 \
    GRAY:test_0_001.img -negate -crop 1024x1024+512+512 -equalize test_0_001.jpg

The "-negate" flag will make the spots black and the background grey, and the "-equalize" filter will throw out all the "outlier pixels" (spots) so you can look at the background. You may also want to use the "-crop" option to focus in on just one part of the image. There are other "enhancement" flags like -normalize, and -contrast-stretch or -brightness and -contrast, but the exact behavior of these flags will depend on the version of ImageMagick you have.


There is probably also a way to "colorize" the data the way ADXV does with the "heat" or "rainbow" options, but I don't know how to do that in ImageMagick. In such cases, I do use screen capture, but again ImageMagick's "import" program is convenient for this. Coupled with the -autoload flag in ADXV, you can set the environment variable $XFORMSTATUSFILE to something like ./temp.txt and write a script to echo "$n $filename" into this file (where $n is an ever-increasing number), wait a few seconds (sleep 2), and then run "import -w root -crop ..." to capture the screen and crop out the part you want.


This will work for the formats supported by ADXV, but obviously other formats will need another program. The central problem is that every program (ADXV, MOSFLM, HKL, D*trek, etc.) has different ways of crushing the 16-bit pixels into 8 bits for the display, and we all have our "favorite" (the one that we think makes weak spots show up better), but almost none of the GUI displays have command-line-with-options equivalents. ImageMagick has enough features that you can usually figure out how to "replicate" a given display program's algorithm, but some file formats (like the "packed" Mar files) will never be readable by ImageMagick.


It is perhaps worth pointing out that the "ADSC format" is actually called "SMV" since this file format was originally created about 30 years ago for a program called "Super Marty View", (written by Martin Stanton, now at SomaLogic). It has evolved somewhat since then. The taxonomy of image file formats is something of a hobby of mine. There seems to be no less than a hundred different species of them floating around in the world. Some are rare, some are locally prevalent, but they appear to all be highly territorial and you will almost never find more than one varietal populating a given lab, synchrotron or even a given country. Someday I hope to collect specimens of each and every one of them (perhaps even filling out the "fossil record" or history of different beamlines and detectors) but documentation and particularly "example lysozyme datasets" are surprisingly hard to come by. For example, I once had a crinkly old paper document that defined the "R-axis format", but recent sitings of files from R-axis detectors seem to be a new species descended from an SMV-like ancestor, and yet nowhere on the Rigaku website is there a document describing this new format, much less an example. Most crystallographers do not have "good" data sets on hand (it is the bad ones that stay on disk forever), and many beamline scientists do not have any "test" data sets available either (for some reason). Currently, my meager "museum" is here:
If anyone would care to donate, I prefer data sets that are "easy" to process and that have anomalous differences (to clarify the hand of the spindle), but in cases where I have no examples, any data set will do.

James Holton
MAD Scientist