私の好きな無料のユーティリティのうちの2つ、pythonとgnuplotを使用して、2つの動作で答えを出します。
私が教えてくれる大学院生として、無料で使おうと思えば、使い方を学ぶことができる最も汎用性の高いツールの1つです。
はここ(黒は白のための0から255まで)のグレースケール値をカウント、最初の部分をするPythonスクリプトです:
#!/usr/bin/python
import Image # basic image processing/manipulation, just what we want
im = Image.open('img.png') # open the image file as a python image object
with open('data.dat', 'w') as f: # open the data file to be written
for i in range(im.size[0]): # loop over columns
counter = sum(im.getpixel((i,j)) for j in range(im.size[1]))
f.write(str(i)+'\t'+str(counter)+'\n') # write to data file
衝撃的無痛!あなたは(私はimg.png
として保存XKCDコミック、この場合には)プロットしたい画像と同じディレクトリに保存し、これらのスクリプトを実行するには
#!/usr/bin/gnuplot
set terminal pngcairo size 925,900
set output 'plot.png'
#set terminal pdfcairo
#set output 'plot.pdf'
set multiplot
## first plot
set origin 0,0.025 # this plot will be on the bottom
set size 1,0.75 # and fill 3/4 of the whole canvas
set title "Black count in XKCD 'Self-Description'"
set xlabel 'Column'
set ylabel "Black\ncount" norotate offset screen 0.0125
set lmargin at screen 0.15 # make plot area correct size
set rmargin at screen 0.95 # width = 740 px = (0.95-0.15)*925 px
set border 0 # these settings are just to make the data
set grid # stand out and not overlap with the tics, etc.
set tics nomirror
set xtics scale 0.5 out
set ytics scale 0
set xr [0:740] # x range such that there is one spike/pixel
## uncomment if gnuplot version >= 4.6.0
## this will autoset the x and y ranges
#stats 'data.dat'
#set xr [STATS_min_x:STATS_max_x+1]
#set yr [STATS_min_y:STATS_may_y]
plot 'data.dat' with impulse notitle lc 'black'
## second plot
set origin 0,0.75 # this plot will be on top
set size 1,0.25 # and fill 1/4 of the canvas
unset ylabel; unset xlabel # clean up a bit...
unset border; unset grid; unset tics; unset title
set size ratio -1 # ensures image proper ratio
plot 'img.png' binary filetype=png with rgbimage
unset multiplot # important to unset multiplot!
:今すぐヒストグラム*を作るGNUPLOT持っています。それらを実行可能にする。 (のpython +画像モジュール+ gnuplotがすべてインストールされている場合)はbashで、これが次に
$ chmod 755 grayscalecount.py plot.plt
である、あなたは、私が得るのgnuplot 4.4.3でのUbuntu 11.10を実行している、私のコンピュータ上で
$ ./grayscalecount.py
$ ./plot.plt
を実行することができます最後に、このクールなプロット:
**サイドノート*:作ることができるのgnuplot異なるヒストグラムプロットが多いです。私はこのスタイルがデータをうまく披露したと思ったが、gnuplot histogramsのデータを整形することができます。
pythonをプロットする方法はたくさんありますが、gnuplot(matplotlib、pygnuplot、gnuplot-py)を使ってプロットすることもできますが、私はそれらのものと同じではありません。 Gnuplotはプロットのために素晴らしいスクリプトであり、Python、Bash、C++などでうまく動作させる方法はたくさんあります。
Python(およびImageモジュール)はありますか? – andyras
無料であれば入手できます。私は何年も前にPythonを学習しようとしましたが、文法のどれもが何の問題もなくなりませんでした。これは私の最初のプロジェクトです( 'python'を入力すると、私は' >>> 'プロンプトになります)。 – user1717828
OK、クール。あなたはどのOSを使用していますか? – andyras