Skip to content

Commit

Permalink
Allow to switch off automatic iris and pupil detection
Browse files Browse the repository at this point in the history
  • Loading branch information
jeisfeld committed Feb 28, 2016
1 parent cbb1f02 commit 304c2ab
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import android.util.SparseArray;

import de.jeisfeld.augendiagnoselib.Application;
import de.jeisfeld.augendiagnoselib.R;
import de.jeisfeld.augendiagnoselib.util.PreferenceUtil;

/**
* Class that serves to detect the pupil and iris within an eye photo.
Expand Down Expand Up @@ -291,6 +293,10 @@ public PupilAndIrisDetector(final Bitmap image) {
* @param imagePath The path of the image.
*/
public static final void determineAndStoreIrisPosition(final String imagePath) {
if (!PreferenceUtil.getSharedPreferenceBoolean(R.string.key_automatic_iris_detection)) {
return;
}

JpegMetadata origMetadata = JpegSynchronizationUtil.getJpegMetadata(imagePath);
if (origMetadata == null
|| origMetadata.hasOverlayPosition() && !origMetadata.hasFlag(JpegMetadata.FLAG_OVERLAY_SET_BY_CAMERA_ACTIVITY)) {
Expand Down Expand Up @@ -470,7 +476,7 @@ private void refinePupilPosition(final int resolution) {

isStable = bestPupilCenter == null
|| (bestPupilCenter.mXCenter == pupilXCenter && bestPupilCenter.mYCenter == pupilYCenter
&& bestPupilCenter.mPupilRadius == pupilRadius);
&& bestPupilCenter.mPupilRadius == pupilRadius);
if (bestPupilCenter != null) {
pupilXCenter = bestPupilCenter.mXCenter;
pupilYCenter = bestPupilCenter.mYCenter;
Expand Down Expand Up @@ -545,11 +551,11 @@ private static final class PupilCenterInfo {
/**
* Create a PupilCenterInfo with certain coordinates.
*
* @param image the image.
* @param image the image.
* @param pixels the image pixels.
* @param xCoord The x coordinate.
* @param yCoord The y coordinate.
* @param phase The phase in which the info is used.
* @param phase The phase in which the info is used.
*/
private PupilCenterInfo(final Bitmap image, final int[] pixels, final int xCoord, final int yCoord, final Phase phase) {
mXCenter = xCoord;
Expand Down Expand Up @@ -600,7 +606,7 @@ private static int getBrightness(final int color) {
/**
* Add pixel info for another pixel.
*
* @param distance The distance of the pixel.
* @param distance The distance of the pixel.
* @param brightness The brightness of the pixel.
*/
private void addInfo(final int distance, final int brightness) {
Expand Down Expand Up @@ -657,13 +663,13 @@ private void calculateStatistics(final int baseRadius) {
for (int j = 1; j <= maxLeapDistance; j++) {
float diff = mPhase == Phase.INITIAL
? (ASSUMED_PUPIL_BRIGHTNESS + getMinMaxQuantile(MAX_BLACK_QUOTA, i + j, i + j + maxLeapDistance, false))
/ (ASSUMED_PUPIL_BRIGHTNESS
+ getMinMaxQuantile(MIN_BLACK_QUOTA, i - j - Math.min(maxLeapDistance, Math.max(j, 2)), i - j, true))
- 1
/ (ASSUMED_PUPIL_BRIGHTNESS
+ getMinMaxQuantile(MIN_BLACK_QUOTA, i - j - Math.min(maxLeapDistance, Math.max(j, 2)), i - j, true))
- 1
: (ASSUMED_PUPIL_BRIGHTNESS + getMinMaxQuantile(MAX_BLACK_QUOTA, i + j, i + j + maxLeapDistance, false))
/ (ASSUMED_PUPIL_BRIGHTNESS
+ getMinMaxQuantile(MIN_BLACK_QUOTA, i - Math.min(maxLeapDistance, Math.max(j, 2)), i, true))
- 1;
/ (ASSUMED_PUPIL_BRIGHTNESS
+ getMinMaxQuantile(MIN_BLACK_QUOTA, i - Math.min(maxLeapDistance, Math.max(j, 2)), i, true))
- 1;
if (diff > MIN_LEAP_DIFF) {
// prefer big jumps in small radius difference.
float newLeapValue = (float) (diff / Math.pow(j, 0.8)); // MAGIC_NUMBER
Expand Down Expand Up @@ -754,10 +760,10 @@ private void calculateStatistics(final int baseRadius) {
/**
* Get the minimum p-quantile for a certain set of radii.
*
* @param p The quantile parameter.
* @param p The quantile parameter.
* @param fromRadius The start radius.
* @param toRadius The end radius.
* @param max if true, the maximum is returned, otherwise the minimum.
* @param toRadius The end radius.
* @param max if true, the maximum is returned, otherwise the minimum.
* @return The minimum quantile.
*/
private float getMinMaxQuantile(final float p, final int fromRadius, final int toRadius, final boolean max) {
Expand Down Expand Up @@ -887,10 +893,10 @@ private static final class IrisBoundary {
/**
* Initialize the IrisBoundary.
*
* @param image The image.
* @param image The image.
* @param xCenter the initial x coordinate of the center.
* @param yCenter the initial y coordinate of the center.
* @param radius the initial iris radius.
* @param radius the initial iris radius.
*/
private IrisBoundary(final Bitmap image, final int xCenter, final int yCenter, final int radius) {
mImage = image;
Expand Down Expand Up @@ -933,7 +939,7 @@ private boolean determineBoundaryPoints(final int yCoord) {
/**
* Determine the boundary points for a certain y coordinate.
*
* @param yCoord The y coordinate for which to find the boundary points.
* @param yCoord The y coordinate for which to find the boundary points.
* @param xDistanceRange the horizontal range which is considered.
* @return true if a boundary point has been found.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<string name="message_dialog_no_hints_will_be_shown">Die App wird keine der bestehenden Tipps anzeigen. Falls zukünftige App-Versionen neue Tipps enthalten, werden diese angezeigt.</string>
<string name="message_dialog_triggering_purchase">Starte Kauf bei Google Play&#8230;</string>
<string name="message_guide_resize_iris">Bitte bewegen Sie das Auge, bis die Iris den Kreis ausfüllt. Dann drücken Sie „OK“.</string>
<string name="message_guide_resize_pupil">Vergrößern Sie nun das Auge, bis die Pupille den Kreis ausfüllt. Dann drücken Sie „OK“.</string>
<string name="message_guide_resize_pupil">Verändern Sie nun die Größe des Auges, bis die Pupille den Kreis ausfüllt. Dann drücken Sie „OK“.</string>
<string name="imageinfo_line_filename">Dateiname:</string>
<string name="imageinfo_line_filedate">Dateidatum:</string>
<string name="imageinfo_line_name">Name:</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<string name="pref_title_sort_by_last_name">Sortieren nach Nachname</string>
<string name="pref_title_guided_topo_setup">Angeleitete Einrichtung von Iris- und Pupillenposition</string>
<string name="pref_title_store_options">Speichern von Daten in JPG-Dateien</string>
<string name="pref_title_automatic_iris_detection">Automatische Iris-Erkennung</string>
<string name="pref_title_full_resolution">Anzeige in voller Auflösung</string>
<string name="pref_title_overlay_color">Standardfarbe für Overlays</string>
<string name="pref_title_language">Sprache</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<string name="pref_title_sort_by_last_name">Ordenar por apellido</string>
<string name="pref_title_guided_topo_setup">Configuración guiada de iris y pupila</string>
<string name="pref_title_store_options">Guardar datos adicionales en JPG</string>
<string name="pref_title_automatic_iris_detection">Detección automática del iris</string>
<string name="pref_title_full_resolution">Mostrar imagen en alta resolución</string>
<string name="pref_title_overlay_color">Color predeterminado de superposiciones</string>
<string name="pref_title_language">Idioma</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<string name="pref_default_guided_topo_setup" translatable="false">true</string>
<string name="pref_title_store_options">Save additional data in jpeg</string>
<string name="pref_default_store_options" translatable="false">2</string>
<string name="pref_title_automatic_iris_detection">Automatic detection of iris</string>
<string name="pref_default_automatic_iris_detection" translatable="false">true</string>
<string name="pref_title_full_resolution">Show image in full resolution</string>
<string name="pref_title_overlay_color">Default overlay color</string>
<string name="pref_title_language">Language</string>
Expand Down Expand Up @@ -140,6 +142,7 @@
<string name="key_sort_by_last_name" translatable="false">sort_by_last_name</string>
<string name="key_guided_topo_setup" translatable="false">guided_topo_setup</string>
<string name="key_store_option" translatable="false">store_option</string>
<string name="key_automatic_iris_detection" translatable="false">automatic_iris_detection</string>
<string name="key_full_resolution" translatable="false">full_resolution</string>
<string name="key_overlay_color" translatable="false">overlay_color</string>
<string name="key_language" translatable="false">language</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@
android:negativeButtonText="@null"
android:positiveButtonText="@null"
android:title="@string/pref_title_store_options"/>
<CheckBoxPreference
android:defaultValue="@string/pref_default_automatic_iris_detection"
android:key="@string/key_automatic_iris_detection"
android:title="@string/pref_title_automatic_iris_detection"/>

</PreferenceScreen>

0 comments on commit 304c2ab

Please sign in to comment.