-
Notifications
You must be signed in to change notification settings - Fork 41
/
init.lua
30 lines (27 loc) · 796 Bytes
/
init.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
29
30
-- Package:
local Image = require 'graphicsmagick.Image'
local convert = require 'graphicsmagick.convert'
local parseExif = require 'graphicsmagick.exif'
local info = require 'graphicsmagick.info'
local load = function(path,type)
local img = Image(path)
return img:toTensor(type or 'float','RGB','DHW')
end
local save = function(path,tensor,quality)
local dim = tensor:nDimension()
if dim == 2 or (dim == 3 and tensor:size(1) == 1) then
tensor = tensor:reshape(1,tensor:size(dim-1),tensor:size(dim))
tensor = tensor:expand(3,tensor:size(2),tensor:size(3))
end
local img = Image(tensor,'RGB','DHW')
img:save(path,quality)
end
-- Export:
return {
Image = Image,
convert = convert,
parseExif = parseExif,
info = info,
load = load,
save = save
}