Coder Social home page Coder Social logo

image's Introduction

image Package Reference Manual

Build Status

image is the Torch7 distribution package for processing images. It contains a wide variety of functions divided into the following categories:

Note that unless speficied otherwise, this package deals with images of size nChannel x height x width.

Install

The easiest way to install this package it by following the intructions to install Torch7, which includes image. Otherwise, to update or manually re-install it:

$ luarocks install image

You can test your install with:

$ luajit -limage -e "image.test()"

Usage

> require 'image'
> l = image.lena()
> image.display(l)
> f = image.fabio()
> image.display(f)

image's People

Contributors

andresy avatar angli-ai avatar atcold avatar chsasank avatar clementfarabet avatar colesbury avatar dm-jrae avatar fidlej avatar gchanan avatar initialneil avatar jagapiou avatar jonathantompson avatar jucor avatar karandwivedi42 avatar koraykv avatar krasin avatar lukemarris avatar lvdmaaten avatar maratyszcza avatar marcoscoffier avatar mtourne avatar mys007 avatar nagadomi avatar nicholas-leonard avatar samehkhamis avatar soumith avatar spk921 avatar timzaman avatar tkoeppe avatar vfonov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

image's Issues

Memory usage

I'm trying to loop over a table of images to re-scale, after a few moments my RAM is almost full.
I didn't find any close() function to close my image when I saved it on the disk.

Here is my code :

function resize_images(df, width, height)
    n_train = count_training_files(df)

    j = 0
    for i = 1, df.n_rows do
        if file_exists('./imgs/'..df.dataset['Image'][i]) == true then
            new_image = image.loadJPG('./imgs/'..df.dataset['Image'][i])
            img = image.scale(new_image, width, height)
            image.save('./data/'..df.dataset['Image'][i], img)
            img = nil
            new_image = nil
            j = j + 1
            print(df.dataset['Image'][i]..' resized ('.. n_train-j ..' left)')
        end
    end
end

Is there a better way or am I missing something ?

error after reinstalling Image package: error loading module 'libimage'

After reinstalling the 'image' package (luarocks install image) i get the following error:

...oiso/Toolkits/torch/install/share/lua/5.1/trepl/init.lua:354: ...oiso/Toolkits/torch/install/share/lua/5.1/trepl/init.lua:354: ...Toolkits/torch/install/share/lua/5.1/luarocks/loader.lua:117: error loading module 'libimage' from file '/home/coiso/Toolkits/torch/install/lib/lua/5.1/libimage.so':
/home/coiso/Toolkits/torch/install/lib/lua/5.1/libimage.so: undefined symbol: luaT_setfuncs
stack traceback:
[C]: in function 'error'
...oiso/Toolkits/torch/install/share/lua/5.1/trepl/init.lua:354: in function 'f'
[string "local f = function() return require 'image' e..."]:1: in main chunk
[C]: in function 'xpcall'
...oiso/Toolkits/torch/install/share/lua/5.1/trepl/init.lua:620: in function 'repl'
...kits/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:185: in main chunk
[C]: at 0x00406670

Tried to install it today on two machines, both gave the same error.

Can't install image

luarocks install image
Installing https://raw.githubusercontent.com/torch/rocks/master/image-1.1.alpha-0.rockspec...
Using https://raw.githubusercontent.com/torch/rocks/master/image-1.1.alpha-0.rockspec... switching to 'build' mode
Cloning into 'image'...
remote: Counting objects: 33, done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 33 (delta 2), reused 21 (delta 1), pack-reused 0
Receiving objects: 100% (33/33), 866.97 KiB | 682.00 KiB/s, done.
Resolving deltas: 100% (2/2), done.
Checking connectivity... done.
cmake -E make_directory build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="/Users/Edwin/torch/install/bin/.." -DCMAKE_INSTALL_PREFIX="/Users/Edwin/torch/install/lib/luarocks/rocks/image/1.1.alpha-0" && make

-- The C compiler identification is AppleClang 6.1.0.6020049
-- The CXX compiler identification is AppleClang 6.1.0.6020049
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Torch7 in /Users/Edwin/torch/install
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/luarocks_image-1.1.alpha-0-298/image/build
Scanning dependencies of target image
[ 25%] Building C object CMakeFiles/image.dir/image.c.o
In file included from /tmp/luarocks_image-1.1.alpha-0-298/image/image.c:40:
In file included from generic/image.c:2:
/tmp/luarocks_image-1.1.alpha-0-298/image/generic/image.c:1825:17: warning: comparison of constant -1 with
expression of type 'unsigned char' is always false [-Wtautological-constant-out-of-range-compare]
if (check == -1) {
~~~~~ ^ ~~
1 warning generated.
Linking C shared module libimage.so
[ 25%] Built target image
Scanning dependencies of target jpeg
[ 50%] Building C object CMakeFiles/jpeg.dir/jpeg.c.o
make[2]: *** No rule to make target /usr/local/lib/libjpeg.dylib', needed bylibjpeg.so'. Stop.
make[1]: *** [CMakeFiles/jpeg.dir/all] Error 2
make: *** [all] Error 2

Error: Build error: Failed building.

16-bit PNG files not supported

Hi there,

I tried to load ground truth disparity data from The KITTI Vision Benchmark Suite, which are encoded as 16-bit grayscale PNG files. image.load pretended to succeed, but the output looked skewed:

bad

After digging into the source code, I realized that the issue is within libpng_(Main_load) in generic/png.c

  /* convert image to dest tensor */
  int x,k;
  for (k=0; k<depth; k++) {
    for (y=0; y<height; y++) {
      png_byte* row = row_pointers[y];
      for (x=0; x<width; x++) {
        *tensor_data++ = (real)row[x*depth+k];
        //png_byte val = row[x*depth+k];
        //THTensor_(set3d)(tensor, k, y, x, (real)val);
      }
    }
  }

If png_get_bit_depth(png_ptr, info_ptr) == 16, the correct inner loop contents will be:

*tensor_data++ = (real)row[x*depth*2+k];

In this case, the image would look right:

good

The obvious "fix" is something like:

  /* convert image to dest tensor */
  int x,k;
  int bit_depth = png_get_bit_depth(png_ptr, info_ptr);
  for (k=0; k<depth; k++) {
    for (y=0; y<height; y++) {
      png_byte* row = row_pointers[y];
      for (x=0; x<width; x++) {
        real val;
        if (bit_depth == 16) {
          /* PNG is big-endian, and we only read the most significant byte for now. */
          val = (real)row[x*depth*2+k];
        } else {
          val = (real)row[x*depth+k];
        }
        *tensor_data++ = val;
        //png_byte val = row[x*depth+k];
        //THTensor_(set3d)(tensor, k, y, x, (real)val);
      }
    }
  }

The only problem, which is somewhat annoying, is that we'll lose the precision, as only the most significant byte will be used. It's certainly possible to fix in processPNG from init.lua, but I think that I would like to hear your opinion first.

Artefacts on image.rotate()

I'm working with small patches and I'm having problems with image.rotate(). Neither the 'simple' nor the 'bilinear' method seem to do what I would expect:

Simple itorch script to rotate a small image:

require 'image'
side = 25
if true then
   x = image.scale( image.lena(), side )
else
   x = torch.DoubleTensor(3, side, side):fill(1)
   center = torch.floor(side/2)
   x[1][c][c] = 1 x[2][c][c] = 0 x[3][c][c] = 0
end

zoom = 10 -- no zoom with itorch.image?
y = image.rotate(x, math.pi/2, 'simple')
itorch.image( {image.scale(x,side*zoom,'simple'), image.scale(y,side*zoom,'simple')} )

y = image.rotate(x, math.pi/2, 'bilinear')
itorch.image( {image.scale(x,side*zoom,'simple'), image.scale(y,side*zoom,'simple')} )

Results, 13x13: https://dl.dropboxusercontent.com/u/34854207/debugging-torch/lena-odd.png
Results, 14x14: https://dl.dropboxusercontent.com/u/34854207/debugging-torch/lena-even.png
(On either, top row: 'simple', bottom row: 'bilinear')

For an odd patch size, the central column/row is duplicated with 'simple', and for 'bilinear' there's a one column/row shift. For an even patch size there's a strange artefact on the central column/row for 'simple' (appears to be shifted? and the "central" pixel is repeated 4 times), and a one-row shift for 'bilinear', plus angle quantization errors (I guess).

Maybe it's easier to see with a toy example:
Results, 13x13: https://dl.dropboxusercontent.com/u/34854207/debugging-torch/toy-odd.png
Results, 14x14: https://dl.dropboxusercontent.com/u/34854207/debugging-torch/toy-even.png

Any ideas?

Using image.scale with CUDA

Hi,
Is there a way to make image.* functions execute in CUDA GPU processors?
f_image = image.scale(II, imW, imH) ;

Thank you,
Deepak

[bug?] erode and dilate doesn't work

I've tried both of this function, but the output remains nil

th> ker = torch.Tensor({{1,1,1},{1,1,1},{1,1,1}})
                                                                      [0.0001s]
th> pxe = image.erode(ppx,ker,0)
(1,.,.) = 
  1  0  0  0  0  0  1  1  1  1  1  1  1  1  1  1
  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
  1  0  0  0  0  0  0  0  0  1  1  1  1  1  1  1
  1  0  0  0  0  0  0  0  0  0  0  1  1  1  1  1
  1  0  0  0  0  0  0  0  0  0  0  1  1  1  1  1
  1  0  0  0  0  0  0  0  0  0  1  1  1  1  1  1
  1  0  0  0  0  0  1  0  0  0  1  1  1  1  1  1
  1  0  0  0  0  0  1  0  0  0  0  1  1  1  1  1
  1  1  0  0  0  0  1  0  0  0  1  1  1  1  1  1
  1  1  0  0  0  0  1  0  0  1  1  1  1  1  1  1
  1  1  0  0  0  1  1  1  0  0  1  1  1  1  1  1
  1  1  0  0  0  0  1  1  0  0  0  1  0  0  0  0
  1  1  0  0  0  0  1  1  0  0  0  0  0  0  0  0
  1  1  0  0  0  0  1  1  0  0  0  0  0  0  0  0
  1  1  0  0  0  0  0  1  0  0  0  0  0  0  0  1
  1  1  0  0  0  0  0  0  0  0  0  0  0  0  1  1
[torch.DoubleTensor of dimension 1x16x16]

                                                                      [0.0004s]
th> =pxe
                                                                      [0.0000s]
th> 

the output of image.erode is just the same as ppx

vflip and hflip corrupt image when src and dst images are the same

The new flip code broke the corner case when src and dst images are the same. I'm pretty annoyed by this... I wasted a HUGE amount of time because of this bug.

I think the torch guys need to layout some code review guidelines. It seems like this one should have been caught if there was a proper code review.

require 'image'
im = image.lena()
image.display(im)
image.hflip(im, im)
image.display(im)
image.save('lena_flipped_new.png', im)

This used to produce:
lena_flipped_old.png

Now it produces:
lena_flipped_new.png

crop image

Hello,

I am generating DB for facial and have questions about "crop image".

  1. I made my own "crop function" and compared the result with the function embedded in torch, but they are different. Torch function does not crop image correctly with given start x,y and end x,y.
  2. Also, it looks like embedded function uses bilinear as default. Why?
  3. Embedded package functions are very fast, but my functions(rotate, crop, scale) are much slower than embedded one. I coded with purely lua/torch. No call any c library/code under torch/pkg.
    However, torch image package calls "image.c"
    How can I make my function fast? I tried to use cuda(), but it took more time to copy data to GPU.

Thanks.

image.toDisplayTensor broken for ByteTensors

Hi all

Commit 3bc649a in October 2014 as part of pull-request #36 introduced a bug on ByteTensor inputs and changed the in-place/not-in-place contract of toDisplayTensor.

Since then, image.toDisplayTensor outputs wrong values when given a 3-by-H-by-W ByteTensor.
This is because that commit made some calls toDisplayTensor in-place, especially those where the input is a 3-channels RGB image. Whereas before, the input was copied into the (Double)Tensor grid.

Sine this copy to Tensor was removed, the inplace minmax operation that is called on the tensor at line 867 tries to renormalize on a ByteTensor, and of course does that poorly due to rounding to the nearest integer that occurs in a ByteTensor.

Corrupt results rotating an image with src == dst

E.g.

require 'image'
img = image.lena()
image.rotate( img, img, math.pi/2, 'bilinear' )
itorch.image( img )

produces:
poor lena

Works fine with :clone() of course.
Not a big deal but it took me a while to track down where the problem was.

Cannot read 1-bit grayscale png on mac

Hi,

I failed loading an 1-bit grayscale png on mac and following error message was shown.

libpng error: invalid after png_start_read_image or png_read_update_info

However, if I convert the image to RGB it would work, and if I switch to ubuntu 14.04 with the same grayscale png it also work.

I am using libpng 1.6.18 installed by brew and OS X 10.10.5.

I think the problem would be in /generic/png.c at line 99 to 115.

png_read_update_info(png_ptr, info_ptr);

/* get depth */
int depth = 0;
if (color_type == PNG_COLOR_TYPE_RGBA)
  depth = 4;
else if (color_type == PNG_COLOR_TYPE_RGB)
  depth = 3;
else if (color_type == PNG_COLOR_TYPE_GRAY)
  {
    if(bit_depth < 8)
    {
      png_set_expand_gray_1_2_4_to_8(png_ptr);
      png_read_update_info(png_ptr, info_ptr);
    }
    depth = 1;
  }

It seems that png_read_update_info is called twice, and on ubuntu 14.04 I got following warning:

Ignoring extra png_read_update_info() call; row buffer not reallocated.

Shouldn't png_read_update_info() be called only once after all png_set_expand() things are done?

Update image.display in the same window

It was not straight forward to update the same window with image.display(). After reading the source code I found out that you have to specify the win variable.

Method 1: set window before the first display

The win variable accepts a "qt window" table made from qtwidget.newwindow()

require 'image'
require 'qtwidget'
w = qtwidget.newwindow(500, 400)
lena = image.lena()
image.display{image=lena, win=w}

Noted that the window size is fixed at creation, it doesn't resize according to image.display()

Method 2: get window from existing display and update

image.display() function returns handler but it's not the window directly. The source code suggests that when offscreen is true by default the return is qt.QtLuaPainter which is for painter variable; while if offscreen is false, the return is the "qt window" for win.

Only by setting offscreen to false can we get the "qt window" from image.display().

require 'image'
require 'sys'

-- toy images to display
images = {}
images[1] = image.lena()
images[2] = image.fabio()

-- display the first image
w = image.display{image=images[1], offscreen=false, win=w}  -- "win=w" can be removed 
                                                            -- here because w = nil

-- sleep for fun
sys.sleep(1)

-- display the second image
w = image.display{image=images[2], offscreen=false, win=w}  -- here input "w" is the 
                                                            -- previous window

In this way, the window size is set by the image.display() automatically. I guess it's very handy when used to display many images in a Tensor or table, where the final size of the display is arbitrage.

issue with image.display()

Hi,

I am using Torch7 with Ubuntu 14.04 and faced an issue with the function

image.display(im) -- image is loaded to the variable im.

The error I am getting is this

/home/rahul/torch/install/share/lua/5.1/trepl/init.lua:383: module 'qt' not found:No LuaRocks module found for qt
no field package.preload['qt']
no file '/home/admin/.luarocks/share/lua/5.1/qt.lua'
no file '/home/admin/.luarocks/share/lua/5.1/qt/init.lua'
no file '/home/rahul/torch/install/share/lua/5.1/qt.lua'
no file '/home/rahul/torch/install/share/lua/5.1/qt/init.lua'
no file './qt.lua'
no file '/home/rahul/torch/install/share/luajit-2.1.0-alpha/qt.lua'
no file '/usr/local/share/lua/5.1/qt.lua'
no file '/usr/local/share/lua/5.1/qt/init.lua'
no file '/home/rahul/.luarocks/share/lua/5.1/qt.lua'
no file '/home/rahul/.luarocks/share/lua/5.1/qt/init.lua'
no file '/home/admin/.luarocks/lib/lua/5.1/qt.so'
no file '/home/rahul/torch/install/lib/lua/5.1/qt.so'
no file './qt.so'
no file '/usr/local/lib/lua/5.1/qt.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file '/home/rahul/.luarocks/lib/lua/5.1/qt.so'
stack traceback:
[C]: in function 'error'
/home/rahul/torch/install/share/lua/5.1/trepl/init.lua:383: in function 'require'
/home/rahul/torch/install/share/lua/5.1/image/init.lua:1334: in function 'display'
[string "_RESULT={image.display(image.lena())}"]:1: in main chunk
[C]: in function 'xpcall'
/home/rahul/torch/install/share/lua/5.1/trepl/init.lua:650: in function 'repl'
...ahul/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:199: in main chunk
[C]: at 0x00406670

I tried the following

  1. Followed (https://groups.google.com/forum/#!searchin/torch7/image.display/torch7/kMP9vYyRwGg/8-EhC_QI84EJ ) and tried qlua -e "require('trepl')()" and in the prompt th> I was able to display an image after loading it.
  2. Similarly, I tried qlua myscript.lua (It has the code image.display(im)) and it works - But quite slow. I tried disabling the code to display the image. Still slow.
  3. Ran th myscript.lua and I get the above error. I have seen in one post by @soumith about a similar issue (torch/qtlua#7) and tried changing the package.path and package.cpath to the ones shown at the output of the qlua interpreter. Still when I run th main.lua, it shows the same error.

May be a silly newbie problem. Any help is much appreciated. Thanks

Here is a screenshot of the issue. I have also displayed the package.path and package.cpath on both qlua and th

lua

Rahul R

Gaussian kernel values

The current implementation of image.gaussian() evaluates the Gaussian over a fixed interval (approx. [-0.5,0.5]^2 in the standard settings) and changes the sampling density by the size. This is not documented and highly non-standard. I would expect the same results as given e.g. by MATLAB's fspecial() function, i.e. the filter size should change the evaluation domain.

Bad memory management

Calling image.load(imagePath); collectgarbage() with the same imagePath for 2,600 times consumes 5 MB, doing the same but with different imagePath consumes 100 MB.
Is this behaviour expected?

I am trying to figure out why my training is allocating so much memory, and the problems start even at the loading images level.
Am I doing something wrong?

How to run this package with the updated Torch

I cannot run this package with the new torch. How am I supposed to do it?

th runs luajit based Torch, qlua, requiring image, gives me

/usr/local/share/lua/5.1/sundown/init.lua:1: module 'ffi' not found:
    no field package.preload['ffi']
    no file './ffi.lua'
    no file '/usr/local/share/lua/5.1/ffi.lua'
    no file '/usr/local/share/lua/5.1/ffi/init.lua'
    no file '/usr/local/lib/lua/5.1/ffi.lua'
    no file '/usr/local/lib/lua/5.1/ffi/init.lua'
    no file './ffi.so'
    no file '/usr/local/lib/lua/5.1/ffi.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
    [C]: in function 'require'
    /usr/local/share/lua/5.1/sundown/init.lua:1: in main chunk
    [C]: in function 'require'
    /usr/local/share/lua/5.1/dok/init.lua:1: in main chunk
    [C]: in function 'require'
    /usr/local/share/lua/5.1/image/init.lua:35: in main chunk
    [C]: in function 'require'
    [string "require 'image'"]:1: in main chunk
    [C]: ?

And trying to install lzmq-ffi gives me

export MACOSX_DEPLOYMENT_TARGET=10.5; gcc -O2 -fPIC -I/usr/local/include -c src/ztimer.c -o src/ztimer.o -DUSE_CLOCK_MONOTONIC -DUSE_GETTIMEOFDAY
src/ztimer.c: In function ‘GetMonotonicTime’:
src/ztimer.c:147:25: error: ‘CLOCK_MONOTONIC’ undeclared (first use in this function)
   if(0 == clock_gettime(CLOCK_MONOTONIC, &ts))
                         ^
src/ztimer.c:147:25: note: each undeclared identifier is reported only once for each function it appears in

Error: Build error: Failed compiling object src/ztimer.o

JPEG error handligh

If an image is corrupted, image.load() does not shoot an error but outputs a string.

th> image.load(p)
Empty input file

I couldn't track down where the Empty input file string is outputted, therefore I guess it's coming from libjpeg and how it's handled in generic/jpeg.c.

Issues with image.scale (depth issue)

Hi,

I am a phd student at Hopkins using torch.

I am making a call to image.scale and I receive the error (seen attached) relating to some sort of depth mismatch between src and dst. Do you know why this may be?

Thanks,
Jamal

filter-bank_jpeg

image fails to run on Mac OSX 10.9

I was trying to use the image library, but this happens:

➜  ~  th -limage
> image.lena()
Wrong JPEG library version: library is 80, caller expects 62
/usr/local/share/lua/5.1/image/init.lua:115: attempt to index local 'a' (a nil value)
stack traceback:
    /usr/local/share/lua/5.1/image/init.lua:115: in function 'loader'
    /usr/local/share/lua/5.1/image/init.lua:247: in function 'load'
    /usr/local/share/lua/5.1/image/init.lua:1007: in function 'f'
    [string "local f = function() return image.lena() end ..."]:1: in main chunk
    [C]: in function 'xpcall'
    /usr/local/share/lua/5.1/trepl/init.lua:510: in function </usr/local/share/lua/5.1/trepl/init.lua:452>  
> 

I have no idea how to fix that.

Getting Error while loading png Image in lua

Hi,
I am loading an image using image package in lua.
It is working fine for many png, jpeg images. But for some images it is getting crashed while loading image.

A=image.load(filename )
libpng error: Read Error
/usr/local/torch/install/share/lua/5.1/image/init.lua:136: [read_png_file] Error during read_image
stack traceback:
[C]: in function 'load'
/usr/local/torch/install/share/lua/5.1/image/init.lua:136: in function 'loader'
/usr/local/torch/install/share/lua/5.1/image/init.lua:337: in function 'load'
[string "A=image.load(filename )"]:1: in main chunk
[C]: in function 'xpcall'
/usr/local/torch/install/share/lua/5.1/trepl/init.lua:648: in function 'repl'
...ocal/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:185: in main chunk
[C]: at 0x00406670

Please let me know how to fix this issue as it is crashing in libpng library
Please find the attached images for which it is crashing.

152856_294068

Problem with loading libimage.so

Any time that I try to load this rock or any library that depends on this rock, I get the following error:

error loading module 'libimage' from file '/home/user/torch/install/lib/lua/5.1/libimage.so':
    /home/user/torch/install/lib/lua/5.1/libimage.so: undefined symbol: luaT_setfuncs

This happens when doing:

require 'image'

or

require 'imgraph'

or

require 'ffmpeg'

I have imgraph version 1.0-0 and ffmpeg 1.0-0 installed currently on a computer running Linux Mint 17.1 Rebecca.

Error on y2jet function if torch.setdefaulttensortype has been set

Error on image.y2jet function if torch.setdefaulttensortype has been set.

Code example,

require 'torch'
require 'image'

-- Commenting below line will work :(
torch.setdefaulttensortype('torch.FloatTensor')

prob = torch.FloatTensor(1, 240, 320):fill(1)
prob = image.y2jet(prob)

image building with wrong versions of libjpeg AND libpng [OSX 10.11.1]

Hi

I have a problem getting image to work as it seems that to be picking up the wrong libraries when building:

th> image.test()
seed: 1449963930
Running 26 tests
**|_______________________ ==> DecompressPNGlibpng warning: Application built with libpng-1.5.14 but running with 1.6.19
|________________ ==> LoadPNGlibpng warning: Application built with libpng-1.5.14 but running with 1.6.19
________
____
_ ==> Done Completed 41 asserts in 26 tests with 9 errors

CompareLoadAndDecompress
Function call failed
.../lua-extra/torch/install/share/lua/5.1/image/init.lua:212: Wrong JPEG library version: library is 80, caller expects 62

and

libpng warning: Application built with libpng-1.5.14 but running with 1.6.19
[...]/lua-extra/torch/install/bin/luajit: ...IPO/lua-extra/torch/install/share/lua/5.1/image/init.lua:148: [read_png] png_create_read_struct failed
stack traceback:
[C]: in function 'load'
.../lua-extra/torch/install/share/lua/5.1/image/init.lua:148: in function 'loader'
.../lua-extra/torch/install/share/lua/5.1/image/init.lua:344: in function 'load'
./misc/DataLoaderRaw.lua:82: in function 'getBatch'
eval.lua:116: in function 'eval_split'
eval.lua:173: in main chunk
[C]: in function 'dofile'
...xtra/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
[C]: at 0x010e846b70

I am running on OSX El Capitan and I have updated brew, libjpeg and libpng to the latest version, like it says in issue #16. I installed torch following the instructions on the install page. When I tried to build with TORCH_LUA_VERSION=LUA52 ./install.sh then the hdf5 library breaks (and the torch-hdf5 maintainer told me to use luajit).
Other system variables are:

echo $LD_LIBRARY_PATH
/Users/niko/workspace/lua-extra/torch/install/lib:
echo $DYLD_LIBRARY_PATH
/usr/local/Cellar/jpeg/8d/lib/:/Users/niko/workspace/lua-extra/torch/install/lib::/usr/lib/

What can I do to force luarocks to find the correct libraries when installing / building image or torch to know about these other libraries?

Thanks a lot for your help.

`{v,h}flip` bug

This commit (14f20a7) throws an error if the input vector is not contiguous, breaking code.
Before, non contiguous vector were not a problem.
More comments and tests are available at the commit webpage.

@jonathantompson, would you mind patching it up?

unexpected behavior in image.crop() if dst is provided

The documentation of image.crop says "if dst is provided, it is used to store the output image". What actually happens is that if dst is provided, the output image is rescaled to the provided dst. There is in fact an intermediate buffer which is created for storing the cropped image.

Is this what is actually intended?
Shouldn't dst be resized to the output crop (and actually used as a buffer, if provided)?

Open images regardless their extension

I was wondering if / how image could be tweaked for opening images regardless their extension. This would be extremely helpful when JPEGs have a PNG extension or the other way around.
I was thinking perhaps to check the st_mode field of the structure struct stat returned by STAT(2), perhaps using ffi, but I don't know if it would be the best approach.
Please advice.

crop(src, x1, y1) broken

what is supposed to do crop(src, x1, y1)? it is not working at this time. i can fix it (i would picked that the missing x2, y2 are the right bottom coordinates of the src image), but i need to know for sure what was the intended behavior 😄 .

also, crop(dst, src, x1, y1) is cheesy (well, compared to what the documentation says!): it uses the dst size to compute the missing coordinates (instead of using dst only to put the result, as advertised).

can we choose a consistent behavior between all these crop alternatives?

vflip and hflip corrupt the image if image dimensions are larger than 256x256

I have experienced this with three-dimensional tensors (KxHxW) where the depth of the image (K) is 3 (RGB images) and the dimensions are larger than 256. hflip and vflip use image:warp so the bug could be within warp.

The corruption experienced with vflip is the top 256x256 pixels of the source image being vertically flipped and tiled across the output image.

cuda implementations of torch/image functionality

Hi everyone

Over the last few months I have been developing lua functions similar to torch/image with cuda support, whenever I needed it. However, I have not seen a single cuda-accelerated function in here. So I was wondering whether others are interested in this functionality and how it is best shared with the community: seperate repo? build flags for this library? automatic replacement of functions when called with a torch.CudaTensor or just extending the function name with _cu or similar?
What are your thoughts on this?

Lukas

CudaTensor breaks image loading

require "torch"
require "cutorch"
require "cunn"
require "image"

torch.setdefaulttensortype("torch.CudaTensor")

img = image.lena()

(cv)[cooper@titan]/code/cv/torch: th test.lua
/usr/local/bin/luajit: /usr/local/share/lua/5.1/image/init.lua:113: attempt to index field 'libjpeg' (a nil value)
stack traceback:
/usr/local/share/lua/5.1/image/init.lua:113: in function 'loader'
/usr/local/share/lua/5.1/image/init.lua:247: in function 'load'
/usr/local/share/lua/5.1/image/init.lua:1004: in function 'lena'
badimage.lua:10: in main chunk
[C]: in function 'dofile'
/usr/local/lib/luarocks/rocks/trepl/scm-1/bin/th:129: in main chunk
[C]: at 0x004061d0

image.load colorspaces

"The returned res Tensor has size nChannel x height x width where nChannel is 1 (greyscale) or 3 (usually RGB or YUV."

Can this text be cleaned up to clarify that RGB will be used for the JPEG and PNG decoders? After reading through the code and trying it out, I'm not sure why YUV is mentioned. Or do I misunderstand?

Artefacts on image.scale()

Similar to #80, but way trickier to see on normal images, so it may have gone unnoticed.
I'm working with something like this:
Source
Zoomed, for clarity:
Source, zoomed
Scaled to 0.9 ('bilinear'), zoomed:
Scaled to 0.9, zoomed
Scaled to 1.1 ('bilinear'), zoomed:
Scaled to 1.1, zoomed

There are pretty noticeable, grid-like artefacts (easier to see on the last image).

Test script:

require 'image'
x = image.loadPNG('source.png')

zoom = 3
y = image.scale(x, 1.1*x:size(2), 'bilinear')
itorch.image( image.scale(x,x:size(3)*zoom,'simple'), {min=0, max=1} )
itorch.image( image.scale(y,y:size(3)*zoom,'simple'), {min=0, max=1} )

torch-rocks install image

"torch-rocks install image" fails in my firewall-rich environment, failing (due to timeout) when attempting to git "git://github.com/andresy/torch7-fakerock"

The git port is blocked for me. I think that the problem might lie in the explicit selection of the git protocol in the rock definition.

for example: (from torch-7.scm-0.rockspec)
source = {
url = "git://github.com/andresy/torch7-fakerock"
}

...I suspect that this works better if
source = {
url = "https://github.com/andresy/torch7-fakerock"
}


NOTE: I resolved this for my installation by modifying git.lua to always change 'git:' to 'https:'

LICENCE

Hi,
do you plan to add a LICENCE for this repository?
--Nick

Image is broken when t():clone():t()

require 'torch'
require 'image'

function success()
   -- no problem
   local lena = image.lena():clone()
   local size = lena:size()
   local tran1 = lena:resize(lena:size(1), lena:nElement() / lena:size(1)):t()

   return tran1:t():resize(size)
end
function fail()
   -- image will glitch
   local lena = image.lena():clone()
   local size = lena:size()
   local tran1 = lena:resize(lena:size(1), lena:nElement() / lena:size(1)):t()

   tran1 = tran1:clone()

   return tran1:t():resize(size)
end

image.save("success.png", success())
image.save("fail.png", fail())

success
fail

[CentOS6.4] libjpeg.so.8 problem

I get the error pasted at bottom when I try to use image library of torch7 due to libjpeg.
I'm using torch7 at CentOS6.4 installed by torch-distro.

I have installed libjpeg-turbo, libjpeg-turbo-devel by yum but the what I get under /usr/lib are only libjpeg.so, libjpeg.so.62 and libjpeg.so.62.0.0.
I tried to download libjpeg.so.8 from web but I couldn't make it.

Is it possible to use ver.62 as alternate of ver.8 OR do you know a way to install ver.8 of libjpeg on CentOS6.4?

In [1]: require 'image'
Out[1]:
true


In [2]: image.load('sample.jpg')
Out[2]:
error loading module 'libjpeg' from file '/home/*******/torch-distro/install/lib/lua/5.1/libjpeg.so':
        libjpeg.so.8: cannot open shared object file: No such file or directory
warning: <libjpeg> could not be loaded (is it installed?)

...******/torch-distro/install/share/lua/5.1/dok/inline.lua:633: <image.loadJPG> libjpeg package not found, please install libjpeg
stack traceback:
        [C]: in function 'error'
        ...******/torch-distro/install/share/lua/5.1/dok/inline.lua:633: in function 'error'
        ...******/torch-distro/install/share/lua/5.1/image/init.lua:137: in function 'loader'
        ...******/torch-distro/install/share/lua/5.1/image/init.lua:275: in function 'f'
        [string "local f = function() return image.load('sampl..."]:2: in main chunk
        [C]: in function 'xpcall'
        ...******/torch-distro/install/share/lua/5.1/itorch/main.lua:194: in function <...******/torch-distro/install/share/lua/5.1/itorch/main.lua:160>
        ...******/torch-distro/install/share/lua/5.1/lzmq/poller.lua:75: in function 'poll'
        ...*****/torch-distro/install/share/lua/5.1/lzmq/impl/loop.lua:307: in function 'poll'
        ...*****/torch-distro/install/share/lua/5.1/lzmq/impl/loop.lua:325: in function 'sleep_ex'
        ...*****/torch-distro/install/share/lua/5.1/lzmq/impl/loop.lua:370: in function 'start'
        ...*****/torch-distro/install/share/lua/5.1/itorch/main.lua:374: in main chunk
        [C]: in function 'require'
        (command line):1: in main chunk
        [C]: at 0x00405330

In [3]:

image.load: number of dimensions (greyscale)

Currently in the doc for image.load, it is stated:

The returned res Tensor has size nChannel x height x width where nChannel is 1 (greyscale) or 3 (usually RGB or YUV).

meaning that the returned tensor should always be 3D.

But in the case where we load an image that has originally 3 or 4 channels and ask for a greyscale tensor by setting depth to 1 it returns a 2D tensor (due to this "[1]" in the code):

lena_path = "assets/lena.jpg" -- the lena image in the repo is RGB
img = image.load(lena_path, 1)
> img:size()
 512
 512
[torch.LongStorage of size 2]

Do you guys think we should correct this edge case? If yes, should we update the doc or fix the code?

multicore bottlenecks

I notice the following painful bottleneck.
Loading 1500 32x32 images to single-channel (load+rgb2y) with torch.setnumthreads(4) (or the default setting on a 4-core machine) : 22 seconds
Loading 1500 32x32 images (load+rgb2y) with torch.setnumthreads(1): 0.92 seconds

The bottleneck is in rgb2y's :add call, I guess for small tensors OpenMP racks up quite an overhead.

This is not a bug, just something that someone else might run into. 22 seconds vs 1 second is a big difference.

image.display(image.lena()) is not working

l = image.lena()
[0.0064s]
th> image.display(l)
...e/deepakjnath/torch/install/share/lua/5.1/trepl/init.lua:363: module 'qt' not found:No LuaRocks module found for qt
no field package.preload['qt']
no file '/home/deepakjnath/.luarocks/share/lua/5.1/qt.lua'
no file '/home/deepakjnath/.luarocks/share/lua/5.1/qt/init.lua'
no file '/home/deepakjnath/torch/install/share/lua/5.1/qt.lua'
no file '/home/deepakjnath/torch/install/share/lua/5.1/qt/init.lua'
no file './qt.lua'
no file '/home/deepakjnath/torch/install/share/luajit-2.1.0-alpha/qt.lua'
no file '/usr/local/share/lua/5.1/qt.lua'
no file '/usr/local/share/lua/5.1/qt/init.lua'
no file '/home/deepakjnath/.luarocks/lib/lua/5.1/qt.so'
no file '/home/deepakjnath/torch/install/lib/lua/5.1/qt.so'
no file './qt.so'
no file '/usr/local/lib/lua/5.1/qt.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'error'
...e/deepakjnath/torch/install/share/lua/5.1/trepl/init.lua:363: in function 'require'
...e/deepakjnath/torch/install/share/lua/5.1/image/init.lua:1237: in function 'display'
[string "_RESULT={image.display(l)}"]:1: in main chunk
[C]: in function 'xpcall'
...e/deepakjnath/torch/install/share/lua/5.1/trepl/init.lua:630: in function 'repl'
...nath/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:185: in main chunk
[C]: at 0x00406670
[0.0003s]
th>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.