我知道如何使用 gnuplot 生成图像文件的轮廓。
set autoscale noextend
set view map
set contour surface
set cntrparam levels 15
set key outside title "Contour levels"
splot 'sampleImage.png' binary filetype=png with lines nosurface title ""
图像上绘制的轮廓最多为 255,例如 255、250、245 等。如何在 gnuplot 中读取这些关键值?
答案 0 :(得分:0)
假设我正确理解了您的问题,以下代码将灰度值和轮廓值都放入表格中。在这里您可以找到所有信息。
输入: (Input.png
)
代码:
### get greyscale pixel data and contour data
reset session
FILE = 'Input.png'
set view map
set size square
set tics out
set table $Dummy
set contour
splot FILE binary filetype=png
unset contour
set table $Data
plot $Dummy u 1:2:3 index 0 w table
set table $Contour
plot $Dummy u 1:2:3 index 1::1 w table
unset table
# print a few grey values
print sprintf("Number of data points: %d",|$Data|)
do for [i=1:40000:2500] { print $Data[i] }
# print a few contour values
print sprintf("Number of contour points: %d",|$Contour|)
do for [i=700:710] { print $Contour[i] }
set multiplot layout 1,2
set autoscale noextend
splot FILE binary filetype=png with rgbimage notitle
set key outside title "Contour levels"
set contour surface
set cntrparam levels 15
splot FILE binary filetype=png with lines nosurface title ""
unset multiplot
### end of code
结果:(仅部分表格摘录)
Number of data points: 40000
0 0 4
100 12 46
0 25 4
100 37 152
0 50 6
100 62 168
0 75 19
100 87 165
0 100 30
100 112 186
0 125 31
100 137 171
0 150 22
100 162 127
0 175 11
100 187 70
Number of contour points: 1328
54.5 163 100
55 163.5 100
56 164 100
110 20 100
109 20.4 100
108 20.6 100
107 20.8333 100
106 21 100
105 21.4 100
104 21.8 100
103.5 22 100
添加:
也许这会朝着想要的方向发展。我不确定这是否是最有效的方式。
代码:
### plot normalized contour from PNG
reset session
FILE = 'Input.png'
set view map
set size square
set tics out
set table $Dummy
set contour
set cntrparam levels 15
splot FILE binary filetype=png
unset contour
set table $Contour
splot $Dummy u 1:2:($3/255) index 1::1
unset table
plot $Contour u 1:2:3 w l lc palette notitle
### end of code
结果: