roiManager:如何根据具有用户定义级别的变量定义颜色? ImageJ 宏

问题描述

我目前正在研究 ImageJ 宏,以帮助我分析从水下海洋栖息地拍摄的样方照片。

简而言之,到目前为止,我已经设法创建了一个宏,该宏将图像划分为平方选区,根据我在宏中定义的行和列的数量形成一个网格。然后,对于每个选择( 网格单元格),要求用户输入定义他所看到的内容的类别(例如沙子、贝壳、藻类)。这些类别以前没有定义,所以我无法知道会有多少。此外,图片间的类别可能会发生变化。 我想做的是根据其类别为每个选择填充一种颜色。例如,将所有归类为“藻类”的选项填充为绿色。

到目前为止,我所想到的并不是在宏中定义类别,而是打开一个对话框,要求用户为每个类别分配一个数字(因此是一个组),但这意味着用户还需要记住所有组/类别组合..

编辑:当为每个选择保存类别时,我设法创建了一个数组。但是,如果多个选择具有相同的类别(我知道会发生),则意味着我的数组充满了重复项。使用这个数组,是否可以将 group=1 归为沙子,将 group=2 归为贝壳,将 group=3 归为藻类?

EDIT2:我在网上找到了这个答案 https://forum.image.sc/t/random-color-generator/10506/4,考虑到一些适合我的问题的更改,它可能会有效。我会尝试相应地更新这篇文章。 --> 此答案中提到的代码允许我随机填充每个单元格,但它会将重复项视为不同的值(例如:按“藻类”分类的两个单元格将随机分配两种不同的颜色)。

我对创建 imageJ 宏完全陌生,但到目前为止,宏记录器以及在线找到的不同类型的文档都非常有用。但是,对于此组/类别问题的一些额外帮助将不胜感激!我什至不确定我正在尝试做的事情是否真的可行..

我可以研究的任何建议或功能都会有很大帮助!

以下是我目前所做的:

//Grid creation 
waitForUser("Please draw the upper left corner inside the quadrat. Press ok when finished");
setTool("point");
getSelectionCoordinates(xPoints,yPoints);
x = xPoints[0];
y = yPoints[0];
showMessage("Got coordinates ("+x+","+y+")");   

waitForUser("Please draw the bottom right corner inside the quadrat. Press ok when finished");
setTool("point");
getSelectionCoordinates(xPoints,yPoints);
x2 = xPoints[0];
y2 = yPoints[0];
showMessage("Got coordinates ("+x2+","+y2+")"); 

numRow = 2; //how many rows
numCol = 2; //how many columns
width = (x2-x)/numRow; //the width of the cell (pixel) 
height = (y2-y)/numCol; //the height of the cell (pixel)
spacing = 0; //spacing between the cells

//Will create as many selection as numRow*numCol add them to the ROI Manager
for (g = 0; g < numRow; g++) {
    for (j = 0; j < numCol; j++) {
        xOffset = j * (width + spacing);
        yOffset = g * (height + spacing);
        makeRectangle(x + xOffset,y + yOffset,width,height);
        roiManager("Add");
        run("Labels...","font=18 show draw");
        run("Add Selection...");
        run("Overlay Options...","stroke=yellow width=3 fill=none show"); 
    }
}
roiManager("Show All with labels");

setoption("ExpandableArrays",true);

catArray=newArray;

//For each cell,enter a category
for(h=0;h<roiManager("Count");h++){
    roiManager("select",h);
    run("Labels...","font=18 show");
        
    //Enter the category:
    Dialog.create("Observations");
    Dialog.addMessage("Please enter the name of the category:");
    Dialog.addString("Category:","Please enter a category");
    Dialog.show();
    category=Dialog.getString();

    catArray[h]=category;
    
    for(k=0;k<catArray.length;k++){
        setForegroungColor(255*random,255*random,255*random);
        run("Fill");
    }

} 
Array.print(catArray);

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...