Skip to content

Commit

Permalink
Use SparseArray instead of Map<Integer>
Browse files Browse the repository at this point in the history
  • Loading branch information
jeisfeld committed Feb 28, 2016
1 parent d0e370d commit cbb1f02
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1079,8 +1078,6 @@ public final void initializeImages() {
}
else {
mImageView.setImage(mFile, getActivity(), mImageIndex);

PupilAndIrisDetector.determineAndStoreIrisPosition(mFile);
}

if (mImageView.getEyePhoto().getRightLeft() == null && mRightLeft != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -534,7 +535,7 @@ private static final class PupilCenterInfo {
/**
* The information about the circles around this point.
*/
private Map<Integer, CircleInfo> mCircleInfos = new HashMap<>();
private SparseArray<CircleInfo> mCircleInfos = new SparseArray<>();

/**
* The brightness leap value for this center.
Expand Down Expand Up @@ -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());
Expand All @@ -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));
}
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit cbb1f02

Please sign in to comment.