-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2026-03-09_swan.qmd
More file actions
129 lines (97 loc) · 3.3 KB
/
2026-03-09_swan.qmd
File metadata and controls
129 lines (97 loc) · 3.3 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
---
title: 天鹅和倒影
subtitle: 天鹅和水波中的扭曲且有趣的倒影
date: 2026-03-10
toc-depth: 4
toc-expand: true
lang: en
---
## 1. 在玛纳斯国家湿地公园拍到了天鹅
<div style="text-align: center;">
{style="border-radius: 8px; width: 100%;"}
天鹅湖(拍摄于2026-02-17)
</div>
## 2. 玛纳斯国家湿地公园的位置
``` {r}
#| message: false
sf |> library()
ggplot2 |> library()
ggtext |> library()
# Read the shapefile of Xinjiang
xinjiang <- "raw_data/新疆维吾尔自治区_市2.shp" |>
sf::read_sf()
# Set the position of 新疆玛纳斯国家湿地公园
wetland_park_location <- data.frame(
x = 86.10,
y = 44.25,
z = "新疆玛纳斯国家湿地公园"
)
xinjiang |> ggplot() +
geom_sf() +
geom_point(
data = wetland_park_location,
aes(x = x, y = y),
color = "red",
size = 2
) +
labs(
x = "经度/longitude",
y = "纬度/latitude",
caption = "坐标来源:\nhttps://www.cj.gov.cn/p1/dfxfg/20170801/190939.html?source=zzb",
title = "**玛纳斯国家湿地公园**位于<span style='color: red;'>红点</span>所示位置"
) +
theme_void() +
theme(
plot.title = ggtext::element_markdown()
)
"images/2026-03-10_wetland-position.png" |>
ggsave(bg = "white")
```
## 3. 给离镜头最近的天鹅来个特写
QuPath建立project → 添加图片 → 就该天鹅画一个矩形注释框 → 导出该矩形注释框的图片。
<div style="text-align: center;">
{style="width: 50%; border-radius: 8px;"}
倒影很有意思
</div>
在QuPath → Classify → Pixel classification来选中天鹅和其倒影 → brush修补生成的annotation → 导出天鹅及其倒影。
<div style="text-align: center;">
{style="width: 50%; border: 1px solid gray; border-radius: 8px;"}
</div>
下面是groovy code:
```
// QuPath v0.7.0
/**
* This exports the selected annotation and its ROI to ImageJ,
* clears outside, and saves the output in a folder
* called swan within your QuPath project.
*/
import ij.IJ
import qupath.lib.regions.RegionRequest
import qupath.imagej.tools.IJTools
def name = getCurrentImageNameWithoutExtension()
// Create output folder
outputPath = buildFilePath(PROJECT_BASE_DIR, "swan")
mkdirs(outputPath)
def imageData = getCurrentImageData()
def server = imageData.getServer()
def downsample = 1 // if the image is large, it could be enlarged
def anno = getSelectedObject()
def roi = anno.getROI()
// Request the region
def request = RegionRequest.createInstance(server.getPath(), downsample, roi)
// Extract the region as an ImageJ ImagePlus
def imp = IJTools.convertToImagePlus(server, request).getImage()
// Convert the QuPath ROI into an ImageJ
def ijRoi = IJTools.convertToIJRoi(roi, request)
imp.setRoi(ijRoi)
IJ.setBackgroundColor(255, 255, 255)
IJ.run(imp, "Clear Outside", "")
def nameExportSwan = name + "_swan" + ".png"
// Export the image with IJ
pathExport = buildFilePath(outputPath, nameExportSwan)
IJ.saveAs(imp, "png", pathExport)
println "Done! Image saved at: " + outputPath
```
Groovy代码参考自[@Isaac2025]并做小部分修改。
[给我买杯茶🍵](给我买杯茶.qmd)
## References