-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2025-12-26_QuPath_输出detections的csv和txt格式文件.qmd
More file actions
86 lines (66 loc) · 2.28 KB
/
2025-12-26_QuPath_输出detections的csv和txt格式文件.qmd
File metadata and controls
86 lines (66 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---
title: 输出csv和txt
subtitle: 输出detections的csv和txt格式文件
date: 2025-12-26
toc-depth: 4
toc-expand: true
lang: en
---
对于QuPath项目图片的detections结果,有时候因为某种需要,就想输出逗号分隔(comma-separated)的csv格式文件,或者就想输出制表符分隔(tab-separated)的txt格式文件。
<center>
{width="100%"}
</center>
## 1. 输出csv和txt格式文件
参考如下代码:
```
// QuPath v0.6.0
import qupath.lib.gui.tools.MeasurementExporter
// #########################################
// Export all detections as comma-separated file (.csv)
// #########################################
// Make the current image name as a list
def entryList = [getProjectEntry()]
// If the folder detections exist, do noting; else create the folder
def outputPath = buildFilePath(PROJECT_BASE_DIR, "detections")
mkdirs(outputPath)
// Separate each measurement value in the output file with ","
def separator = ","
def csvName = getCurrentImageName() + "_detections.csv"
def csvOutputFile = new File(buildFilePath(outputPath, csvName))
// Create the measurementExporter and start the export
def exporter = new MeasurementExporter()
.imageList(entryList)
.separator(separator)
.allDetections()
.exportMeasurements(csvOutputFile)
println "${csvOutputFile} saved."
// #########################################
// Export all detections as tab-separated file (.txt)
// #########################################
def txtName = getCurrentImageName() + "_detections.txt"
def txtOutputFile = new File(buildFilePath(outputPath, txtName))
saveDetectionMeasurements("${txtOutputFile}")
println "${txtOutputFile} saved."
println "Done."
```
以上代码部分参考自[@MicroscopyRA2020]。
确认下文件已经保存成功:
```{r}
#| eval: false
# R v4.5.2
outputPath <- "path/to/detections/"
outputPath |> fs::dir_tree()
path/to/detections/
├── image1_detections.csv
├── image1_detections.txt
├── image2_detections.csv
├── image2_detections.txt
├── image3_detections.csv
├── image3_detections.txt
├── image4_detections.csv
├── image4_detections.txt
├── image5_detections.csv
└── image5_detections.txt
```
[给我买杯茶🍵](给我买杯茶.qmd)
## References