Histogram Package

画像のヒストグラム表示を手助けするための拡張パッケージです。
画像からRGBとHLS(HBS)の度数分布を調べます。

サンプルのスクリーンショット

ヒストグラム

仕様

::histogram::count photo
    Tkのphotoから度数分布を調べます。

::histogram::get red
    RGBの赤(0〜255)の度数分布データをリストで返します。

::histogram::get green
    RGBの緑(0〜255)の度数分布データをリストで返します。

::histogram::get blue
    RGBの青(0〜255)の度数分布データをリストで返します。

::histogram::get hue
    HLSの色相(色合い)(0〜255)の度数分布データをリストで返します。

::histogram::get luminance
    HLSの明度(明るさ)(0〜255)の度数分布データをリストで返します。

::histogram::get saturation
    HLSの彩度(鮮やかさ)(0〜255)の度数分布データをリストで返します。

ライセンス

Histogram拡張パッケージはフリーソフトウェアです。
GNU Lesser General Public Licenseが定める条項に従って本プログラムを再頒布または変更することができます。

ダウンロード

こちらからダウンロードできます。(フリーです。)

バイナリ: histogram10.zip

ソース: histogram10src.zip

今のところ、Windows 95/98/Me/NT4.0/2000で動作します。
動作させるには、Tcl/Tk8.1以上が必要です。

サンプル

#
# histogram sample
#
package require Img
package require BLT
namespace import blt::*
package require histogram

option add *Font {{MS Pゴシック} 10}
wm title . Histogram

option add *graph.red.Color red
option add *graph.green.Color green
option add *graph.blue.Color blue
option add *graph.hue.Color cyan
option add *graph.luminance.Color yellow
option add *graph.saturation.Color magenta
option add *graph.red.Symbol ""
option add *graph.green.Symbol ""
option add *graph.blue.Symbol ""
option add *graph.hue.Symbol ""
option add *graph.luminance.Symbol ""
option add *graph.saturation.Symbol ""
option add *graph.activeLine.Color yellow
option add *graph.activeLine.Symbol circle
option add *graph.Legend.ActiveBackground yellow

proc openimg {} {
    global xdata
    set types {
	{{JPEG Files} {.jpg .jpeg}}
	{{GIF Files} {.gif}}
	{{BMP Files} {.bmp}}
	{{All FIles} *}
    }
    set file [tk_getOpenFile -defaultextension .jpg -filetypes $types -title Open]
    if {$file != ""} {
	catch {image delete img}
	image create photo img -file $file

	histogram::count img

	catch {.graph element delete red green blue hue luminance saturation}
	.graph element create red -xdata $xdata -ydata [histogram::get red]
	.graph element create green -xdata $xdata -ydata [histogram::get green]
	.graph element create blue -xdata $xdata -ydata [histogram::get blue]
	.graph element create hue -xdata $xdata -ydata [histogram::get hue]
	.graph element create luminance -xdata $xdata -ydata [histogram::get luminance]
	.graph element create saturation -xdata $xdata -ydata [histogram::get saturation]
    }
}

set xdata {}
for {set i 0} {$i < 256} {incr i} {
    lappend xdata $i
}

pack [button .b -text Open... -command openimg] -anchor w
pack [graph .graph -width 5i -height 2i] -fill both -expand 1

Blt_ZoomStack .graph
Blt_Crosshairs .graph
Blt_ActiveLegend .graph
Blt_ClosestPoint .graph

.graph element bind all <Enter> {
    %W legend activate [%W element get current]
}

.graph element bind all <Leave> {
    %W legend deactivate [%W element get current]
}

参考文献


Satoshi Imai
[HOME]