# Tree Rings- automatically counting on photo of trunk csa.

An attempt to count annual growth rings from a photo.
```
WindowWidth  =1008
WindowHeight = 750

nomainwin

dim pixels( 1000), integral( 1000)

graphicbox  #w.gb,  1, 1, 1001, 702

open "Tree Ring counter" for window as #w

#w  "trapclose [quit]"

handleg  =hwnd( #w.gb)
calldll  #user32, "GetDC", handleg as ulong, hDC as ulong

#w.gb "down ; drawbmp scr 1 1 ; flush ; size 2"

y           =440

for x =85 to 935
calldll #gdi32, "GetPixel", hDC as ulong, x as long, y as long, pixcol as ulong
bl = int(  pixcol /( 256*256)): gr = int( (pixcol -bl *256*256) / 256): re = int(  pixcol -bl *256*256 -gr *256)

if pixcol <>2^24 -1 then pixels( x)  =( re +gr +bl) /3 else pixels( x) =0

integral( x) =integral( x -1) +pixels( x)

#w.gb "color white ; set "; x; " "; y
next x

#w.gb "color cyan"

totalIntegral =integral( 935)
vold =0

#w.gb "up ; goto 0 430 ; down"

for x =86 to 934
'#w.gb "color darkblue ; set "; x; " "; 430 -int( pixels( x) /4)
v      =int( integral( x +1) -x /1000 *totalIntegral)
if v >vold then #w.gb "color white ; set "; x; " "; 440 else #w.gb "color black ; set "; x; " "; 440
vold =v
next x

#w.gb "font arial 24"
#w.gb "up ; goto 40 412 ; down"
#w.gb "\"; str\$( int( age2 /4))

#w.gb "getbmp scr 1 1 1000 702"
bmpsave "scr", "ringStats6.bmp"

wait

[quit]
close #w
callDll #user32, "ReleaseDC", handleg as ulong, hDC as ulong, result as ushort
end
```