; $Id: ij_read_bio_formats.pro,v 1.16 2009/05/08 19:04:54 karo Exp $ ;+ ; NAME: ; ij_read_bio_formats ; ; ; PURPOSE: ; Reading different file formats using bio-formats.jar Java library from ; http://www.loci.wisc.edu/ome/formats.html ; considering some explanations found in ; https://skyking.microscopy.wisc.edu/svn/java/trunk/components/bio-formats/doc/using-bioformats.txt ; ; ; CATEGORY: ; IO ; ; ; CALLING SEQUENCE: ; image=ij_read_bio_formats(filename [, info, /VERBOSE, /RAW, /NODATA]) ; ; INPUTS: ; filename ; ; OPTIONAL INPUTS: ; info: Variable contains upon return header information ; ; KEYWORD PARAMETERS: ; VERBOSE=1 Prints the header info ; RAW=1 Data are not reformed ; NODATA=1 No data are read, only header data are read ; STACK=1 In case of errors print stack (test purpose) ; ; OUTPUTS: ; image=image data (2...5-dim) ; ; COMMON BLOCKS: ; none ; ; SIDE EFFECTS: ; idljavabridge has to be configured (~/.idljavabrc) ; with bio-formats.jar in the classpath and loci-common.jar, ; poi-loci.jar in the same directory ; Example CLASSPATH from .idljavabrc ; JVM Classpath = $CLASSPATH:/Applications/MiscEXE/ImageJ/ij.jar:/Applications/MiscEXE/ImageJ/plugins/bio-formats.jar:/Applications/itt/idl70/resource/bridge/import/java/jbexamples.jar ; if there is an error concerning AWT threading try in (~/.idljavabrc) ; to add the option: ; JVM Option1 = -Djava.awt.headless=true ; Sometimes data a read although messages are printed! ; ; RESTRICTIONS: ; This is mere alpha state. Everything is done on Mac OS X 5.3 (Leopard) ; (in the mean time with Mac OS X 5.6 and IDL 7.0.6) ; Only tested with flat tiff, lsm (one series), zvi (also only one series). ; I would appreciate to get improved code for other formats. ; ; bio-formats know a certain "dimensionorder", describing the interleaving. ; For XYZCT I try to generate pixel interleaved data! ; For XYCTZ and XYCZT data are reformed to the given order ; all others are returned as stream of pixels, to be reformed accordingly. ; (I had no other examples!) ; ; Up to now no series are handled, lacking examples. ; I hope the problem "call AWT" solved, will allow to use openImage method ; and other already in the library inbuilt functions. ; This is dirty programming but helpful for some things! ; ; PROCEDURE: ; a = ij_read_bio_formats("testimage.zvi",inf) ; help,a ; A UINT = Array[650, 650, 4] ; help,inf,/str ; ** Structure <215b410>, 25 tags, length=116, data length=115, refs=1: ; NAME STRING 'testimage.zvi' ; IMAGECOUNT LONG 4 ; SERIESCOUNT LONG 1 ; FORMAT STRING 'Zeiss Vision Image (ZVI)' ; SIZEX LONG 650 ; SIZEY LONG 650 ; SIZEC LONG 4 ; SIZEZ LONG 1 ; SIZET LONG 1 ; THUMBSIZEX LONG 128 ; THUMBSIZEY LONG 128 ; PIXELTYPE LONG 3 ; RGBCHANNELCOUNT LONG 1 ; ISRGB INT 0 ; ISINDEXED INT 0 ; ISFALSECOLOR INT 0 ; ISLITTLEENDIAN INT 1 ; ISINTERLEAVED INT 1 ; ISORDERCERTAIN INT 1 ; EFFECTIVESIZEC LONG 4 ; DIMENSIONORDER STRING 'XYCZT' ; CHANNELDIMLENGTHS ; LONG Array[1] ; CHANNELDIMTYPES STRING Array[1] ; BBITLOOKUPTABLE BYTE 0 ; SBITLOOKUPTABLE INT 0 ; ; EXAMPLE: ; ; ; ; MODIFICATION HISTORY: ; ; Mon Dec 17 18:05:06 2007, Karsten Rodenacker ; ; $Log: ij_read_bio_formats.pro,v $ ; Revision 1.16 2009/05/08 19:04:54 karo ; Some weblink corrected ; ; Revision 1.15 2009/05/08 18:16:18 karo ; Documentation changed, option headless added for idljavabrc ; ; Revision 1.14 2008/06/05 17:28:32 karo ; Changed the header read and some logic ; Added documentation ; ; Revision 1.13 2008/06/05 12:47:09 karo ; restrictions added in doc ; ; Revision 1.12 2008/06/05 12:38:51 karo ; Documentation extended ; showexcept replaced by content ; ; Revision 1.11 2008/06/04 21:20:41 karo ; reform part extended ; ; Revision 1.10 2008/06/04 17:10:42 karo ; swap added ; exceptions isolated ; same reforming done ; ; Revision 1.9 2008/06/03 17:57:14 karo ; Minor changes in the reform of data ; Documentation added ; ; Revision 1.8 2008/05/31 21:48:16 karo ; some improvements, still not ready with rearrangement ; ; Revision 1.7 2008/05/30 21:15:38 karo ; Some improvements concerning reform of data ; ; Revision 1.6 2008/04/04 06:54:32 karo ; *** empty log message *** ; ; Revision 1.5 2008/03/13 22:08:24 karo ; openImage durch openBytes ersetzt (Tip von Curtis Rueden) ; ; Revision 1.4 2008/01/16 14:35:27 karo ; Added CVS info ; ; ; ;- function ij_read_bio_formats_head, m, verbose=verbose, DESTROY = destroy bbit = m -> get8BitLookupTable() sbit = m -> get16BitLookupTable() if n_elements(bbit) lt 2 then bbit = 0b if n_elements(sbit) lt 2 then sbit = 0 head={Name: m -> getCurrentFile(), $ ImageCount: m -> getImageCount(), $ SeriesCount: m -> getSeriesCount(), $ Format: m -> getFormat(), $ SizeX: m -> getSizeX(), $ SizeY: m -> getSizeY(), $ SizeC: m -> getSizeC(), $ SizeZ: m -> getSizeZ(), $ SizeT: m -> getSizeT(), $ ThumbSizeX: m -> getThumbSizeX(), $ ThumbSizeY: m -> getThumbSizeY(), $ PixelType: m -> getPixelType(), $ RGBChannelCount: m -> getRGBChannelCount(), $ isRGB: m -> isRGB(), $ isIndexed: m -> isFalseColor(), $ isFalseColor: m -> isIndexed(), $ isLittleEndian: m -> isLittleEndian(), $ isInterleaved: m -> isInterleaved(), $ isOrderCertain: m -> isOrderCertain(), $ EffectiveSizeC: m -> getEffectiveSizeC(), $ DimensionOrder: m -> getDimensionOrder(), $ ChannelDimLengths:m -> getChannelDimLengths(), $ ChannelDimTypes: m -> getChannelDimTypes(), $ BBitLookupTable: bbit, $ SBitLookupTable: sbit } if keyword_set(verbose) then help,head,/str if keyword_set(destroy) then obj_destroy, m return, head end function ij_read_bio_formats_raw, m, head, swap = swap, verbose=verbose if head.imagecount gt 0 then begin ;; a=m->openImage(0l) ;; a1=a->getData() ;; a11=a1->getDataBuffer() ;; px=a11->getBankData() px = m -> openBytes(0l) ;; unsi=obj_class(a11) eq "IDLJAVAOBJECT$JAVA_AWT_IMAGE_DATABUFFERUSHORT" ;; if unsi then px=uint(temporary(px)) ;; obj_destroy,[a11,a1,a] for i=1l,head.imagecount-1 do begin ;; a=m->openImage(i) ;; a1=a->getData() ;; a11=a1->getDataBuffer() ;; py=a11->getBankData() py = m -> openBytes(i) ;; if unsi then py=uint(temporary(py)) px=[temporary(px),temporary(py)] ;; obj_destroy,[a11,a1,a] endfor case head.pixeltype of ;; 0: int8 does not exist ;; 1: uint8 is default 2: px = fix(px, 0, n_elements(px)/2) 3: px = uint(px, 0, n_elements(px)/2) 4: px = long(px, 0, n_elements(px)/4) 5: px = ulong(px, 0, n_elements(px)/4) 6: px = float(px, 0, n_elements(px)/4) 7: px = double(px, 0, n_elements(px)/8) else: endcase return,px endif else return, -1l end function ij_read_bio_formats, na, head, $ verbose=verbose, raw = raw, nodata = nodata, $ STACK = stack catch, err if err ne 0 then begin if err lt 0l then print, !error_state.msg oBridgeSession = OBJ_NEW("IDLJavaObject$IDLJAVABRIDGESESSION") oExc = oBridgeSession->getException() IF (oExc NE OBJ_NEW()) THEN BEGIN print, oExc->toString() if keyword_set(stack) then begin print, 'Stack Trace : ' oExc->printStackTrace print, '' endif OBJ_DESTROY, oExc ENDIF ELSE BEGIN print, 'No Java exception to show!' ENDELSE OBJ_DESTROY, oBridgeSession catch, /cancel if obj_valid(m) then obj_destroy, m return, -1l endif m = obj_new("idljavaobject$bio-formats_loci_formats","loci.formats.ImageReader") m -> setId,na head = ij_read_bio_formats_head(m, verbose=verbose) if keyword_set(nodata) then begin obj_destroy,m return, 1l endif px = ij_read_bio_formats_raw(m, head, verbose = verbose) obj_destroy,m if ~keyword_set(raw) then case head.dimensionorder of "XYZCT": if strpos(head.format,'ZVI') lt 0 $ then px = transpose(reform(temporary(px), $ head.sizex, head.sizey, head.sizec, $ head.sizez, head.sizet), $ [2, 0, 1, 3, 4]) $ else px = transpose(reform(temporary(px), $ head.sizex, head.sizey, head.sizez, $ head.sizec, head.sizet), $ [3, 0, 1, 2, 4]) "XYCTZ": px = reform(temporary(px), $ head.sizex, head.sizey, head.sizec, $ head.sizet, head.sizez) "XYCZT": px = reform(temporary(px), $ head.sizex, head.sizey, head.sizec, $ head.sizez, head.sizet) else: endcase if head.islittleendian then swap_endian_inplace, px, /SWAP_IF_BIG_ENDIAN $ else swap_endian_inplace, px, /SWAP_IF_LITTLE_ENDIAN return, reform(temporary(px)) end