From cbb1f0240d32f932464b815d96026f4da3994678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Eisfeld?= Date: Sun, 28 Feb 2016 19:19:41 +0100 Subject: [PATCH] Use SparseArray instead of Map --- .../fragments/DisplayImageFragment.java | 3 --- .../util/imagefile/PupilAndIrisDetector.java | 23 ++++++++++--------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/fragments/DisplayImageFragment.java b/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/fragments/DisplayImageFragment.java index dbd6fef4..97fdfee7 100644 --- a/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/fragments/DisplayImageFragment.java +++ b/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/fragments/DisplayImageFragment.java @@ -53,7 +53,6 @@ import de.jeisfeld.augendiagnoselib.util.SystemUtil; import de.jeisfeld.augendiagnoselib.util.imagefile.EyePhoto.RightLeft; import de.jeisfeld.augendiagnoselib.util.imagefile.JpegMetadataUtil; -import de.jeisfeld.augendiagnoselib.util.imagefile.PupilAndIrisDetector; /** * Variant of DisplayOneFragment that includes overlay handling. @@ -1079,8 +1078,6 @@ public final void initializeImages() { } else { mImageView.setImage(mFile, getActivity(), mImageIndex); - - PupilAndIrisDetector.determineAndStoreIrisPosition(mFile); } if (mImageView.getEyePhoto().getRightLeft() == null && mRightLeft != null) { diff --git a/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/util/imagefile/PupilAndIrisDetector.java b/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/util/imagefile/PupilAndIrisDetector.java index e89bce41..cdcd6575 100644 --- a/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/util/imagefile/PupilAndIrisDetector.java +++ b/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/util/imagefile/PupilAndIrisDetector.java @@ -12,6 +12,7 @@ import android.graphics.Bitmap; import android.graphics.Color; import android.util.Log; +import android.util.SparseArray; import de.jeisfeld.augendiagnoselib.Application; @@ -534,7 +535,7 @@ private static final class PupilCenterInfo { /** * The information about the circles around this point. */ - private Map mCircleInfos = new HashMap<>(); + private SparseArray mCircleInfos = new SparseArray<>(); /** * The brightness leap value for this center. @@ -618,8 +619,8 @@ private void addInfo(final int distance, final int brightness) { */ private void calculateStatistics(final int baseRadius) { // Base calculations for each circle. - for (CircleInfo circleInfo : mCircleInfos.values()) { - circleInfo.calculateStatistics(); + for (int i = 0; i < mCircleInfos.size(); i++) { + mCircleInfos.valueAt(i).calculateStatistics(); } int resolution = Math.max(mImage.getWidth(), mImage.getHeight()); @@ -634,7 +635,7 @@ private void calculateStatistics(final int baseRadius) { float[] innerDarkness = new float[mCircleInfos.size()]; for (int i = minRadius; i <= maxRadius; i++) { - float currentQuantile = mCircleInfos.get(Integer.valueOf(i)).getQuantile(MIN_BLACK_QUOTA); + float currentQuantile = mCircleInfos.get(i).getQuantile(MIN_BLACK_QUOTA); innerQuantileSum += currentQuantile * i; innerDarkness[i] = i == 0 ? 0 : 2 * innerQuantileSum / (i * (i + 1)); } @@ -672,7 +673,7 @@ private void calculateStatistics(final int baseRadius) { } } if (pupilLeapValue > 0) { - CircleInfo circleInfo = mCircleInfos.get(Integer.valueOf(i)); + CircleInfo circleInfo = mCircleInfos.get(i); // prefer big, dark circles circleInfo.mPupilLeapValue = (float) (Math.sqrt(i) * pupilLeapValue / innerDarkness[i]); relevantPupilCircles.add(circleInfo); @@ -689,10 +690,10 @@ private void calculateStatistics(final int baseRadius) { Math.min(i, mCircleInfos.size() - 1 - i)); for (int j = 1; j <= maxLeapDistance; j++) { irisQuantileSum += - (mCircleInfos.get(Integer.valueOf(i + j)).getQuantile(1 - MIN_WHITE_QUOTA) - - mCircleInfos.get(Integer.valueOf(i - j)).getQuantile(1 - MIN_WHITE_QUOTA) - + mCircleInfos.get(Integer.valueOf(i + j)).getQuantile(1 - MIN_WHITE_QUOTA2) - - mCircleInfos.get(Integer.valueOf(i - j)).getQuantile(1 - MIN_WHITE_QUOTA2)) + (mCircleInfos.get(i + j).getQuantile(1 - MIN_WHITE_QUOTA) + - mCircleInfos.get(i - j).getQuantile(1 - MIN_WHITE_QUOTA) + + mCircleInfos.get(i + j).getQuantile(1 - MIN_WHITE_QUOTA2) + - mCircleInfos.get(i - j).getQuantile(1 - MIN_WHITE_QUOTA2)) / (2 * Math.sqrt(j)); if (irisQuantileSum > 0) { // prefer big jumps in small radius difference. @@ -703,7 +704,7 @@ private void calculateStatistics(final int baseRadius) { } } if (irisLeapValue > 0) { - CircleInfo circleInfo = mCircleInfos.get(Integer.valueOf(i)); + CircleInfo circleInfo = mCircleInfos.get(i); // prefer big radius in order to prevent selection of small spots. // prefer dark inner area circleInfo.mIrisLeapValue = irisLeapValue; @@ -762,7 +763,7 @@ private void calculateStatistics(final int baseRadius) { private float getMinMaxQuantile(final float p, final int fromRadius, final int toRadius, final boolean max) { float result = max ? Float.MIN_VALUE : Float.MAX_VALUE; for (int radius = fromRadius; radius <= toRadius; radius++) { - float newValue = mCircleInfos.get(Integer.valueOf(radius)).getQuantile(p); + float newValue = mCircleInfos.get(radius).getQuantile(p); if ((!max && newValue < result) || (max && newValue > result)) { result = newValue; }