简体   繁体   English

如何解决 ImageJ 运行(“HSB 堆栈”)错误/错误?

[英]How to work around ImageJ run("HSB stack") error/ bug?

I am working on a macro for ImageJ.我正在为 ImageJ 开发宏。 The goal is to take colour scans with several seeds on them and crop around the seeds to get several equally sized images with one seed on each.目标是对上面有几个种子进行彩色扫描,然后在种子周围进行裁剪,以获得几个大小相同的图像,每个图像上都有一个种子。 This is the basic idea for the macro: prompt to select folder with scans (info about the seed is in the name of the image) > threshold to select seeds > crop around each seed on the original image > save all of the cropped images in a folder (name of the cropped images still containing the information of the name of the original image) When I run the code below, I get an error for line 31: run("HSB stack");这是宏的基本思想:提示 select 文件夹进行扫描(有关种子的信息在图像的名称中)> select 种子的阈值 > 在原始图像上围绕每个种子进行裁剪 > 将所有裁剪的图像保存在一个文件夹(裁剪图像的名称仍然包含原始图像名称的信息)当我运行下面的代码时,我收到第 31 行的错误:run("HSB stack"); The error informs me about supported conversions and shows that in order to run this command I need to start with an RGB image.该错误通知我支持的转换,并表明为了运行此命令,我需要从 RGB 图像开始。 However, according to Fiji > Image > Type, my images are RGBs.但是,根据 Fiji > Image > Type,我的图像是 RGB。 A coding error in that part also seems unlikely since it was written with the recording function in ImageJ.该部分的编码错误似乎也不太可能,因为它是使用 ImageJ 中的记录 function 编写的。

Error message错误信息

According to what I found for the error, this seems to concern a recurring bug in the software, specific to the commands run("HSB stack") and run("RGB stack") in macros.根据我发现的错误,这似乎与软件中反复出现的错误有关,特定于宏中的命令 run("HSB stack") 和 run("RGB stack")。 We have tried running this on ImageJ 2.3.0/1.53s as well as 1.53q on MacOS and Windows and always got the same problem.我们已经尝试在 ImageJ 2.3.0/1.53s 以及 MacOS 和 Windows 上的 1.53q 上运行它,但总是遇到同样的问题。 If it is not a software problem, where is the error?如果不是软件问题,错误在哪里? Or if it is, do you have any suggestions for workarounds or a different program that could perform the same job?或者,如果是,您对解决方法或可以执行相同工作的不同程序有任何建议吗?

The images I am working with are colour scans, 600dpi, white background with between 1 and 90 seeds on each scan.我正在使用的图像是彩色扫描,600dpi,白色背景,每次扫描有 1 到 90 个种子。 They are large tiff images (107.4 MB) but look like this: Example scan image它们是大型 tiff 图像 (107.4 MB),但看起来像这样:示例扫描图像

I am not sure if it is helpful, but the code is below.我不确定它是否有帮助,但代码如下。 There are probably still errors in the latter part that I could not yet get to because I can't get past the problem in line 31.后半部分可能仍然存在我无法解决的错误,因为我无法解决第 31 行中的问题。

// Directory
dir=getDirectory("Choose a data folder");
list = getFileList(dir);
processed_dir_name = dir + "Cropped" + File.separator;
print(processed_dir_name);
File.makeDirectory(processed_dir_name);

// Batch
for (i=0; j<list.length; i++) {
print(i + ":" + dir+list[i]};

// Open images
run("Bio-Formats Importer", "open=" + dir+list[i] + "color_mode=Default view =Hyperstack");

// Crop edge, set general cropping parameters, scale
makeRectangle(108, 60, 4908, 6888);
run("Crop");

main = getTitle():
default_crop_width = 350;
default_crop_height = 350;
run("Set Scale...", "distance=600 known=25.4 unit=mm global");

//Thresholding
run("Color Threshold...");
//Color Thresholder 2.3.0/1.53q
// Autogenerated macro, single images only!
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("HSB stack");
run("Convert Stack to images");
selectWindow("Hue");
rename("0");

selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=0;
max[0]=255;
filter[0]="pass";
min[1]=0;
max[1]=255;
filter[1]="pass";
min[2]=0;
max[2]=193;
filter[2]="pass";
for (i=0;j<3;i++){
 selectWindow(""+i);

The problem lies in the fact that your image is a hyperstack, and the color thresholding doesn't know how to work with that.问题在于您的图像是一个超堆栈,并且颜色阈值不知道如何使用它。 There are a few options you could try: Open the image as an 8-bit RGB, eg via open(dir+list[i]);您可以尝试以下几个选项: 以 8 位 RGB 格式打开图像,例如通过open(dir+list[i]); or split the channels of the hyperstack and threshold each separately.或分别拆分超堆栈和阈值的通道。 Based on your sample image, I assume the first option makes more sense.根据您的示例图像,我认为第一个选项更有意义。

The following is an edited version of your code that works for the sample that you've provided:以下是适用于您提供的示例的代码的编辑版本:

// Directory
dir=getDirectory("Choose a data folder");
list = getFileList(dir);
processed_dir_name = dir + "Cropped" + File.separator;
print(processed_dir_name);
File.makeDirectory(processed_dir_name);

// Batch
for (i=0; i<list.length; i++) 
{   
    if (!File.isDirectory(dir+list[i])) // Ignore directories such as processed_dir_name
    {
        print(i + ":" + dir+list[i]);
    
        // Open images
        open(dir+list[i]);
        
        // Crop edge, set general cropping parameters, scale
        makeRectangle(108, 60, 4908, 6888);
        run("Crop");
    
        main = getTitle();
        default_crop_width = 350;
        default_crop_height = 350;
        run("Set Scale...", "distance=600 known=25.4 unit=mm global");
    
        //Thresholding
        //run("Color Threshold...");
        
        //Color Thresholder 2.3.0/1.53q
        // Autogenerated macro, single images only!
        min=newArray(3);
        max=newArray(3);
        filter=newArray(3);
        a=getTitle();
        run("HSB Stack");
        run("Convert Stack to Images");
        selectWindow("Hue");
        rename("0");
        selectWindow("Saturation");
        rename("1");
        selectWindow("Brightness");
        rename("2");
        min[0]=0;
        max[0]=255;
        filter[0]="pass";
        min[1]=0;
        max[1]=255;
        filter[1]="pass";
        min[2]=0;
        max[2]=193;
        filter[2]="pass";
        for (j=0;j<3;j++){
          selectWindow(""+j);
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM