-
Notifications
You must be signed in to change notification settings - Fork 8
/
util.lua
executable file
·28 lines (22 loc) · 682 Bytes
/
util.lua
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
local function toDouble(imgData)
return imgData:type() == 'torch.CudaLongTensor' and imgData:cudaDouble() or imgData:double()
end
local function toLong(imgData)
return imgData:type() == 'torch.CudaTensor' and imgData:cudaLong() or imgData:long()
end
local function normalizeByteImage(imgData)
return toDouble(imgData):div(256)
end
local function quantize(imgData, quantLevels)
return toLong(imgData:mul(quantLevels):add(1))
end
local function dequantize(imgData, quantLevels)
return toDouble(imgData):csub(1):div(quantLevels-1)
end
return {
toDouble = toDouble,
toLong = toLong,
normalizeByteImage = normalizeByteImage,
quantize = quantize,
dequantize = dequantize
}