我正在使用一个 ImageJ 宏,它打开并处理来自几个按顺序命名的样本的一组图像——例如sample1_image1.tif,sample1_image2.tif,sample2_image1.tif,(...)。我正在使用循环来增加样本和图像的序列。
for (i=0; i<samplenumber.length; i++) // Counter of the samples
{
imgnumber = imgspersample[i];
j=0;
for (j=0; j<imgnumber; j++) // Counter of the images for a given sample
{
k = j + 1;
file = "sample"+samplenumber[i]+"_image"+k+".tif";
path = directory+file;
// Opening, converting and thresholding the image
open(""+path+"");
但是,一些示例可能会丢失,并且当宏尝试打开不存在的图像时会发生错误,从而打破循环。是否可以添加任何功能或条件,以便在缺少样本时循环不会中断?
例如:如果缺少样本 2,宏会打开并处理样本 1 中的所有图像,识别出样本 2 没有图像,然后跳转到样本 3?