目次
前
次
特定色抽出
特定色抽出は、R、G、Bの成分が、どの程度含まれている
のかを利用します。
特定色抽出ができると、画像中の物体の認識につながります。
白地に赤、緑、青の円を入れた画像から、赤、緑、青だけを
抽出してみると、次のようになります。
これが出来ると、色盲、色弱の人が交通信号を認識
することが可能になります。
処理内容
HSPでは、ピクセルの情報を取得するための
組込み関数ginfoがあります。
組込み関数ginfoで、赤、緑、青の成分値を取得後
比較判定で特定の色成分だけにします。
ソースコードでは、特定色を抽出していることが
わかるように、表示位置を変えています。
また、1つのサブルーチンで赤、緑、青を指定して
処理できるように工夫してあります。
--------------------------------------------------
title "select color"
; set screen dimensions
screen 0,80*2+1,60*2+1
; constants
ylast = 60
xlast = 80
; get image
picload "tsignal.bmp",1
shift = 4 : gosub *get_color_image
shift = 2 : gosub *get_color_image
shift = 1 : gosub *get_color_image
stop
*get_color_image
; line direction
for j,0,ylast,1
; pixel direction
for i,0,xlast,1
; get infosmations of current position
pget i,j
; get color
r = ginfo(16)
g = ginfo(17)
b = ginfo(18)
; default
color 0,0,0
; select
if (shift = 4) {
; set color
if ( r > g and r > b ) {
color 255,0,0
}
; calculate location
x = i+xlast+1
y = j
}
if (shift = 2) {
; set color
if ( g > r and g > b ) {
color 0,255,0
}
; calculate location
x = i
y = j+ylast+1
}
if (shift = 1) {
; set color
if ( b > r and b > g ) {
color 0,0,255
}
; calculate location
x = i+xlast+1
y = j+ylast+1
}
; show
pset x,y
next
next
return
end
--------------------------------------------------
デフォルトで、黒地に特定色を出す仕様にしましたが
color 0,0,0をcolor 255,255,255で、白地に色を浮き
上がせることもできます。
目次
前
次