我正在尝试将图像文件与数组中的特定行匹配。 在第一步中,我选择包含tif文件的文件夹。 然后我选择一个csv文件,其中包含我想要使用的信息。 我一个接一个地打开每个图像。对于打开的图像,我想从与csv文件中的图像名称对应的行中检索值。 CSV文件的标题是FileName,XValue,YValue。
到目前为止,这是我的代码......任何帮助都将不胜感激。
// Make a pop up to select the input directory
InputDirPath=getDirectory("Select Input directory");
// Get the list of files in the input input directory selected above as an array
InputFileList=getFileList(InputDirPath);
// Defines cell separator and line separator
CellSeparator=",";
LineSeparator="\n";
// open the csv file as a string
FileCCValuesPath=File.openDialog("Select the file containing the coordinates");
FileCCValuesString=File.openAsString(FileCCValuesPath);
// Split each row into an array
FileCCValuesRows=split(FileCCValuesString, LineSeparator);
// Create new arrays for the content of column and for each row
FileNameArray=newArray(FileCCValuesRows.length);
XValueArray=newArray(FileCCValuesRows.length);
YValueArray =newArray(FileCCValuesRows.length);
// Start of the loop going through the list of image files in the input folder selected above
for (Filei = 0; Filei < InputFileList.length; Filei++)
{
InputFileNamei=InputFileList[Filei];
InputFilePathi = InputDirPath+InputFileNamei;
if(endsWith(InputFilePathi, ".tif"))
{
open(InputFilePathi);
//////////This is where I am stuck
//////////Get the XValue and Value from the CSV file for the row in which
//////////FileName=InputFileNamei
run("Translate...", "x=XValue y=YValue interpolation=None");
}//end if
}//end for File i loop
// Notice of end of process
waitForUser("Process is done");
答案 0 :(得分:1)
您可以添加另一个.center:hover h1 {
/* new padding here */
}
循环(在打开当前图像之后),该循环遍历所有行并检查该行是否以当前图像名称开头,然后拆分当前行以获取x和y值:
for
请注意,“ImageJ”方式是在结果表中打开您的CSV文件,并使用getResultString
和getResult
宏函数来获取要求的价值。以下是使用这些宏的版本:
for (i=0; i < FileCCValuesRows.length; i++) {
if (startsWith(FileCCValuesRows[i], InputFileNamei)) {
values = split(FileCCValuesRows[i], CellSeparator);
xValue = parseInt(values[1]);
yValue = parseInt(values[2]);
run("Translate...", "x=" + xValue+ " y=" + yValue + " interpolation=None");
}
}
答案 1 :(得分:1)
非常感谢您的回复 这就是我最终要做的事情:
1 - 使用
按行拆分数组FileValuesRows=split(FileValuesString, LineSeparator);
2-为每列创建新数组(由于标题,我删除了一行)
Column1Array=newArray(FileValuesRows.length-1);
Column2Array=newArray(FileValuesRows.length-1);
3-创建一个for循环,筛选每一行并将其分成每个单独的列(由于标题从1开始)
for (Rowi=1;Rowi<FileCCValuesRows.length; Rowi++){
FileCCValuesRowi=split(FileCCValuesRows[Rowi], CellSeparator);
//Array.show(FileCCValuesRowi);
4-将每行的内容内容添加到先前创建的数组中(由于标题为-1)
Column1Array[Rowi-1]=FileCCValuesRowi[0];
Column2Array[Rowi-1]=FileCCValuesRowi[1];
}
//end if for Rowi
5-在下一步中,目标是找到与当前打开图像对应的行号。这分两步完成: 5.1-在csv文件中筛选字符串的出现次数(在本例中为文件名) 5.2如果occurrence为非null,则将它们添加到Indices Array 5.3使用此indice获取与
之前创建的数组中该行对应的值//Returns the indices at which a value occurs within an array
Occurence=0;
// Screen the FileName Array row by row and count the number of occurence
for (Rowi=0; Rowi<lengthOf(FileNameArray); Rowi++) {
if (FileNameArray[Rowi]==InputFileName) {
Occurence++;
//print(Occurence);
} //end of if
} // end of for Rowi
// If found
if (Occurence>0) {
// Create an array of length the number of occurence
IndicesArray=newArray(Occurence);
Occurence=0;
// Screen the FileName Array row by row and add the row of occurence into the Indices Array
for (Rowi=0; Rowi<lengthOf(FileNameArray); Rowi++) {
if (FileNameArray[Rowi]==InputFileName) {
IndicesArray[Occurence]=Rowi;
Occurence++;
}
}
//Array.show(IndicesArray);
}
最后一步
//Get the X and Y translation value for the File being processed
In this case I have only 1 occurrence so I will take the first line of the Indice array which is the line 0
XValue=Column1Array[(IndicesArray[0])];
YValue=Column2Array[IndicesArray[0]];
//Translate the picture
run("Translate...", "x=XValue y=YValue interpolation=None");