Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/image.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Agapiou <jagapiou@google.com>2015-12-09 16:48:43 +0300
committerJohn Agapiou <jagapiou@google.com>2015-12-21 13:05:20 +0300
commitc98cba9e50d8e8d1499b614a8e7d8df4969691e3 (patch)
tree803c0b0cd56120f35b5783bb7806f5a32816b087 /init.lua
parent045e9d443fd947880e4ce2e949abb2de1247d69f (diff)
Fix issues with ByteTensors.
Summary ======= In generic/image.c many of the intermediate calculations are done using the datatype `real`. For ByteTensors this is an integral type meaning that undesired results are obtained for ByteTensors. The following methods are fixed for ByteTensors: * y2jet * rgb2y * rgb2hsv * hsv2rgb * rgb2hsl * hsl2rgb * gaussian The following methods are disabled for ByteTensors: * rgb2lab * lab2rgb The following methods are believed to be fixed for ByteTensors, but have not been tested: * warp * rotate * polar The following methods have not been functionally modified, are believed to already work for ByteTensors, but have not been tested: * crop * translate * vflip * hflip * flip Changes ======= generic/image.c --------------- * Define a `temp_t` type to control the precision of intermediate calculations. This avoids hard-wiring 64-bit precision for 32-bit calculations. * Use `temp_t` in place of `real` for intermediate variables. If the function already uses `float` for intermediate calculations then continue to use `float`. * Rename `image_(FromDouble)` to `image_(FromIntermediate)`. * Use `image_(FromIntermediate)` wherever assigning a non-`real` to a `real`. For ByteTensors, this ensures rounding and clipping to the range [0, 255]. * For color conversion, use the ranges [0, 255] rather than [0, 1] for ByteTensors. * Remove `rgb2lab` and `lab2rgb` for ByteTensors. Lab is not constrained to [0, 1] and does not fit well into a 1 byte quantization depth. It makes no sense to have this for ByteTensors. * Make `saturate` a noop for ByteTensors, since they are already constrained to [0, 255]. * In `colorize` randomize a color value only if the colormap has not been set. There was a bug that meant that for ByteTensors any color with R=255 would be randomized. test/test.lua ------------- * Add gaussian test cases. * Modify bilinearUpscale_ByteTensor test to reflect change to rounding behavior. * Update test cases so all color conversion functions are covered. init.lua -------- * Allow y2jet to operate on FloatTensors and ByteTensors. image.c ------- * Move sRGB conversion functions to generic/image.c.
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua16
1 files changed, 11 insertions, 5 deletions
diff --git a/init.lua b/init.lua
index 64fb604..4397d58 100644
--- a/init.lua
+++ b/init.lua
@@ -1879,7 +1879,7 @@ function image.rgb2nrgb(...)
end
----------------------------------------------------------------------
--- image.y2yet(image)
+-- image.y2jet(image)
-- Converts a L-levels (1-L) greyscale image into a jet heat-map
--
function image.y2jet(...)
@@ -1896,9 +1896,6 @@ function image.y2jet(...)
error('Invalid input for image.y2jet()')
end
- -- just use double
- if torch.type(input) ~= 'torch.DoubleTensor' then input = input:double() end
-
-- accept 3D grayscale
if input:dim() == 3 and input:size(1) == 1 then
input = input.new(input):resize(input:size(2), input:size(3))
@@ -1912,7 +1909,16 @@ function image.y2jet(...)
local output = output or input.new()
local L = input:max()
- local colorMap = image.jetColormap(L):typeAs(input)
+ local colorMap = image.jetColormap(L)
+ if torch.type(input) == 'torch.ByteTensor' then
+ colorMap = colorMap:mul(255):round()
+ colorMap[torch.lt(colorMap, 0)] = 0
+ colorMap[torch.gt(colorMap, 255)] = 255
+ colorMap = colorMap:byte()
+ else
+ colorMap = colorMap:typeAs(input)
+ end
+
input.image.colorize(output, input-1, colorMap)
return output