Advertisement
UF6

Pyramidal OME-TIFF using the Bio-Formats API

UF6
Oct 31st, 2023
1,973
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.34 KB | Source Code | 0 0
  1. % Add the Bio-Formats toolbox to the MATLAB path
  2. addpath('path_to_bfmatlab_folder');
  3.  
  4. % Import the necessary Bio-Formats classes
  5. import loci.formats.*;
  6.  
  7. % Create a Bio-Formats Reader for your input images
  8. reader = loci.formats.ChannelFiller();
  9.  
  10. % Configure metadata for the output pyramidal OME-TIFF
  11. metadata = loci.formats.MetadataTools.createOMEXMLMetadata();
  12.  
  13. % Define the output file name
  14. outputFile = 'output.ome.tif';
  15.  
  16. % Set the number of pyramid levels (e.g., 5 levels)
  17. numPyramidLevels = 5;
  18.  
  19. % Load your input images (assuming you have them in an 'images' cell array)
  20. images = cell(numPyramidLevels, 1);
  21. for level = 1:numPyramidLevels
  22.     % Load the image for the current level
  23.     image = imread(['image_level_' num2str(level) '.tif']);
  24.    
  25.     % Store the image in the 'images' cell array
  26.     images{level} = image;
  27. end
  28.  
  29. % Write the pyramid levels to the output OME-TIFF
  30. for level = 1:numPyramidLevels
  31.     % Set the resolution level for the current image
  32.     metadata.setPixelsSizeC(0, images{level}, level - 1);
  33.    
  34.     % Write the image to the Bio-Formats reader
  35.     reader.setId(outputFile);
  36.     reader.setSeries(0);
  37.     reader.saveBytes(0, images{level}, level - 1);
  38. end
  39.  
  40. % Close the Bio-Formats reader
  41. reader.close();
  42.  
  43. % Save metadata to the output OME-TIFF
  44. loci.formats.FileStitcher.writeOME(metadata, outputFile);
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement