TreeRings (dendroecology)
Challenge: count tree rings from a photo.
Device: Android mobile (no server backend processing)
Goog Play Store: https://play.google.com/store/apps/details?id=com.ctyeung.treerings
Application Workflow
Camera/Gallery -> Photo -> Sobel Edge Detection -> User Selects Path -> Count Intersections -> Render
Navigation Graph
Camera/Gallery -> Photo
Select and preview your tree ring image.
Edge Detection (Sobel Operators)
User should select the best threshold value from slider for best edge detection.
Default value = 30 in range 0 - 255.
The image process steps are convolution -> threshold -> merge (source + highlighted edges).
Convolution with 1st derivative sobel operators on x, y, 45 degree axis.
Kernel is 3x3 where x-sobel values = 0, 1, -1
User Selects Path
Find the best cross-section to count your tree rings.
(Try to draw a path that is 'normal' tangent across all rings)
- Touch point #1 : center of tree rings.
- Touch point #2 : most outer ring position.
- Touch any point : update/correct #1 or #2 (line)
- Next : navigate to detail screen.
UserLine Intersects Rings (Derivative pixels)
Ok, there is some correction to be done in scaling user line coordinates in raster space.
Black line is a rendering in pixels; black should line up with blue line.
Count Intersections
Current algorithm is simply a 1st derivative to detect the transition of ring color.
Some noise is removed by accepting only low->high transition (no high->high, high->low).
Work in Progress
- Scale image to fit screen.
- Higher resolution image.
- Image Processing, identify rings from pixels.
- Highlight configuration / colors.
- About page.
- Progress bar
Configuration Details
JNI Configuration
Below addition is CRITICAL to JNI referencing to C++ classes.
Please consider the file, ../src/CMakeList.txt \
add_library( # Sets the name of the library. native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
+ Convolution.cpp
native-lib.cpp)
target_link_libraries( # Specifies the target library.
native-lib
+ -ljnigraphics
Version
Version 2.0 on Google Play
- Main Page: add background image and instruction.
- Count Page: add white background to count value - legibility.
Version 3.0 on Google Play
- Draw Line Page: draw normal lines in tangent to user's specified line (previous horizontal).
Substitude into distance equation: [7]
Version 4.0 on Google Play
- Portrait mode only - so image does not get lost.
Sample Images (dev/test)
A collection of photos are available in sub-directory /photos.
Many thanks to Earl 'Bud' Reaves, Maryland County Forester, for photos: bud1-4.
All others are 'borrowed' on the world-wide-web.
Only low resolution version of 'borrowed' images have been used thus far.
Look forward to expanding as better algorithm is devised.
Inspiration
Earl 'Bud' Reaves
After seeing many of his Facebook posts, I was intrigued by his deligence, tracking tree age for studies.
The prospect of automating the process might be helpful ?
Even a quick estimate on the field might be useful ?
Stuart Dahlberg
Stu was a mentor and colleague in my early career, 1994.
Stu once showed me a pine tree cross section while pointing out the rings and said,
"However slow or fast, every living thing must grow.
The moment growth ceases, it is dead."
Stu was 52 when he and spouse perished on a plane crash, 2012.
https://www.legacy.com/obituaries/sctimes/obituary.aspx?n=stuart-and-ivelisse-dahlberg&pid=156721789&fhid=12808
References
-
Android10CameraBasics - C.T. Yeung
https://github.com/yeuchi/Android10CameraBasic -
NDKExercise - C.T. Yeung
https://github.com/yeuchi/NDKExercise -
Get started with the Navigation component
https://developer.android.com/guide/navigation/navigation-getting-started Android mobile for counting tree rings. -
Codepath: Accessing the Camera and Stored Media
https://guides.codepath.com/android/Accessing-the-Camera-and-Stored-Media -
Custom View in Android with Kotlin by Antonio Leiva
https://antonioleiva.com/custom-views-android-kotlin/ -
Sample tree cross section images (bud1-4), by Earl Bud Reaves, County Forester, Anne Arundel County, MD
-
Mathematics: "How do I find a point a given distance from another point along a line?" by John Douma, June 2, 2013
https://math.stackexchange.com/questions/409689/how-do-i-find-a-point-a-given-distance-from-another-point-along-a-line/409721