Skip to content

Commit aeabb3b

Browse files
committed
adapt histogram code in scala to support int8
1 parent 73a694c commit aeabb3b

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/DataConverter.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ trait DataConverter extends FoxImplicits {
4747
dstArray
4848
}
4949

50-
def toUnsigned(data: Array[_ >: Byte with Short with Int with Long with Float])
51-
: Array[_ >: UByte with UShort with UInt with ULong with Float] =
50+
def toMaybeUnsigned(data: Array[_ >: Byte with Short with Int with Long with Float])
51+
: Array[_ >: UByte with Byte with UShort with UInt with ULong with Float] =
5252
data match {
53-
case d: Array[Byte] => d.map(UByte(_))
53+
case d: Array[Byte] => d
5454
case d: Array[Short] => d.map(UShort(_))
5555
case d: Array[Int] => d.map(UInt(_))
5656
case d: Array[Long] => d.map(ULong(_))

webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/FindDataService.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class FindDataService @Inject()(dataServicesHolder: BinaryDataServiceHolder)(imp
139139

140140
def createHistogram(dataSource: DataSource, dataLayer: DataLayer): Fox[List[Histogram]] = {
141141

142-
def calculateHistogramValues(data: Array[_ >: UByte with UShort with UInt with ULong with Float],
142+
def calculateHistogramValues(data: Array[_ >: UByte with Byte with UShort with UInt with ULong with Float],
143143
bytesPerElement: Int,
144144
isUint24: Boolean) = {
145145
val counts = if (isUint24) Array.ofDim[Long](768) else Array.ofDim[Long](256)
@@ -157,10 +157,14 @@ class FindDataService @Inject()(dataServicesHolder: BinaryDataServiceHolder)(imp
157157
extrema = (0, 255)
158158
} else
159159
byteData.foreach(el => counts(el.toInt) += 1)
160+
case byteData: Array[Byte] => {
161+
byteData.foreach(el => counts(el.toInt + 128) += 1)
162+
extrema = (-128, 128)
163+
}
160164
case shortData: Array[UShort] =>
161165
shortData.foreach(el => counts((el / UShort(256)).toInt) += 1)
162-
case intData: Array[UInt] =>
163-
intData.foreach(el => counts((el / UInt(16777216)).toInt) += 1)
166+
case uintData: Array[UInt] =>
167+
uintData.foreach(el => counts((el / UInt(16777216)).toInt) += 1)
164168
case longData: Array[ULong] =>
165169
longData.foreach(el => counts((el / ULong(math.pow(2, 56).toLong)).toInt) += 1)
166170
case floatData: Array[Float] =>
@@ -186,7 +190,7 @@ class FindDataService @Inject()(dataServicesHolder: BinaryDataServiceHolder)(imp
186190
for {
187191
dataConcatenated <- getConcatenatedDataFor(dataSource, dataLayer, positions, mag) ?~> "dataset.noData"
188192
isUint24 = dataLayer.elementClass == ElementClass.uint24
189-
convertedData = toUnsigned(filterZeroes(convertData(dataConcatenated, dataLayer.elementClass), skip = isUint24))
193+
convertedData = toMaybeUnsigned(filterZeroes(convertData(dataConcatenated, dataLayer.elementClass), skip = isUint24))
190194
} yield calculateHistogramValues(convertedData, dataLayer.bytesPerElement, isUint24)
191195

192196
if (dataLayer.resolutions.nonEmpty)

0 commit comments

Comments
 (0)