-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColonyMeasurements.swift
37 lines (29 loc) · 1 KB
/
ColonyMeasurements.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// ColonyMeasurements.swift
// ColonyPigmentationAnalysisKit
//
// Created by Javier Soto on 4/19/20.
// Copyright © 2020 Javier Soto. All rights reserved.
//
import Foundation
// MARK: - Measurements
extension MaskBitMap {
public func measureColonySize() -> SquarePixels {
let inMaskPixels = pixels.count(where: { $0 == .white })
let percentage = Double(inMaskPixels) / Double(pixels.count)
let originalImageSize = size.width * size.height
return SquarePixels(value: Int((Double(originalImageSize) * percentage).rounded(.down)))
}
}
public struct SquarePixels {
public let value: Int
public init(value: Int) {
self.value = value
}
public func squareMilimeters(withMicrometersPerPixel micrometersPerPixel: Double) -> SquareMilimeters {
return SquareMilimeters(value: Double(value) * (micrometersPerPixel * micrometersPerPixel) / (1000 * 1000))
}
}
public struct SquareMilimeters: Codable {
public let value: Double
}