Bio-format meta data to crop in import

Dear all,
I try to cut my files in 4 part with the crop import from Bio format but I can’t find how to set properly the macro

Hi Alex,

if it is not specifically necessary to crop using Bio-Formats directly on import, I would suggest to first open the image, duplicate the desired regions and save those.
See below macro code as an example of what I mean, using the useful script parameters to get to the file:

#@ File input_image

directory = File.getParent(input_image);
run("Bio-Formats Importer", "open=" + input_image + " autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
title = getTitle();
getDimensions(width, height, _, _, _);

makeRectangle(0, 0, width/2, height/2);
makeRectangle(width/2, 0, width/2, height/2);
makeRectangle(0, height/2, width/2, height/2);
makeRectangle(width/2, height/2, width, height);

for (i = 0; i < roiManager("count"); i++) {
	roiManager("select", i);
	run("Duplicate...", " ");
	filename = title + "_crop"  + i + ".ome.tif";
	savename = directory + "/" + filename;
	run("Bio-Formats Exporter", "save=" + savename + " compression=Uncompressed");

1 Like

if you do have to crop on import maybe your input arguments need to be data type string for the bio-formats command.

here’s a (python) command that worked for me:

# xPos, yPos are integers"Bio-Formats Importer", "open=["+origPath+"] color_mode=Default crop rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT series_1 x_coordinate_1="+str(xPos)+" y_coordinate_1="+str(yPos)+" width_1="+str(width)+" height_1="+str(height)+"")
1 Like

Sorry, my message was not very clear.
I have multiple 2D big file bigger than 2.5Go and when I open them in Fiji the images have bugs.
Every files have different X and Y number of pixels. I would like to imports 4 times to save 4 OME.tiff or 4 tiff files.
So I decide to read the metadata from the files (maybe with Bioformat). Do you know how to read the metadata without opening the files ? Like this I will know the size of every files in my folder and I can batch the macro easily.

I tried

  1. getDimensions(width, height, channels, slices, frames) but this works only with a pictures already open“Bio-Formats Importer”, “open=inputPath2 color_mode=Default rois_import=[ROI manager] view=[Metadata only] stack_order=XYCZT”) I have a widow with the infos but I don’t know how to extract the data for the macro

  1. and run(“Bio-Formats Macro Extensions”);.
    Ext.getMetadataValue(“width”, width );
    Ext.getMetadataValue(“height”, height );
    But now the macro crash bioformat error and I can’t understand how to set the field and value

Hi Alex,

If you are comfortable to switch the scripting language to e.g. python, here is a good way to get the ome-xml metadata of an image without reading in the pixels:

How exactly its done is shown in the linked example scripts.
Hope this helps!
Cheers, Kai

1 Like

I don’t know how to script. For the moment I use only the macro tools from Fiji.
I will try Python with this script.

Thank you

I found the solution !!

run("Bio-Formats Macro Extensions");
input = getDirectory("choose the input directory"); 				
function processFolder(input);
list2 = getFileList(input); 
	for (j=0; j<list2.length; j++) {
			inputPath2= input +  list2[j];
print("Width = " + sizeX + " , height = " + sizeY);
1 Like

another way is through the loci.formats tools. in python:

from loci.formats import ImageReader
from loci.formats import MetadataTools

reader = ImageReader()
omeMeta = MetadataTools.createOMEXMLMetadata()
#my images are pyramidal and the different resolutions are called 'series'
seriesCount = reader.getSeriesCount()
#print seriesCount
sizeX = reader.getSizeX()
sizeY = reader.getSizeY()
print sizeX
print sizeY
physSizeX = omeMeta.getPixelsPhysicalSizeX(seriesCount-3)
#print physSizeX.value()