Changeset 3570 for trunk/utils


Ignore:
Timestamp:
01/25/08 14:25:47 (12 years ago)
Author:
curtis
Message:

Updated bfopen MATLAB script incorporating additional suggestions from Ville Rantanen and Brett Shoelson.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/utils/bfopen.m

    r3490 r3570  
    11function [result] = bfopen(id) 
    22 
     3% A script for opening microscopy images in MATLAB using Bio-Formats. 
     4% 
    35% Portions of this code were adapted from: 
    46% http://www.mathworks.com/support/solutions/data/1-2WPAYR.html?solution=1-2WPAYR 
    57% 
    6 % Thanks to Ville Rantanen for his performance improvements. 
     8% Excluding figure creation, this method is ~1.5x-2.5x slower than 
     9% Bio-Formats's command line showinf tool (MATLAB R14 vs. java 1.6.0_03), 
     10% due to overhead from reshaping arrays and converting pixel types. 
     11% 
     12% Thanks to Ville Rantanen for his performance improvements and ideas. 
     13% Thanks to Brett Shoelson of The MathWorks for his excellent suggestions. 
    714 
    8 r = loci.formats.ChannelSeparator(); 
     15% Internet Explorer sometimes erroneously renames the Bio-Formats library 
     16% to loci_tools.zip. If this happens, rename it back to loci_tools.jar. 
     17 
     18% load Bio-Formats library into MATLAB environment 
     19javaaddpath('loci_tools.jar'); 
     20% Alternately, you can add the library to MATLAB's static class path: 
     21%   1. Type "edit classpath.txt" at the MATLAB prompt. 
     22%   2. Go to the end of the file, and add the path to your JAR file 
     23%      (e.g., C:/Program Files/MATLAB/work/loci_tools.jar). 
     24%   3. Save the file and restart MATLAB. 
     25 
     26r = loci.formats.ChannelFiller(); 
     27r = loci.formats.ChannelSeparator(r); 
     28r = loci.formats.FileStitcher(r); 
     29tic 
    930r.setId(id); 
    1031numSeries = r.getSeriesCount(); 
     
    1536    h = r.getSizeY(); 
    1637    numImages = r.getImageCount(); 
    17     arr = double(zeros([h, w, 1])); 
    1838    for i = 1:numImages 
    1939        fprintf('.'); 
    2040        img = r.openImage(i - 1); 
    2141        % convert Java BufferedImage to MATLAB image 
    22         B = img.getData.getPixels(0, 0, w, h, []); 
    23         arr = reshape(B, [w h])'; 
     42        pix = img.getData.getPixels(0, 0, w, h, []); 
     43        arr = reshape(pix, [w h])'; 
     44        % build an informative title for our figure 
     45        label = id; 
     46        if numSeries > 1 
     47            qs = int2str(s); 
     48            label = [label, '; series ', qs, '/', int2str(numSeries)]; 
     49        end 
     50        if numImages > 1 
     51            qi = int2str(i); 
     52            label = [label, '; plane ', qi, '/', int2str(numImages)]; 
     53            if r.isOrderCertain() 
     54                lz = 'Z'; 
     55                lc = 'C'; 
     56                lt = 'T'; 
     57            else 
     58                lz = 'Z?'; 
     59                lc = 'C?'; 
     60                lt = 'T?'; 
     61            end 
     62            zct = r.getZCTCoords(i - 1); 
     63            sizeZ = r.getSizeZ(); 
     64            if sizeZ > 1 
     65                qz = int2str(zct(1) + 1); 
     66                label = [label, '; ', lz, '=', qz, '/', int2str(sizeZ)]; 
     67            end 
     68            sizeC = r.getSizeC(); 
     69            if sizeC > 1 
     70                qc = int2str(zct(2) + 1); 
     71                label = [label, '; ', lc, '=', qc, '/', int2str(sizeC)]; 
     72            end 
     73            sizeT = r.getSizeT(); 
     74            if sizeT > 1 
     75                qt = int2str(zct(3) + 1); 
     76                label = [label, '; ', lt, '=', qt, '/', int2str(sizeT)]; 
     77            end 
     78        end 
    2479        % plot the image plane in a new figure 
    25         figure; 
    26         pcolor(arr); 
     80        figure('Name', label); 
     81        imagesc(arr); 
    2782        % If you have the image processing toolbox, you could use: 
    28         %imshow(arr); 
     83        %imshow(arr, []); 
    2984        % You could do something else with each plane 
    3085        % here, rather than just overwriting the result. 
     
    3388    fprintf('\n'); 
    3489end 
     90toc 
Note: See TracChangeset for help on using the changeset viewer.