/TreeRings

Android mobile for counting tree rings.

Primary LanguageCMake

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

Screen Shot 2020-10-29 at 3 49 02 AM

Camera/Gallery -> Photo

Select and preview your tree ring image.

  1. Camera : take a photo.
  2. Gallery : pick a photo from gallery.
  3. Next : navigate to next screen.
    starter

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)

  1. Touch point #1 : center of tree rings.
  2. Touch point #2 : most outer ring position.
  3. Touch any point : update/correct #1 or #2 (line)
  4. 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

  1. Scale image to fit screen.
  2. Higher resolution image.
  3. Image Processing, identify rings from pixels.
  4. Highlight configuration / colors.
  5. About page.
  6. 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

Screen Shot 2020-10-25 at 2 56 56 PM

Version 2.0 on Google Play

  1. Main Page: add background image and instruction.
  2. Count Page: add white background to count value - legibility.

Version 3.0 on Google Play

  1. Draw Line Page: draw normal lines in tangent to user's specified line (previous horizontal).

Slope intercept: [7]

Substitude into distance equation: [7]

Version 4.0 on Google Play

  1. 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.

bud1-4

borrowed

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

  1. Android10CameraBasics - C.T. Yeung
    https://github.com/yeuchi/Android10CameraBasic

  2. NDKExercise - C.T. Yeung
    https://github.com/yeuchi/NDKExercise

  3. Get started with the Navigation component
    https://developer.android.com/guide/navigation/navigation-getting-started Android mobile for counting tree rings.

  4. Codepath: Accessing the Camera and Stored Media
    https://guides.codepath.com/android/Accessing-the-Camera-and-Stored-Media

  5. Custom View in Android with Kotlin by Antonio Leiva
    https://antonioleiva.com/custom-views-android-kotlin/

  6. Sample tree cross section images (bud1-4), by Earl Bud Reaves, County Forester, Anne Arundel County, MD

  7. 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