@@ -28,9 +28,7 @@ class CountPlaquesViewController: UIViewController {
28
28
private var tileArray = [ Tile] ( )
29
29
private var colExtraTileArray = [ Tile] ( )
30
30
private var rowExtraTileArray = [ Tile] ( )
31
- private var mainPlaqueArray = [ Plaque] ( )
32
- private var colExtraPlaqueArray = [ Plaque] ( )
33
- private var rowExtraPlaqueArray = [ Plaque] ( )
31
+ private var mergedPlaqueArray = [ Plaque] ( )
34
32
35
33
private var tilesPerCol : Int !
36
34
private var tilesPerRow : Int !
@@ -199,38 +197,28 @@ class CountPlaquesViewController: UIViewController {
199
197
200
198
let tempBox = VNImageRectForNormalizedRect ( objectObservation. boundingBox, Int ( currentTileWidth) , Int ( currentTileHeight) ) . applying ( transformVerticalAxis)
201
199
200
+ var objectBounds : CGRect
201
+
202
202
switch currentTile. tileType {
203
203
case . tile:
204
- let objectBounds = tempBox. offsetBy ( dx: currentTile. locRowColumn. x * currentTileWidth, dy: currentTile. locRowColumn. y * currentTileHeight)
204
+ objectBounds = tempBox. offsetBy ( dx: currentTile. locRowColumn. x * currentTileWidth, dy: currentTile. locRowColumn. y * currentTileHeight)
205
205
. applying ( CGAffineTransform ( scaleX: scaleX, y: scaleY) )
206
206
. applying ( CGAffineTransform ( translationX: ( self . imageView. bounds. width- actualImageBounds. size. width) / 2 , y: offsetY) )
207
207
208
- let shapeLayer = self . createRoundedRectLayerWithBounds ( objectBounds, color: [ 1.0 , 0.0 , 0.0 ] )
209
- detectionOverlay. addSublayer ( shapeLayer)
210
-
211
- mainPlaqueArray. append ( Plaque ( petriDish: petriDish, locInLayer: shapeLayer. bounds, plaqueLayer: shapeLayer) )
212
-
213
208
case . colExtraTile:
214
- let objectBounds = tempBox. offsetBy ( dx: ( currentTile. locRowColumn. x * currentTileWidth) - ( currentTileWidth * 0.5 ) , dy: currentTile. locRowColumn. y * currentTileHeight)
209
+ objectBounds = tempBox. offsetBy ( dx: ( currentTile. locRowColumn. x * currentTileWidth) - ( currentTileWidth * 0.5 ) , dy: currentTile. locRowColumn. y * currentTileHeight)
215
210
. applying ( CGAffineTransform ( scaleX: scaleX, y: scaleY) )
216
211
. applying ( CGAffineTransform ( translationX: offsetX, y: offsetY) )
217
212
218
- let shapeLayer = self . createRoundedRectLayerWithBounds ( objectBounds, color: [ 1.0 , 0.0 , 0.0 ] )
219
- detectionOverlay. addSublayer ( shapeLayer)
220
-
221
- colExtraPlaqueArray. append ( Plaque ( petriDish: petriDish, locInLayer: shapeLayer. bounds, plaqueLayer: shapeLayer) )
222
-
223
213
case . rowExtraTile:
224
- let objectBounds = tempBox. offsetBy ( dx: currentTile. locRowColumn. x * currentTileWidth, dy: ( currentTile. locRowColumn. y * currentTileHeight) + ( currentTileHeight * 0.5 ) )
214
+ objectBounds = tempBox. offsetBy ( dx: currentTile. locRowColumn. x * currentTileWidth, dy: ( currentTile. locRowColumn. y * currentTileHeight) + ( currentTileHeight * 0.5 ) )
225
215
. applying ( CGAffineTransform ( scaleX: scaleX, y: scaleY) )
226
216
. applying ( CGAffineTransform ( translationX: ( self . imageView. bounds. width- actualImageBounds. size. width) / 2 , y: offsetY) )
227
-
228
- let shapeLayer = self . createRoundedRectLayerWithBounds ( objectBounds, color: [ 1.0 , 0.0 , 0.0 ] )
229
- detectionOverlay. addSublayer ( shapeLayer)
230
-
231
- rowExtraPlaqueArray. append ( Plaque ( petriDish: petriDish, locInLayer: shapeLayer. bounds, plaqueLayer: shapeLayer) )
232
217
}
233
218
219
+ let shapeLayer = self . createRoundedRectLayerWithBounds ( objectBounds, color: [ 1.0 , 0.0 , 0.0 ] )
220
+ detectionOverlay. addSublayer ( shapeLayer)
221
+ mergedPlaqueArray. append ( Plaque ( petriDish: petriDish, locInLayer: shapeLayer. bounds, plaqueLayer: shapeLayer) )
234
222
}
235
223
236
224
self . updateLayerGeometry ( )
@@ -302,28 +290,23 @@ class CountPlaquesViewController: UIViewController {
302
290
}
303
291
304
292
func summarizePlaques( plaqueArray: [ Plaque ] ? = nil ) {
305
- print ( " ===== START OF PLAQUE COUNTS ===== " )
306
293
if let plaqueArray = plaqueArray {
307
- print ( " Total plaque count after NMS is: \( plaqueArray. count) " )
294
+ print ( " Total plaque count AFTER NMS is: \( plaqueArray. count) " )
308
295
let s = ( plaqueArray. count == 1 ) ? " " : " s "
309
296
DispatchQueue . main. async {
310
297
self . textView. text = " \( plaqueArray. count) plaque \( s) detected "
311
298
}
312
299
} else {
313
- print ( " mainPlaqueArray count is: \( mainPlaqueArray. count) " )
314
- print ( " colExtraPlaqueArray plaque array count is: \( colExtraPlaqueArray. count) " )
315
- print ( " rowExtraPlaqueArray plaque array count is: \( rowExtraPlaqueArray. count) " )
300
+ print ( " Total plaque count BEFORE NMS is: \( mergedPlaqueArray. count) " )
316
301
}
317
- print ( " ===== END OF PLAQUE COUNTS ===== " )
318
302
}
319
303
320
304
func nonMaximumSuppression( finished: @escaping ( ) -> Void ) {
321
305
summarizePlaques ( )
322
306
323
307
//all vs all comparison
324
- var mergedArray = mainPlaqueArray + colExtraPlaqueArray + rowExtraPlaqueArray
325
- for plaque in mergedArray {
326
- for otherPlaque in mergedArray {
308
+ for plaque in mergedPlaqueArray {
309
+ for otherPlaque in mergedPlaqueArray {
327
310
if plaque !== otherPlaque {
328
311
let plaqueLayerBds = plaque. locInLayer
329
312
let otherPlaqueLayerBds = otherPlaque. locInLayer
@@ -339,17 +322,17 @@ class CountPlaquesViewController: UIViewController {
339
322
340
323
if ( areaOverPlaque > areaOverOtherPlaque) && ( areaOverPlaque >= CGFloat ( iouThreshold) ) {
341
324
DispatchQueue . main. async { self . detectionOverlay. sublayers!. removeAll ( where: { $0 === plaque. plaqueLayer} ) }
342
- mergedArray . removeAll ( where: { $0 === plaque} )
325
+ mergedPlaqueArray . removeAll ( where: { $0 === plaque} )
343
326
} else if ( areaOverOtherPlaque > areaOverPlaque) && ( areaOverOtherPlaque >= CGFloat ( iouThreshold) ) {
344
327
DispatchQueue . main. async { self . detectionOverlay. sublayers!. removeAll ( where: { $0 === otherPlaque. plaqueLayer} ) }
345
- mergedArray . removeAll ( where: { $0 === otherPlaque} )
328
+ mergedPlaqueArray . removeAll ( where: { $0 === otherPlaque} )
346
329
}
347
330
}
348
331
}
349
332
}
350
333
}
351
- petriDish. plaques = mergedArray
352
- summarizePlaques ( plaqueArray: mergedArray )
334
+ petriDish. plaques = mergedPlaqueArray
335
+ summarizePlaques ( plaqueArray: mergedPlaqueArray )
353
336
finished ( )
354
337
}
355
338
0 commit comments