Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/.codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
coverage:
status:
project:
default:
target: 80%
patch:
default:
target: auto
threshold: 5%
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ dependencies {
exclude group: 'org.hamcrest'
}

// https://mvnrepository.com/artifact/nl.jqno.equalsverifier/equalsverifier
testImplementation 'nl.jqno.equalsverifier:equalsverifier:3.10.1'

// Hamcrest https://mvnrepository.com/artifact/org.hamcrest/hamcrest
testImplementation 'org.hamcrest:hamcrest:2.2'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import java.nio.file.Paths;
import java.util.*;
import java.util.prefs.Preferences;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -533,7 +532,7 @@ public void onRegisterPreviousImageFileRequested() {
}

/**
* Handles the event of the user committing a object category name edit. Names of categories are allowed
* Handles the event of the user committing an object category name edit. Names of categories are allowed
* to be changed by the user as long as the uniqueness of category-names is not violated, otherwise an error dialog
* will be displayed and the edit will be reverted.
*
Expand Down Expand Up @@ -1260,7 +1259,7 @@ private List<File> getImageFilesFromDirectory(File directory) throws IOException
return imageFiles.map(file -> new File(file.toString()))
.filter(File::isFile)
.sorted(Comparator.comparing(File::getName))
.collect(Collectors.toList());
.toList();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ public void updateFromImageAnnotationData(ImageAnnotationData imageAnnotationDat
IOResult.OperationType operationType) {
final Map<String, Integer> updatedCategoryNameToBoundingShapeCountMap =
createMergedCategoryToBoundingShapeCountMap(
imageAnnotationData.getCategoryNameToBoundingShapeCountMap());
updateObjectCategoriesFromData(imageAnnotationData.getCategoryNameToCategoryMap());
imageAnnotationData.categoryNameToBoundingShapeCountMap());
updateObjectCategoriesFromData(imageAnnotationData.categoryNameToCategoryMap());
categoryToAssignedBoundingShapesCount.putAll(updatedCategoryNameToBoundingShapeCountMap);
updateImageAnnotations(imageAnnotationData.getImageAnnotations(), operationType);
updateImageAnnotations(imageAnnotationData.imageAnnotations(), operationType);
}

/**
Expand Down Expand Up @@ -443,7 +443,7 @@ public boolean containsCategories() {
}

/**
* Returns the the currently set image-files as an unmodifiable list.
* Returns the currently set image-files as an unmodifiable list.
*
* @return the image-file list
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*
* @see BoundingShapeData#setParts(List)
*/
public class BoundingBoxData extends BoundingShapeData {
public final class BoundingBoxData extends BoundingShapeData {
@SerializedName("bndbox")
private final Bounds relativeBoundsInImage;

Expand Down Expand Up @@ -149,18 +149,21 @@ public boolean equals(Object o) {
if(this == o) {
return true;
}
if(!(o instanceof BoundingBoxData)) {
if(!(o instanceof BoundingBoxData that)) {
return false;
}
if(!super.equals(o)) {
return false;
}
BoundingBoxData that = (BoundingBoxData) o;

if(relativeBoundsInImage == that.relativeBoundsInImage) {
return true;
}

if(relativeBoundsInImage == null || that.relativeBoundsInImage == null) {
return false;
}

return MathUtils.doubleAlmostEqual(relativeBoundsInImage.getMinX(), that.relativeBoundsInImage.getMinX()) &&
MathUtils.doubleAlmostEqual(relativeBoundsInImage.getMinY(), that.relativeBoundsInImage.getMinY()) &&
MathUtils.doubleAlmostEqual(relativeBoundsInImage.getMaxX(), that.relativeBoundsInImage.getMaxX()) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*
* @see BoundingShapeData#setParts(List)
*/
public class BoundingPolygonData extends BoundingShapeData {
public final class BoundingPolygonData extends BoundingShapeData {
@SerializedName("polygon")
private final List<Double> relativePointsInImage;

Expand Down Expand Up @@ -97,20 +97,22 @@ public boolean equals(Object o) {
return true;
}

if(!(o instanceof BoundingPolygonData)) {
if(!(o instanceof BoundingPolygonData that)) {
return false;
}

if(!super.equals(o)) {
return false;
}

BoundingPolygonData that = (BoundingPolygonData) o;

if(relativePointsInImage == that.relativePointsInImage) {
return true;
}

if((relativePointsInImage == null) || (that.relativePointsInImage == null)) {
return false;
}

if(relativePointsInImage.size() != that.relativePointsInImage.size()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ public boolean equals(Object o) {
return true;
}

if(!(o instanceof BoundingShapeData)) {
if(!(o instanceof BoundingShapeData that)) {
return false;
}

BoundingShapeData that = (BoundingShapeData) o;

return Objects.equals(category, that.category) &&
Objects.equals(tags, that.tags) &&
Objects.equals(parts, that.parts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,11 @@
/**
* Holds {@link ImageAnnotation}s and shape count data.
*/
public class ImageAnnotationData {
private final Collection<ImageAnnotation> imageAnnotations;
private final Map<String, Integer> categoryNameToBoundingShapeCountMap;
private final Map<String, ObjectCategory> categoryNameToCategoryMap;

/**
* Creates a new image annotation data object.
*
* @param imageAnnotations the collection of {@link ImageAnnotation}s
* @param categoryNameToBoundingShapeCountMap a map that maps category names to the number of assigned shapes
* @param categoryNameToCategoryMap a map that maps category names to {@link ObjectCategory} objects
*/
public ImageAnnotationData(Collection<ImageAnnotation> imageAnnotations,
Map<String, Integer> categoryNameToBoundingShapeCountMap,
Map<String, ObjectCategory> categoryNameToCategoryMap) {
this.imageAnnotations = imageAnnotations;
this.categoryNameToBoundingShapeCountMap = categoryNameToBoundingShapeCountMap;
this.categoryNameToCategoryMap = categoryNameToCategoryMap;
}
public record ImageAnnotationData(Collection<ImageAnnotation> imageAnnotations,
Map<String, Integer> categoryNameToBoundingShapeCountMap,
Map<String, ObjectCategory> categoryNameToCategoryMap) {

public static ImageAnnotationData empty() {
return new ImageAnnotationData(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap());
}

/**
* Returns the image annotations.
*
* @return the image annotations
*/
public Collection<ImageAnnotation> getImageAnnotations() {
return imageAnnotations;
}

/**
* Returns the category to assigned shapes count map.
*
* @return the map
*/
public Map<String, Integer> getCategoryNameToBoundingShapeCountMap() {
return categoryNameToBoundingShapeCountMap;
}

/**
* Returns the category-name to category object map.
*
* @return the map
*/
public Map<String, ObjectCategory> getCategoryNameToCategoryMap() {
return categoryNameToCategoryMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* Holds metadata information about an image.
*/
public class ImageMetaData {
public final class ImageMetaData {
private static final List<String> supportedImageFormats = List.of("jpeg", "bmp", "png");
private static final String NOT_AN_IMAGE_FILE_ERROR_MESSAGE = "Not an image file.";
private static final String UNSUPPORTED_IMAGE_FORMAT_ERROR_MESSAGE = "Unsupported image file format.";
Expand Down Expand Up @@ -67,7 +67,7 @@ public ImageMetaData(String fileName) {
public static ImageMetaData fromFile(File imageFile) throws IOException {
ImageDimensions imageDimensions = readImageDimensionsFromFile(imageFile);
return new ImageMetaData(imageFile.getName(), imageFile.toPath().getParent().toFile().getName(),
imageDimensions.getWidth(), imageDimensions.getHeight(), imageDimensions.getDepth());
imageDimensions.width(), imageDimensions.height(), imageDimensions.depth());
}

/**
Expand Down Expand Up @@ -126,8 +126,7 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if(obj instanceof ImageMetaData) {
ImageMetaData other = (ImageMetaData) obj;
if(obj instanceof ImageMetaData other) {
return Objects.equals(fileName, other.fileName) && Objects.equals(details, other.details);
}
return false;
Expand Down Expand Up @@ -178,44 +177,30 @@ private static ImageDimensions readImageDimensionsFromFile(File imageFile) throw
return new ImageDimensions(width, height, numComponents);
}

private static class ImageMetaDataDetails {
private final String folderName;
@SerializedName("width")
private final double imageWidth;
@SerializedName("height")
private final double imageHeight;
@SerializedName("depth")
private final int imageDepth;

ImageMetaDataDetails(String folderName, double imageWidth, double imageHeight, int imageDepth) {
this.folderName = folderName;
this.imageWidth = imageWidth;
this.imageHeight = imageHeight;
this.imageDepth = imageDepth;
}
private record ImageMetaDataDetails(String folderName, @SerializedName("width") double imageWidth,
@SerializedName("height") double imageHeight,
@SerializedName("depth") int imageDepth) {

@Override
public int hashCode() {
return Objects.hash(imageWidth, imageHeight, imageDepth);
}

@Override
public boolean equals(Object o) {
if(this == o) {
return true;
public int hashCode() {
return Objects.hash(imageWidth, imageHeight, imageDepth);
}

if(!(o instanceof ImageMetaDataDetails)) {
return false;
}
@Override
public boolean equals(Object o) {
if(this == o) {
return true;
}

ImageMetaDataDetails that = (ImageMetaDataDetails) o;
if(!(o instanceof ImageMetaDataDetails that)) {
return false;
}

return Double.compare(that.imageWidth, imageWidth) == 0 &&
Double.compare(that.imageHeight, imageHeight) == 0 &&
imageDepth == that.imageDepth;
return Double.compare(that.imageWidth, imageWidth) == 0 &&
Double.compare(that.imageHeight, imageHeight) == 0 &&
imageDepth == that.imageDepth;
}
}
}

public static class NotAnImageFileException extends RuntimeException {
private static final long serialVersionUID = 5256590447321177896L;
Expand All @@ -233,27 +218,6 @@ public UnsupportedImageFileException(String errorMessage) {
}
}

private static class ImageDimensions {
private final double width;
private final double height;
private final int depth;

ImageDimensions(double width, double height, int depth) {
this.width = width;
this.height = height;
this.depth = depth;
}

double getWidth() {
return width;
}

double getHeight() {
return height;
}

int getDepth() {
return depth;
}
private record ImageDimensions(double width, double height, int depth) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ public boolean equals(Object other) {
return true;
}

if(!(other instanceof ObjectCategory)) {
if(!(other instanceof ObjectCategory otherCategory)) {
return false;
}

final ObjectCategory otherCategory = (ObjectCategory) other;
return otherCategory.getName().equals(this.getName()) && otherCategory.getColor().equals(this.getColor());
return Objects.equals(otherCategory.getName(), this.getName()) && Objects.equals(otherCategory.getColor(), this.getColor());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class BoundingBoxPredictor {
private static final String DEFAULT_IMAGE_STREAM_FORMAT_NAME = "png";
private static final String NON_EXISTANT_IMAGE_ERROR_MESSAGE = "Image file does not exist.";
private static final String NON_EXISTENT_IMAGE_ERROR_MESSAGE = "Image file does not exist.";
private final BoundingBoxPredictorClient client;
private final BoundingBoxPredictorConfig predictorConfig;
private double predictedImageWidth;
Expand All @@ -63,7 +62,7 @@ public BoundingBoxPredictionResult predict(File imageFile, ImageMetaData imageMe
imageMetaData.getImageHeight())) {
boundingBoxPredictions = client.predict(inputStream);
} catch(FileNotFoundException e) {
errorInfoEntries.add(new IOErrorInfoEntry(imageFile.getName(), NON_EXISTANT_IMAGE_ERROR_MESSAGE));
errorInfoEntries.add(new IOErrorInfoEntry(imageFile.getName(), NON_EXISTENT_IMAGE_ERROR_MESSAGE));
return new BoundingBoxPredictionResult(
0,
errorInfoEntries,
Expand All @@ -85,13 +84,12 @@ public BoundingBoxPredictionResult predict(File imageFile, ImageMetaData imageMe

imageAnnotation.getBoundingShapeData()
.addAll(boundingBoxPredictions.stream()
.filter(prediction ->
Double.compare(prediction.getScore(),
predictorConfig
.getMinimumScore()) >=
0)
.map(predictionExtractor::extract)
.collect(Collectors.toList()));
.filter(prediction ->
Double.compare(prediction.score(),
predictorConfig
.getMinimumScore()) >=
0)
.map(predictionExtractor::extract).toList());

return new BoundingBoxPredictionResult(1, errorInfoEntries,
new ImageAnnotationData(List.of(imageAnnotation), categoryToCount,
Expand Down Expand Up @@ -148,7 +146,7 @@ public PredictionExtractor(

public BoundingBoxData extract(BoundingBoxPredictionEntry prediction) {
final Map.Entry<String, List<Double>> boundingBoxCoordinatesEntry =
prediction.getCategoryToBoundingBoxes().entrySet().iterator().next();
prediction.categoryToBoundingBoxes().entrySet().iterator().next();

final String predictedCategory = boundingBoxCoordinatesEntry.getKey();

Expand Down
Loading