libvips / pyvips Goto Github PK
View Code? Open in Web Editor NEWpython binding for libvips using cffi
License: MIT License
python binding for libvips using cffi
License: MIT License
I'm trying to resize a large image to a smaller width with a limited memory available 256MB (due to AWS lambda configuration). I used the code like this:
import pyvips
image = pyvips.Image.new_from_file(src_file, access='sequential')
image = image.resize(0.8/1.0)
image.write_to_file(dst_file)
In my local machine I'm testing it by putting a limit on Python VM using code like:
resource.setrlimit(resource.RLIMIT_AS, (maxsize, hard))
when I set the maxsize
to 256MB, I get Segmentation fault (core dumped)
error. I suppose this is coming from the vips C library. So, I have two questions:
I have built a code which will stitch 100X100 images approx. I want to view this stitiching process in real time. I am using pyvips to create large image. I am saving final image in .DZI format as it will take very less memory footprint to display. Below code is copied just for testing purpose https://github.com/jcupitt/pyvips/issues/43.
#!/usr/bin/env python
import sys
import pyvips
# overlap joins by this many pixels
H_OVERLAP = 100
V_OVERLAP = 100
# number of images in mosaic
ACROSS = 20
DOWN = 20
if len(sys.argv) < 2 + ACROSS * DOWN:
print 'usage: %s output-image input1 input2 ..'
sys.exit(1)
def join_left_right(filenames):
images = [pyvips.Image.new_from_file(filename) for filename in filenames]
row = images[0]
for image in images[1:]:
row = row.merge(image, 'horizontal', H_OVERLAP - row.width, 0)
return row
def join_top_bottom(rows):
image = rows[0]
for row in rows[1:]:
image = image.merge(row, 'vertical', 0, V_OVERLAP - image.height)
return image
rows = []
for y in range(0, DOWN):
start = 2 + y * ACROSS
end = start + ACROSS
rows.append(join_left_right(sys.argv[start:end]))
image = join_top_bottom(rows)
image.write_to_file(sys.argv[1])
To run this code:
$ export VIPS_DISC_THRESHOLD=100
$ export VIPS_PROGRESS=1
$ export VIPS_CONCURRENCY=1
$ mkdir sample
$ for i in {1..400}; do cp ~/pics/k2.jpg sample/$i.jpg; done
$ time ./mergeup.py x.dz sample/*.jpg
here cp ~/pics/k2.jpg
will copy k2.jpg
image 400 times from pics
folder, so change according to your image name and location.
I want to display this process in real time. Right now after creating final mosaiced image I am able to display. Just an idea,I am thinking to make a large image and display it, then insert smaller images. I don't know, how it can be done. I am confused as we also have to make pyramidal structure. So If we create large image first we have to replace each level images with the new images. Creating .DZI image is expensive, so I don't want to create it in every running loop. Replacing images may be a solution. Any suggestion folks??
pyvips sends g_warning() off to logging, but we could send g_info() as well
Hello @jcupitt
I am having a problem with saving the final result. I am using merge
function for stitching images. I don't face any problem in saving 25X25 images but when I exceed the limit to 80X80 images it gives an error, image resolution is 480X640px.
I am using coordinates to merge the images coor
is a numpy array having coordinate information.
Attaching sample code.
def stitch(coor):
global onlyfiles,mypath,row,column
onlyfiles=np.array(onlyfiles)
files=onlyfiles.reshape(row,column)
blend=False
for r in tqdm(range(files.shape[0])):
c=0
if r==0:
tile = pyvips.Image.black(coor[r,c][0],coor[r,c][1])
else:
tile = pyvips.Image.black(coor[r,c][0],coor[r,c][1]-coor[r-1,c][1])
for c in tqdm(range(files.shape[1])):
tile1 = pyvips.Image.new_from_file(join(mypath,files[r][c]), access="sequential")
if r==0:
x,y=coor[r,c]
else:
x,y=coor[r,c][0],coor[r,c][1]-coor[r-1,0][1]
tile = tile.merge(tile1, 'horizontal', -x, -y, mblend =blend)
if r>0:
y=coor[r-1,0][1]
stitch_img = stitch_img.merge(tile, 'vertical', 0, -y, mblend =blend)
else :
stitch_img=tile
print (stitch_img.width,stitch_img.height,"width","height")
stitch_img.dzsave('test_80X80')
Error:
Traceback (most recent call last):
File "stitcher_coor.py", line 217, in <module>
File "stitcher_coor.py", line 101, in stitch
File "/home/machine/.virtualenvs/project/lib/python3.6/site-packages/pyvips/vimage.py", line 783, in call_function
File "/home/machine/.virtualenvs/project/lib/python3.6/site-packages/pyvips/voperation.py", line 188, in call
pyvips.error.Error: unable to call dzsave
vips__file_open_read: unable to open file "/home/machine/Desktop/iter6/set4_80X80/25_13.jpeg" for reading
unix error: Too many open files
I have also set open files limit to the maximum.
I am new to pyvips. I am inable to find the syntax for writing these huge images in *.svs or *.tiff format. Please help.
We might need to trigger GC occasionally under pypy, and maybe add some memory pressure hints.
My install does:
sudo apt-get install libvips libvips-dev
pip install pyvips
A week ago this worked fine, and installed pyvips version 2.0.5 (libvips version 8.2.2-1) (Ubuntu 16.04, python 3.6)
However, now it is failing to install pyvips:
copying pyvips/voperation.py -> build/lib.linux-x86_64-3.6/pyvips\n'
' copying pyvips/enums.py -> build/lib.linux-x86_64-3.6/pyvips\n'
' copying pyvips/gvalue.py -> build/lib.linux-x86_64-3.6/pyvips\n'
' copying pyvips/vobject.py -> build/lib.linux-x86_64-3.6/pyvips\n'
' copying pyvips/version.py -> build/lib.linux-x86_64-3.6/pyvips\n'
' copying pyvips/base.py -> build/lib.linux-x86_64-3.6/pyvips\n'
' copying pyvips/decls.py -> build/lib.linux-x86_64-3.6/pyvips\n'
' copying pyvips/vimage.py -> build/lib.linux-x86_64-3.6/pyvips\n'
' copying pyvips/gobject.py -> build/lib.linux-x86_64-3.6/pyvips\n'
' running build_ext\n'
" generating cffi module 'build/temp.linux-x86_64-3.6/_libvips.c'\n"
' creating build/temp.linux-x86_64-3.6\n'
" building '_libvips' extension\n"
' creating build/temp.linux-x86_64-3.6/build\n'
' creating build/temp.linux-x86_64-3.6/build/temp.linux-x86_64-3.6\n'
' x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong '
'-Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DMAGICKCORE_HDRI_ENABLE=0 '
'-DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/include/libgsf-1 '
'-I/usr/include/libxml2 -I/usr/include/x86_64-linux-gnu//ImageMagick-6 -I/usr/include/ImageMagick-6 '
'-I/usr/include/x86_64-linux-gnu//ImageMagick-6 -I/usr/include/ImageMagick-6 -I/usr/include/orc-0.4 '
'-I/usr/include/OpenEXR -I/usr/include/openslide -I/usr/lib/x86_64-linux-gnu/hdf5/serial/include '
'-I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/freetype2 '
'-I/usr/include/x86_64-linux-gnu -I/usr/include/libpng12 -I/usr/include/libexif -I/usr/include/glib-2.0 '
'-I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/python3.6m -I/xx/venv/include/python3.6m -c '
'build/temp.linux-x86_64-3.6/_libvips.c -o build/temp.linux-x86_64-3.6/build/temp.linux-x86_64-3.6/_libvips.o\n'
' build/temp.linux-x86_64-3.6/_libvips.c: In function ‘_cffi_d_vips_image_get_fields’:\n'
' build/temp.linux-x86_64-3.6/_libvips.c:2795:10: warning: implicit declaration of function '
'‘vips_image_get_fields’ [-Wimplicit-function-declaration]\n'
' return vips_image_get_fields(x0);\n'
' ^\n'
' build/temp.linux-x86_64-3.6/_libvips.c:2795:10: warning: return makes pointer from integer without a cast '
'[-Wint-conversion]\n'
' build/temp.linux-x86_64-3.6/_libvips.c: In function ‘_cffi_f_vips_image_get_fields’:\n'
' build/temp.linux-x86_64-3.6/_libvips.c:2818:12: warning: assignment makes pointer from integer without a cast '
'[-Wint-conversion]\n'
' { result = vips_image_get_fields(x0); }\n'
' ^\n'
' build/temp.linux-x86_64-3.6/_libvips.c: In function ‘_cffi_checkfld__GValue’:\n'
' build/temp.linux-x86_64-3.6/_libvips.c:4569:25: warning: initialization from incompatible pointer type '
'[-Wincompatible-pointer-types]\n'
' { uint64_t(*tmp)[2] = &p->data; (void)tmp; }\n'
' ^\n'
' build/temp.linux-x86_64-3.6/_libvips.c: In function ‘_cffi_checkfld__VipsImage’:\n'
' build/temp.linux-x86_64-3.6/_libvips.c:4609:25: error: ‘VipsImage {aka struct _VipsImage}’ has no member named '
'‘parent_instance’\n'
' { VipsObject *tmp = &p->parent_instance; (void)tmp; }\n'
' ^\n'
' build/temp.linux-x86_64-3.6/_libvips.c: In function ‘_cffi_checkfld__VipsObject’:\n'
' build/temp.linux-x86_64-3.6/_libvips.c:4627:22: error: ‘VipsObject {aka struct _VipsObject}’ has no member named '
'‘parent_instance’\n'
' { GObject *tmp = &p->parent_instance; (void)tmp; }\n'
' ^\n'
' build/temp.linux-x86_64-3.6/_libvips.c:4630:19: warning: initialization from incompatible pointer type '
'[-Wincompatible-pointer-types]\n'
' { void * *tmp = &p->argument_table; (void)tmp; }\n'
' ^\n'
' In file included from /usr/include/sched.h:28:0,\n'
' from /usr/include/pthread.h:23,\n'
' from /usr/include/glib-2.0/glib/deprecated/gthread.h:128,\n'
' from /usr/include/glib-2.0/glib.h:107,\n'
' from /usr/include/vips/vips.h:85,\n'
' from build/temp.linux-x86_64-3.6/_libvips.c:493:\n'
' build/temp.linux-x86_64-3.6/_libvips.c: At top level:\n'
' build/temp.linux-x86_64-3.6/_libvips.c:4816:24: error: ‘VipsImage {aka struct _VipsImage}’ has no member named '
'‘parent_instance’\n'
' { "parent_instance", offsetof(VipsImage, parent_instance),\n'
' ^\n'
' build/temp.linux-x86_64-3.6/_libvips.c:4817:47: error: ‘VipsImage {aka struct _VipsImage}’ has no member named '
'‘parent_instance’\n'
' sizeof(((VipsImage *)0)->parent_instance),\n'
' ^\n'
' In file included from /usr/include/sched.h:28:0,\n'
' from /usr/include/pthread.h:23,\n'
' from /usr/include/glib-2.0/glib/deprecated/gthread.h:128,\n'
' from /usr/include/glib-2.0/glib.h:107,\n'
' from /usr/include/vips/vips.h:85,\n'
' from build/temp.linux-x86_64-3.6/_libvips.c:493:\n'
' build/temp.linux-x86_64-3.6/_libvips.c:4822:24: error: ‘VipsObject {aka struct _VipsObject}’ has no member named '
'‘parent_instance’\n'
' { "parent_instance", offsetof(VipsObject, parent_instance),\n'
' ^\n'
' build/temp.linux-x86_64-3.6/_libvips.c:4823:48: error: ‘VipsObject {aka struct _VipsObject}’ has no member named '
'‘parent_instance’\n'
' sizeof(((VipsObject *)0)->parent_instance),\n'
' ^\n'
" error: command 'x86_64-linux-gnu-gcc' failed with exit status 1\n"
' \n'
' ----------------------------------------\n'
'\n'
':stderr: Failed building wheel for pyvips\n'
'Command "/xx/venv/bin/python3.6 -u -c "import setuptools, '
"tokenize;__file__='/tmp/pip-build-mi3al6kr/pyvips/setup.py';f=getattr(tokenize, 'open', "
'open)(__file__);code=f.read().replace(\'\\r\\n\', \'\\n\');f.close();exec(compile(code, __file__, \'exec\'))" '
'install --record /tmp/pip-cm6ibh4v-record/install-record.txt --single-version-externally-managed --compile '
'--install-headers /xx/venv/include/site/python3.6/pyvips" failed with error code 1 in '
'/tmp/pip-build-mi3al6kr/pyvips/\n')
In [33]: logfile = 'output.txt'
In [34]: pp.pprint(msg, logfile)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-34-9ce2d8690c0f> in <module>()
----> 1 pp.pprint(msg, logfile)
TypeError: pprint() takes 2 positional arguments but 3 were given
In [35]: pp.pprint(msg, stream=logfile)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-35-388d0498a1f3> in <module>()
----> 1 pp.pprint(msg, stream=logfile)
TypeError: pprint() got an unexpected keyword argument 'stream'
In [36]: with open("output.txt", "w") as fout:
...: pprint(msg, fout)
...:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-36-3ac17316ab0b> in <module>()
1 with open("output.txt", "w") as fout:
----> 2 pprint(msg, fout)
3
TypeError: 'module' object is not callable
In [37]: os.path.exists(logfile)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-37-6ecdaa4b77dc> in <module>()
----> 1 os.path.exists(logfile)
NameError: name 'os' is not defined
' ^\n'
' build/temp.linux-x86_64-3.6/_libvips.c:4630:19: warning: initialization '
'from incompatible pointer type [-Wincompatible-pointer-types]\n'
' { void * *tmp = &p->argument_table; (void)tmp; }\n'
' ^\n'
' In file included from /usr/include/sched.h:28:0,\n'
' from /usr/include/pthread.h:23,\n'
' from '
'/usr/include/glib-2.0/glib/deprecated/gthread.h:128,\n'
' from /usr/include/glib-2.0/glib.h:107,\n'
' from /usr/include/vips/vips.h:85,\n'
' from build/temp.linux-x86_64-3.6/_libvips.c:493:\n'
' build/temp.linux-x86_64-3.6/_libvips.c: At top level:\n'
' build/temp.linux-x86_64-3.6/_libvips.c:4816:24: error: ‘VipsImage {aka '
'struct _VipsImage}’ has no member named ‘parent_instance’\n'
' { "parent_instance", offsetof(VipsImage, parent_instance),\n'
' ^\n'
' build/temp.linux-x86_64-3.6/_libvips.c:4817:47: error: ‘VipsImage {aka '
'struct _VipsImage}’ has no member named ‘parent_instance’\n'
' sizeof(((VipsImage *)0)->parent_instance),\n'
' ^\n'
' In file included from /usr/include/sched.h:28:0,\n'
' from /usr/include/pthread.h:23,\n'
' from '
'/usr/include/glib-2.0/glib/deprecated/gthread.h:128,\n'
' from /usr/include/glib-2.0/glib.h:107,\n'
' from /usr/include/vips/vips.h:85,\n'
' from build/temp.linux-x86_64-3.6/_libvips.c:493:\n'
' build/temp.linux-x86_64-3.6/_libvips.c:4822:24: error: ‘VipsObject {aka '
'struct _VipsObject}’ has no member named ‘parent_instance’\n'
' { "parent_instance", offsetof(VipsObject, parent_instance),\n'
' ^\n'
' build/temp.linux-x86_64-3.6/_libvips.c:4823:48: error: ‘VipsObject {aka '
'struct _VipsObject}’ has no member named ‘parent_instance’\n'
' sizeof(((VipsObject *)0)->parent_instance),\n'
' ^\n'
" error: command 'x86_64-linux-gnu-gcc' failed with exit status 1\n"
' \n'
' ----------------------------------------\n'
'\n'
':stderr: Failed building wheel for pyvips\n'
'Command "/xx/venv/bin/python3.6 -u -c "import setuptools, '
"tokenize;__file__='/tmp/pip-build-mi3al6kr/pyvips/setup.py';f=getattr(tokenize, "
"'open', open)(__file__);code=f.read().replace('\\r\\n', "
'\'\\n\');f.close();exec(compile(code, __file__, \'exec\'))" install --record '
'/tmp/pip-cm6ibh4v-record/install-record.txt '
'--single-version-externally-managed --compile --install-headers '
'/xx/venv/include/site/python3.6/pyvips" failed with error code 1 in '
'/tmp/pip-build-mi3al6kr/pyvips/\n'
My libvips/libvips-dev versions are still 8.2.2-1, but the latest pypi pyvips version is 2.1.0. pip install pyvips==2.0.5
works fine.
The docs still say that pyvips just needs libvips > 8.2. Does the latest version of pyvips actually require a later version of libvips than 8.2.2-1 (which is the latest 16.04 debian package)
I'm working on streaming image sequences into ffmpeg.
Roughly, this is my code:
image_original = pyvips.Image.new_from_file(self.file_path)
p = Popen(['/usr/local/bin/ffmpeg', '-y', '-f', 'image2pipe', '-vcodec', 'mjpeg', '-r', self.fps, '-i', '-', '-r', self.fps, '-f', 'mp4', '-vcodec', 'libx264', '-crf', '26', 'output/{}.mp4'.format(self.animation_name)], stdin=PIPE)
for image in images:
image.smartcrop(self.output_raster_width, self.output_raster_height)
image.jpegsave(p.stdin, profile='JPEG')
p.stdin.close()
p.wait()
This yields an error, but I suspect I'm not using the right method to do the sdtin write. Is there a good way to handle this use case?
TODO before we can declare 1.0:
__eq__
on the enum compat classes?pyvips.Image.black(1, 1)
help()
, we should test in one of the Python IDEs__pypy__.add_memory_pressure(n)
for PyPyPlease add more items!
I am doing the following:
import logging
logging.basicConfig(level = logging.DEBUG)
import numpy as np
import pyvips
print("pyvips version: ", pyvips.__version__)
arr = np.array([[-1, -1, -1],
[-1, 16, -1],
[-1, -1, -1]])
height, width = arr.shape
bands = 1
linear = arr.reshape(width * height * bands)
vi = pyvips.Image.new_from_memory(linear.data, width, height, bands, 'uchar')
The result is:
DEBUG:pyvips:Loaded binary module _libvips
DEBUG:pyvips:Inited libvips
DEBUG:pyvips:
pyvips version: 2.1.2
(pyv.py:52631): GLib-GObject-WARNING **: 15:58:03.238: cannot retrieve class for invalid (unclassed) type '<invalid>'
Traceback (most recent call last):
File "pyv.py", line 16, in <module>
vi = pyvips.Image.new_from_memory(linear.data, width, height, bands, 'uchar')
File "/usr/local/miniconda3/envs/apollo_env/lib/python3.6/site-packages/pyvips/vimage.py", line 332, in new_from_memory
format_value = GValue.to_enum(GValue.format_type, format)
File "/usr/local/miniconda3/envs/apollo_env/lib/python3.6/site-packages/pyvips/gvalue.py", line 105, in to_enum
format(value, type_name(gtype), gtype))
File "/usr/local/miniconda3/envs/apollo_env/lib/python3.6/site-packages/pyvips/base.py", line 71, in type_name
return _to_string(ffi.string(gobject_lib.g_type_name(gtype)))
RuntimeError: cannot use string() on <cdata 'char *' NULL>
I am using vips 8.6.5 on MacOS X:
$ vips -v
vips-8.6.5-Wed Jul 25 09:46:22 UTC 2018
Hello, @jcupitt!
I am new to pyvips, I want to create a large image. Following steps, I have to take:
Issues:
import sys
import random
from PIL import Image
import numpy as np
import pyvips
output_size = 2000
bg = pyvips.Image.black(output_size, output_size, bands=3)
tile1 = pyvips.Image.new_from_file('1805_corrected.jpg', access="sequential")
tile2 = pyvips.Image.new_from_file('1806_corrected.jpg', access="sequential")
vips_image1 = tile1.embed(0, 0, output_size, output_size)
vips_image2 = tile2.embed(1000,1000, output_size, output_size)
vips_image=vips_image1.composite(vips_image2,["over"])
vips_image.write_to_file('vi_1.tiff')
I'm writing a AWS Lambda function using pyvips python package. But it throws exception when import pyvips
is executed. The error is as follows. I've zipped cffi, pycparser, pyvips and a lib directory which contains all the shared libraries of libvips for lambda build package. I've also set the environment variable LD_LIBRARY_PATH=./lib:LD_LIBRARY_PATH
.The lambda.zip that I'm uploading to the AWS lambda can be found here.
cannot load library 'libvips.so.42': /lib64/libz.so.1: version `ZLIB_1.2.9' not found (required by ./lib/libpng16.so.16). Additionally, ctypes.util.find_library() did not manage to locate a library called 'libvips.so.42': OSError
Traceback (most recent call last):
File "/var/task/lambda.py", line 5, in lambda_handler
import pyvips
File "/var/task/pyvips/__init__.py", line 54, in <module>
vips_lib = ffi.dlopen(_vips_libname)
File "/var/task/cffi/api.py", line 141, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "/var/task/cffi/api.py", line 802, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "/var/task/cffi/api.py", line 797, in _load_backend_lib
raise OSError(msg)
OSError: cannot load library 'libvips.so.42': /lib64/libz.so.1: version `ZLIB_1.2.9' not found (required by ./lib/libpng16.so.16). Additionally, ctypes.util.find_library() did not manage to locate a library called 'libvips.so.42'
END RequestId: af867599-5876-11e8-a3ca-ffec3ebba19d
REPORT RequestId: af867599-5876-11e8-a3ca-ffec3ebba19d Duration: 459.45 ms Billed Duration: 500 ms Memory Size: 128 MB Max Memory Used: 21 MB
This may not be a problem of libvips or pyvips but some setting in AWS Lambda function that I don't know.
Created an issue with AWS as well.
Hi, @jcupitt!
I'd like to ask you to review pyvips results in pillow-perf benchmarks.
Originally in this benchmark, there was one test for one operation. As VIPS works differently, I've added "Full operations cycle" competition with several operations in each test (from two to five). To see index and numbers, hover the graphs. Please note, all tests are run in a single thread, the explanation of this is given at the start of the page.
At first, I'd like you to check the benchmark code. Is it correct and is it equivalent to Pillow code?
Benchmarks repository and readme
Pyvips code
Pillow code
If you uncomment the last line, you could compare results visually. They are almost identical except small shift for VIPS, I already seen the issue about this.
There are results for three systems: Macbook with Core i5, EC2 c3.large and EC2 c4.large. On Macbook I have libvips 8.5.7 from sources with the following configuration:
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for gobject-introspection... no
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for needs -lstdc++... yes
checking for native Win32... no
checking for binary open needed... no
checking for Mac OS X... no
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... no
checking for gawk... (cached) mawk
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking for gcc option to accept ISO C99... none needed
checking for gcc option to accept ISO Standard C... (cached) none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... gcc3
checking for an ANSI C-conforming const... yes
checking for C/C++ restrict keyword... __restrict
checking for ranlib... ranlib
checking whether ln -s works... yes
checking if malloc debugging is wanted... no
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking locale.h usability... yes
checking locale.h presence... yes
checking for locale.h... yes
checking for LC_MESSAGES... yes
checking libintl.h usability... yes
checking libintl.h presence... yes
checking for libintl.h... yes
checking for ngettext in libc... yes
checking for dgettext in libc... yes
checking for bind_textdomain_codeset... yes
checking for msgfmt... /usr/bin/msgfmt
checking for dcgettext... yes
checking if msgfmt accepts -c... yes
checking for gmsgfmt... /usr/bin/msgfmt
checking for xgettext... /usr/bin/xgettext
checking for catalogs to be installed... en_GB de
checking for dirent.h that defines DIR... yes
checking for library containing opendir... none required
checking for ANSI C header files... (cached) yes
checking errno.h usability... yes
checking errno.h presence... yes
checking for errno.h... yes
checking math.h usability... yes
checking math.h presence... yes
checking for math.h... yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking limits.h usability... yes
checking limits.h presence... yes
checking for limits.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking sys/file.h usability... yes
checking sys/file.h presence... yes
checking for sys/file.h... yes
checking sys/ioctl.h usability... yes
checking sys/ioctl.h presence... yes
checking for sys/ioctl.h... yes
checking sys/param.h usability... yes
checking sys/param.h presence... yes
checking for sys/param.h... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking sys/mman.h usability... yes
checking sys/mman.h presence... yes
checking for sys/mman.h... yes
checking for sys/types.h... (cached) yes
checking for sys/stat.h... (cached) yes
checking for unistd.h... (cached) yes
checking io.h usability... no
checking io.h presence... no
checking for io.h... no
checking direct.h usability... no
checking direct.h presence... no
checking for direct.h... no
checking windows.h usability... no
checking windows.h presence... no
checking for windows.h... no
checking for dllwrap... no
checking for dlltool... dlltool
checking for objdump... objdump
checking for ranlib... (cached) ranlib
checking for strip... strip
checking for ar... ar
checking for as... as
checking for ld... ld
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by gcc... ld
checking if the linker (ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for ld option to reload object files... -r
checking for objdump... (cached) objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... (cached) dlltool
checking how to associate runtime and link libraries... printf %s\n
checking for archiver @FILE support... @
checking for strip... (cached) strip
checking for ranlib... (cached) ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking how to run the C++ preprocessor... g++ -E
checking for ld used by g++... ld -m elf_x86_64
checking if the linker (ld -m elf_x86_64) is GNU ld... yes
checking whether the g++ linker (ld -m elf_x86_64) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC -DPIC
checking if g++ PIC flag -fPIC -DPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking if g++ supports -c -o file.o... (cached) yes
checking whether the g++ linker (ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... (cached) GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking for an ANSI C-conforming const... (cached) yes
checking for mode_t... yes
checking for off_t... yes
checking for size_t... yes
checking for working memcmp... yes
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for sys/param.h... (cached) yes
checking for getpagesize... yes
checking for working mmap... yes
checking for vprintf... yes
checking for _doprnt... no
checking for getcwd... yes
checking for gettimeofday... yes
checking for getwd... yes
checking for memset... yes
checking for munmap... yes
checking for putenv... yes
checking for realpath... yes
checking for strcasecmp... yes
checking for strchr... yes
checking for strcspn... yes
checking for strdup... yes
checking for strerror... yes
checking for strrchr... yes
checking for strspn... yes
checking for vsnprintf... yes
checking for realpath... (cached) yes
checking for mkstemp... yes
checking for mktemp... yes
checking for random... yes
checking for rand... yes
checking for sysconf... yes
checking for atexit... yes
checking for cbrt in -lm... yes
checking for hypot in -lm... yes
checking for atan2 in -lm... yes
checking for REQUIRED... yes
checking for CONTEXT_GET_HELP... yes
checking for MONOTONIC... yes
checking for THREADS... yes
checking for TYPE_INIT... no
checking for TYPE_INIT... yes
checking for gtk-doc... no
configure: WARNING:
You will not be able to create source packages with 'make dist'
because gtk-doc >= 1.14 is not found.
checking for gtkdoc-check... no
checking for gtkdoc-check... no
checking for gtkdoc-rebase... no
checking for gtkdoc-mkpdf... no
checking whether to build gtk-doc documentation... no
checking for GTKDOC_DEPS... yes
checking for XML_ParserCreate in -lexpat... yes
checking expat.h usability... yes
checking expat.h presence... yes
checking for expat.h... yes
checking for GSF... yes
checking for GSF_ZIP64... yes
checking for FFTW... yes
checking for MAGICK_WAND... yes
checking for MAGICK... no
checking for MAGICK... yes
checking for SetImageOption... yes
checking for MagickCoreGenesis... yes
checking for ResetImagePropertyIterator... yes
checking for ResetImageAttributeIterator... yes
checking for GetVirtualPixels... yes
checking for struct _ImageInfo.number_scenes... yes
checking for ORC... yes
checking for orc_program_get_error... yes
checking for LCMS... yes
checking for OPENEXR... yes
checking for POPPLER... yes
checking for RSVG... yes
checking for X... libraries , headers
checking for gethostbyname... yes
checking for connect... yes
checking for remove... yes
checking for shmat... yes
checking for IceConnectionNumber in -lICE... yes
checking for ZLIB... yes
checking for OPENSLIDE... yes
checking for MATIO... yes
checking for CFITSIO... yes
checking for LIBWEBP... yes
checking for LIBWEBPMUX... no
configure: WARNING: libwebpmux not found; disabling webp metadata support
checking for PANGOFT2... yes
configure: WARNING: pygobject-3.0 not found; disabling vips8 python support
checking for TIFF... yes
checking for giflib... libraries -lgif, headers in default path
checking for PNG... yes
checking for JPEG... libraries -ljpeg, headers in default path
checking for jpeg_c_bool_param_supported... no
checking for EXIF... yes
checking exif-data.h usability... yes
checking exif-data.h presence... yes
checking for exif-data.h... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating vips.pc
config.status: creating vipsCC.pc
config.status: creating vips-cpp.pc
config.status: creating Makefile
config.status: creating libvips/include/vips/version.h
config.status: creating libvips/include/Makefile
config.status: creating libvips/include/vips/Makefile
config.status: creating libvips/Makefile
config.status: creating libvips/arithmetic/Makefile
config.status: creating libvips/colour/Makefile
config.status: creating libvips/conversion/Makefile
config.status: creating libvips/convolution/Makefile
config.status: creating libvips/deprecated/Makefile
config.status: creating libvips/foreign/Makefile
config.status: creating libvips/freqfilt/Makefile
config.status: creating libvips/histogram/Makefile
config.status: creating libvips/draw/Makefile
config.status: creating libvips/iofuncs/Makefile
config.status: creating libvips/morphology/Makefile
config.status: creating libvips/mosaicing/Makefile
config.status: creating libvips/create/Makefile
config.status: creating libvips/resample/Makefile
config.status: creating libvips/video/Makefile
config.status: creating libvipsCC/include/Makefile
config.status: creating libvipsCC/include/vips/Makefile
config.status: creating libvipsCC/Makefile
config.status: creating cplusplus/include/Makefile
config.status: creating cplusplus/include/vips/Makefile
config.status: creating cplusplus/Makefile
config.status: creating tools/Makefile
config.status: creating tools/batch_crop
config.status: creating tools/batch_image_convert
config.status: creating tools/batch_rubber_sheet
config.status: creating tools/light_correct
config.status: creating tools/shrink_width
config.status: creating python/Makefile
config.status: creating python/packages/Makefile
config.status: creating python/packages/gi/Makefile
config.status: creating python/packages/gi/overrides/Makefile
config.status: creating test/Makefile
config.status: creating test/variables.sh
config.status: creating swig/Makefile
config.status: creating swig/vipsCC/Makefile
config.status: creating man/Makefile
config.status: creating doc/Makefile
config.status: creating doc/libvips-docs.xml
config.status: creating po/Makefile.in
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
config.status: executing default-1 commands
config.status: executing libtool commands
* build options
native win32: no
native OS X: no
open files in binary mode: no
enable debug: no
build deprecated components: yes
build docs with gtkdoc: no
gobject introspection: no
build vips7 Python binding: no
install vips8 Python overrides: no
(requires pygobject-3.13.0 or later)
build radiance support: yes
build analyze support: yes
build PPM support: yes
* optional dependencies
use fftw3 for FFT: yes
Magick package: MagickCore
file import with libMagick: yes (magick6)
accelerate loops with orc: yes
(requires orc-0.4.11 or later)
ICC profile support with lcms: yes (lcms2)
file import with OpenEXR: yes
file import with OpenSlide: yes
(requires openslide-3.3.0 or later)
file import with matio: yes
PDF import with poppler-glib: yes
(requires poppler-glib 0.16.0 or later)
SVG import with librsvg-2.0: yes
(requires librsvg-2.0 2.34.0 or later)
zlib: yes
file import with cfitsio: yes
file import/export with libwebp: yes
(requires libwebp-0.1.3 or later)
support webp metadata: no
(requires libwebpmux-0.5 or later)
text rendering with pangoft2: yes
file import/export with libpng: yes (pkg-config libpng >= 1.2.9)
(requires libpng-1.2.9 or later)
file import/export with libtiff: yes (pkg-config libtiff-4)
file import/export with giflib: yes (found by search)
file import/export with libjpeg: yes
image pyramid export: yes
(requires libgsf-1 1.14.26 or later)
use libexif to load/save JPEG metadata: yes
And on ec2 instances, I have VIPS 8.2 from Ubuntu package.
The strange thing is VIPS from sources works signifficantly slower than from the repo. This is VIPS 8.5 from sources compared with VIPS 8.2 from a package on the same computer:
Vips full cycle 2560×1600 RGB image
Load+save 0.06170 s 66.39 Mpx/s
+transpose 0.06942 s 59.00 Mpx/s
+resize 0.27630 s 14.82 Mpx/s
+blur 0.40508 s 10.11 Mpx/s
Vips full cycle 2560×1600 RGB image
Load+save 0.06210 s 65.96 Mpx/s
+transpose 0.07080 s 57.85 Mpx/s
+resize 0.14978 s 27.35 Mpx/s
+blur 0.27115 s 15.11 Mpx/s
I also tried to build VIPS 8.2 from sources, it has the same speed as 8.5 from sources. Do you have explanation for this?
Hi,
I can open files without an issue and all the things work well then. But if I directly pass the bytes what I got from aiohttp, it throws an error: TypeError: initializer for ctype 'int(*)(void *, void *)' must be a pointer to same type, not cdata 'void(*)(void *)'
Here is my buffer's first few lines:
b"\x89PNG\r\n\x1a\n\x00\x00"
And some details from Sentry if you need them image
What can I do?
The test suite currently fails on Windows due to temp file handling. We should do something better to remove files we're finished with.
Setup libvips using:
curl -L -O https://github.com/jcupitt/libvips/releases/download/v8.6.5/vips-8.6.5.tar.gz
tar xvf vips-8.6.5.tar.gz
cd vips-8.6.5
./configure --prefix=/home/jramapuram/usr/
make && make install
Verify:
-bash-4.1$ ls /home/jramapuram/usr/lib
libvips.a libvipsCC.la libvipsCC.so.42 libvips-cpp.a libvips-cpp.so libvips-cpp.so.42.8.4 libvips.so libvips.so.42.8.4
libvipsCC.a libvipsCC.so libvipsCC.so.42.8.4 libvips-cpp.la libvips-cpp.so.42 libvips.la libvips.so.42 pkgconfig
Check LD_LIBRARY_PATH
:
-bash-4.1$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/jramapuram/usr/lib
-bash-4.1$ env | grep LD
LD_LIBRARY_PATH=/home/jramapuram/cuda-9.1/lib64:/usr/mpi/gcc/openmpi-1.6.5/lib:/home/jramapuram/usr/lib
Import pyvips:
In [1]: import logging
...: logging.basicConfig(level = logging.DEBUG)
...: import pyvips
...:
DEBUG:pyvips:Binary module load failed: No module named '_libvips'
DEBUG:pyvips:Falling back to ABI mode
DEBUG:pyvips:Loaded lib <cffi.api._make_ffi_library.<locals>.FFILibrary object at 0x2b67c4249780>
DEBUG:pyvips:Loaded lib <cffi.api._make_ffi_library.<locals>.FFILibrary object at 0x2b67c42419b0>
DEBUG:pyvips:Inited libvips
I have also tried:
bdist_wheel
and compilePATH
to vips binary (/usr/jramapuram/usr/binI am running OSX. I've homebrew'd vips, the pip installed pyvips. In an attempt to load a jpeg image, I've gotten an error. Here is my code:
import pyvips
image = pyvips.Image.new_from_file(vips_filename="IMG_0015_guides.jpg")
error:
(process:43653): GLib-CRITICAL **: g_datalist_id_set_data_full: assertion 'key_id > 0' failed
(process:43653): GLib-GObject-CRITICAL **: g_param_spec_pool_lookup: assertion 'pool != NULL' failed
(process:43653): GLib-GObject-WARNING **: g_object_set_is_valid_property: object class '(null)' has no property named 'filename'
Traceback (most recent call last):
File "/Users/marcleonard/Sites/asvcu_dev/www/FlaskApp/FlaskApp/ArtstreamVideoWorkflow/test.py", line 3, in <module>
image = pyvips.Image.new_from_file(vips_filename="IMG_0015_guides.jpg")
File "/Users/marcleonard/anaconda3/lib/python3.6/site-packages/pyvips/vimage.py", line 254, in new_from_file
), **kwargs)
File "/Users/marcleonard/anaconda3/lib/python3.6/site-packages/pyvips/voperation.py", line 213, in call
raise Error('unable to call {0}'.format(operation_name))
pyvips.error.Error: unable to call VipsForeignLoadJpegFile
jpegload: parameter filename not set
I have installed pyvips on Mac by first compiling/installing VIPS from source and then PYVIPS with pip.
Initial module load is successful:
Python 3.6.4 |Anaconda, Inc.| (default, Dec 21 2017, 15:39:08)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import logging
...: logging.basicConfig(level = logging.DEBUG)
...: import pyvips
...:
DEBUG:pyvips:Loaded binary module _libvips
DEBUG:pyvips:Inited libvips
DEBUG:pyvips:
However when I try to load a JPEG or TIFF image I am getting:
In [2]: fn = "./whatever.jpeg"
In [3]: image = pyvips.Image.new_from_file(fn, access='sequential', filename=fn)
DEBUG:pyvips.voperation:VipsOperation.call: operation_name = VipsForeignLoadJpegFile
DEBUG:pyvips.voperation:VipsOperation.call: string_options =
DEBUG:pyvips.voperation:VipsOperation.call: match_image = None
DEBUG:pyvips.vobject:VipsObject.set: name = filename, value = ./whatever.jpeg
(process:99721): GLib-CRITICAL **: g_datalist_id_set_data_full: assertion 'key_id > 0' failed
(process:99721): GLib-GObject-CRITICAL **: g_param_spec_pool_lookup: assertion 'pool != NULL' failed
(process:99721): GLib-GObject-WARNING **: g_object_set_is_valid_property: object class '(null)' has no property named 'filename'
DEBUG:pyvips.vobject:VipsObject.set: name = access, value = sequential
(process:99721): GLib-CRITICAL **: g_datalist_id_set_data_full: assertion 'key_id > 0' failed
(process:99721): GLib-GObject-CRITICAL **: g_param_spec_pool_lookup: assertion 'pool != NULL' failed
(process:99721): GLib-GObject-WARNING **: g_object_set_is_valid_property: object class '(null)' has no property named 'access'
DEBUG:pyvips.vobject:VipsObject.set: name = filename, value = ./whatever.jpeg
(process:99721): GLib-CRITICAL **: g_datalist_id_set_data_full: assertion 'key_id > 0' failed
(process:99721): GLib-GObject-CRITICAL **: g_param_spec_pool_lookup: assertion 'pool != NULL' failed
(process:99721): GLib-GObject-WARNING **: g_object_set_is_valid_property: object class '(null)' has no property named 'filename'
DEBUG:pyvips.error:Error unable to call VipsForeignLoadJpegFile jpegload: parameter filename not set
---------------------------------------------------------------------------
Error Traceback (most recent call last)
<ipython-input-3-5d3ba5f3eef3> in <module>()
----> 1 image = pyvips.Image.new_from_file(fn, access='sequential', filename=fn)
/Applications/anaconda3/envs/kidney/lib/python3.6/site-packages/pyvips/vimage.py in new_from_file(vips_filename, **kwargs)
214 string_options=_to_string(
215 ffi.string(options)
--> 216 ), **kwargs)
217
218 @staticmethod
/Applications/anaconda3/envs/kidney/lib/python3.6/site-packages/pyvips/voperation.py in call(operation_name, *args, **kwargs)
186 vop = vips_lib.vips_cache_operation_build(op.pointer)
187 if vop == ffi.NULL:
--> 188 raise Error('unable to call {0}'.format(operation_name))
189 op = Operation(vop)
190
Error: unable to call VipsForeignLoadJpegFile
jpegload: parameter filename not set
Any idea what's wrong here?
Hi,
I am trying to stitch a large number of smaller "tiled" images (~7000, 512x512 pixels) to create one large image (~90000x40000 pixels). The "tiled" images may have overlap and some tiles are missing (these areas should just be black). I tried solving the problem using the code below:
def saveImage(width, height, X, Y, fileNames, outputFileName):
I = pyvips.Image.black(width, height, bands=3);
for x, y, fileName in zip(X, Y, fileNames):
C = pyvips.Image.new_from_file(fileName, access='sequential');
I = I.insert(C, x, y);
I.write_to_file(outputFileName);
If I have understood it correctly, the line I = I.insert(C, x, y)
creates a new copy of the large image every iteration. I assume this is the culprit somehow, but I have no idea on how to fix it.
I am using Python 3.6 64 bit version, Windows 10 and have 64 GB RAM.
Hello @jcupitt
I have used merge
function to stitch the image. Is there any function to global balance the final mosaiced image. As you can see in the attached image contrast is not balanced in each tile.
I know there is a function globalbalance
in pyvips but it works with only mosaiced
function. Is there any way to do balancing using merge function or any other way?
Hello,
I used pyvips on Linux and everything worked pretty well. Now I try to set up pyvips on Windows. Following the instruction and setting path in environment variable, I got this error:
Traceback (most recent call last):
File "C:\Python37-32\lib\site-packages\pyvips_init_.py", line 19, in
import _libvips
ModuleNotFoundError: No module named '_libvips'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/HaoyueZhang/Documents/GitHub/prediction_overlay/venv/overlay_Mask_R.py", line 9, in
import pyvips
File "C:\Python37-32\lib\site-packages\pyvips_init_.py", line 69, in
vips_lib = ffi.dlopen(_vips_libname)
File "C:\Python37-32\lib\site-packages\cffi\api.py", line 141, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "C:\Python37-32\lib\site-packages\cffi\api.py", line 802, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "C:\Python37-32\lib\site-packages\cffi\api.py", line 798, in _load_backend_lib
return backend.load_library(path, flags)
OSError: cannot load library 'C:\Program Files\vips-dev-8.6\bin\libvips-42.dll': error 0xc1
I saw another issue similar to this one so I tried moving the VIPS path to top, still no luck.
In command line I get correct output from "vips"
Usage:
vips [OPTIONâ?▌] [ACTION] [OPTIONS] [PARAMETERS] - VIPS driver program
Help Options:
-h, --help Show help options
Application Options:
-l, --list=BASE-NAME list objects
-p, --plugin=PLUGIN load PLUGIN
-v, --version print version
--vips-concurrency=N evaluate with N concurrent threads
--vips-progress show progress feedback
--vips-leak leak-check on exit
--vips-profile profile and dump timing on exit
--vips-disc-threshold=N images larger than N are decompressed to disc
--vips-novector disable vectorised versions of operations
--vips-cache-max=N cache at most N operations
--vips-cache-max-memory=N cache at most N bytes in memory
--vips-cache-max-files=N allow at most N open files
--vips-cache-trace trace operation cache
--vips-cache-dump dump operation cache on exit
--vips-version print libvips version
I am using the latest version of libvips and pyvips, and I tried to load this image...
I did:
image = pyvips.Image.new_from_file('test.png')
image = image.invert()
image.pngsave('invert.png', strip=True)
And I got the following result:
What can cause this? The lib doesn't support alpha channels?
Hi,
I am trying to use the smartcrop feature, and it looks like it isn't picking up the binding.
import pyvips
img = pyvips.Image.new_from_file('inv/1/0001_0001.tif', access='sequential')
img.smartcrop(100,100,interesting='attention')
This results in the following stack trace:
Traceback (most recent call last):
File "test.py", line 3, in <module>
img.smartcrop(100,100,interesting='attention')
File "/home/jflat06/.local/lib/python2.7/site-packages/pyvips/vimage.py", line 799, in call_function
return pyvips.Operation.call(name, self, *args, **kwargs)
File "/home/jflat06/.local/lib/python2.7/site-packages/pyvips/voperation.py", line 132, in call
op = Operation.new_from_name(operation_name)
File "/home/jflat06/.local/lib/python2.7/site-packages/pyvips/voperation.py", line 60, in new_from_name
raise Error('no such operation {0}'.format(operation_name))
pyvips.error.Error: no such operation smartcrop
VipsOperation: class "smartcrop" not found
This is using version 2.1.3 on Ubuntu 18.04:
$ pip show pyvips
Name: pyvips
Version: 2.1.3
Summary: binding for the libvips image processing library, ABI mode
Home-page: https://github.com/jcupitt/pyvips
Author: ---
Author-email: ---
License: MIT
Location: /home/user/.local/lib/python2.7/site-packages
Requires: cffi
Maybe similar to #33?
I installed libvips 8.6.2 from source, with pyvips 2.1.2 (ubuntu 16.04, python 3.6), and ran into the following error using pyvips (via gdal2mbtiles, which I am in the process of upgrading to use pyvips):
File "/venv/src/pyvips/pyvips/__init__.py", line 153, in <module>
from .gvalue import *
File "/venv//src/pyvips/pyvips/gvalue.py", line 26, in <module>
class GValue(object):
File "/venv/src/pyvips/pyvips/gvalue.py", line 60, in GValue
pyvips.vips_lib.vips_blend_mode_get_type()
AttributeError: cffi library '_libvips' has no function, constant or global variable named 'vips_blend_mode_get_type'
I can see in gvalue.py
that vips_blend_mode_get_type is only wrapped for 8.6+. Installed 8.5.9 from source and everything worked fine.
In ipython shell:
In [1]: import pkgconfig
In [2]: pkgconfig.installed('vips', '==8.6.2')
Out[2]: True
In [3]: import pyvips
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-b1ec53e8f619> in <module>()
----> 1 import pyvips
~/venv/lib/python3.6/site-packages/pyvips/__init__.py in <module>()
151 from .base import *
152 from .gobject import *
--> 153 from .gvalue import *
154 from .vobject import *
155 from .vinterpolate import *
~/venv/lib/python3.6/site-packages/pyvips/gvalue.py in <module>()
24
25
---> 26 class GValue(object):
27
28 """Wrap GValue in a Python class.
~/venv/lib/python3.6/site-packages/pyvips/gvalue.py in GValue()
58
59 if at_least_libvips(8, 6):
---> 60 pyvips.vips_lib.vips_blend_mode_get_type()
61 blend_mode_type = type_from_name('VipsBlendMode')
62
AttributeError: cffi library '_libvips' has no function, constant or global variable named 'vips_blend_mode_get_type'
I have the following error when running pytest tests/test_foreign.py
on master with vips 8.6.3:
============================= test session starts ==============================
platform darwin -- Python 2.7.15, pytest-3.6.1, py-1.5.3, pluggy-0.6.0
rootdir: /Users/felix/dev/misc/pyvips, inifile: tox.ini
collected 19 items
tests/test_foreign.py ....F..ssss........ [100%]
=================================== FAILURES ===================================
_________________________ TestForeign.test_magickload __________________________
self = <tests.test_foreign.TestForeign instance at 0x10b4a0ea8>
@pytest.mark.skipif(not have("magickload") or
not os.path.isfile(BMP_FILE),
reason="no magick support, skipping test")
def test_magickload(self):
def bmp_valid(im):
a = im(100, 100)
assert_almost_equal_objects(a, [227, 216, 201])
assert im.width == 1419
assert im.height == 1001
self.file_loader("magickload", BMP_FILE, bmp_valid)
self.buffer_loader("magickload_buffer", BMP_FILE, bmp_valid)
# we should have rgba for svg files
im = pyvips.Image.magickload(SVG_FILE)
> assert im.bands == 4
E assert 3 == 4
E + where 3 = <pyvips.Image 360x588 ushort, 3 bands, rgb16>.bands
tests/test_foreign.py:333: AssertionError
================ 1 failed, 14 passed, 4 skipped in 6.81 seconds ================
libvips is linked against libMagickCore-7.Q16HDRI.6.dylib
from ImageMagick 7.0.7-29.
I'm not sure if this is the right place to report the issue, since the underlying problem seems to be in libvips.
As far as I can see this issue does not occur with ImageMagick 6.x.
Hi
I get the following error when importing pyvips:
$ python testvips.py
DEBUG:pyvips:Binary module load failed: No module named '_libvips'
DEBUG:pyvips:Falling back to ABI mode
DEBUG:pyvips:Loaded lib <cffi.api._make_ffi_library.<locals>.FFILibrary object at 0x7fd20b984278>
DEBUG:pyvips:Loaded lib <cffi.api._make_ffi_library.<locals>.FFILibrary object at 0x7fd20b9e1eb8>
DEBUG:pyvips:Inited libvips
DEBUG:pyvips:
Traceback (most recent call last):
File "testvips.py", line 4, in <module>
import pyvips
File "/REDACTED/.venv/lib/python3.5/site-packages/pyvips/__init__.py", line 75, in <module>
import decls
ImportError: No module named 'decls'
I tried on 2 machines with the same result:
I ran sudo apt-get install libvips libvips-dev libvips-tools --no-install-recommends
Then in my virtualenv pip install pyvips
pip show
tells me pyvips is Version: 2.1.1 in ABI mode
Is there anything I missed?
Hi,
handling images that would cause a fallback towards ImageMagick doesn't work as expected. Given an exemplary image, located at https://www.welt.de/favicon.ico, the actual vips-cli is capable to handle it. A command like
vips copy favicon.ico favicon.jpeg
completes without any error. Also the following python code completes without any error:
img = pyvips.Image.new_from_file("favicon.ico")
print "Height: %s; Width: %s" % (img.height, img.width)
But loading the image from the buffer will result in an error:
with open("favicon.ico", "rb") as f:
buf = f.read()
img = pyvips.Image.new_from_buffer(buf, '*')
->
Traceback (most recent call last):
File "test.py", line 10, in <module>
img = pyvips.Image.new_from_buffer(buf, "")
File "/home/philip/.local/lib/python2.7/site-packages/pyvips/vimage.py", line 247, in new_from_buffer
raise Error('unable to load from buffer')
pyvips.error.Error: unable to load from buffer
VipsForeignLoad: buffer is not in a known format
Hi,
After doing pip install pyvips, I'm unable to find the autogenerated methods, though I am able to run the example:
import pyvips
image = pyvips.Image.new_from_file('my_file.jpg', access='sequential')
image *= [1, 2, 1]
mask = pyvips.Image.new_from_array([[-1, -1, -1],
[-1, 16, -1],
[-1, -1, -1]
], scale=8)
image = image.conv(mask, precision='integer')
image.write_to_file('x.jpg')
Thanks,
Ed
vips-tile-height
is an important parameter for PDF conversion, without it, the performance of this library is very bad.
I have looked at base.py but still could not figure out how to do this in python.
DEBUG:pyvips.error:Error image: no property named `dzsave'
DEBUG:pyvips.error:Error no such operation dzsave VipsOperation: class "dzsave" not found
DEBUG:pyvips.voperation:VipsOperation.call: operation_name = dzsave
DEBUG:pyvips.voperation:VipsOperation.call: string_options =
DEBUG:pyvips.error:Error no such operation dzsave VipsOperation: class "dzsave" not found
Traceback (most recent call last):
File "", line 1, in
File "/root/.local/lib/python3.5/site-packages/pyvips/vimage.py", line 799, in call_function
return pyvips.Operation.call(name, self, *args, **kwargs)
File "/root/.local/lib/python3.5/site-packages/pyvips/voperation.py", line 132, in call
op = Operation.new_from_name(operation_name)
File "/root/.local/lib/python3.5/site-packages/pyvips/voperation.py", line 60, in new_from_name
raise Error('no such operation {0}'.format(operation_name))
pyvips.error.Error: no such operation dzsave
VipsOperation: class "dzsave" not found
When using smart-crop, I did not get results as expected. My assumption was that smartcrop works like a typical crop would - upon specifying the width and height, it uses those dimensions starting from the upper left (0,0) and crops down and right. Here is the code I was using:
import pyvips
image_vips = pyvips.Image.new_from_file("IMG_0015_guides.jpg")
cropped = image_vips.smartcrop(1920, 1080)
cropped.jpegsave('output_image.jpeg')
Here is the image:
Here is the output image
Am I misunderstanding how the method works? The resulting image is the correct dimensions, just the wrong placement.
See for example:
https://jcupitt.github.io/pyvips/vimage.html#pyvips.Image.labelregions
versus:
http://jcupitt.github.io/libvips/API/current/libvips-morphology.html#vips-labelregions
If a user wants to get the number of regions then they have to call labelregions
in the following way:
https://github.com/jcupitt/pyvips/blob/d1e690de8ecb947b116a9db606d121bef0a86f90/tests/test_morphology.py#L18
The auto-generated docs haven't described this parameter. To fix this, an libvips argument that has been tagged as VIPS_ARGUMENT_OPTIONAL_OUTPUT
should also be included in the optional parameters (as boolean type).
I'm running into the following error when trying to load libvips from python 2.7 on macOS:
import logging
logging.basicConfig(level = logging.DEBUG)
import pyvips
DEBUG:pyvips:Binary module load failed: No module named _libvips
DEBUG:pyvips:Falling back to ABI mode
DEBUG:pyvips:Loaded lib <cffi.api.FFILibrary_libvips.42.dylib object at 0x109023e10>
DEBUG:pyvips:Loaded lib <cffi.api.FFILibrary_libgobject-2.0.dylib object at 0x109023d90>
DEBUG:pyvips:Inited libvips
DEBUG:pyvips:
Traceback (most recent call last):
File "vips-pngquant.py", line 4, in <module>
import pyvips
File "/usr/local/lib/python2.7/site-packages/pyvips/__init__.py", line 157, in <module>
from .vimage import *
File "/usr/local/lib/python2.7/site-packages/pyvips/vimage.py", line 134, in <module>
class Image(pyvips.VipsObject):
File "/usr/local/lib/python2.7/site-packages/pyvips/vimage.py", line 1174, in Image
@_add_doc('ifthenelse')
File "/usr/local/lib/python2.7/site-packages/pyvips/vimage.py", line 101, in _add_doc
docstring = pyvips.Operation.generate_docstring(name)
File "/usr/local/lib/python2.7/site-packages/pyvips/voperation.py", line 310, in generate_docstring
result += argstr(name)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 25: ordinal not in range(128)
Also it's not using the binary module, even though pyvips was freshly installed with --no-cache-dir
.
Using python 3 this does not occur and it's using the binary module.
Environment:
Installing on ubnutu 16
sudo apt install libvips-tools
sudo apt install libvips
pip install pyvips
python
import pyvips
raise OSError(msg)
OSError: cannot load library libgobject-2.0.so: libgobject-2.0.so: cannot open shared object file: No such file or directory. Additionally, ctypes.util.find_library() did not manage to locate a library called 'libgobject-2.0.so'
any ideas?
related
stechstudio/libvips-lambda#1
I am trying to install the the pyvips bindings but am having trouble running the simple import test described in the readme. My system is a MacBook Pro running Windows 10 Pro 10.0.17134 in Parallels.
I did not have the latest vips, so I downloaded 8.6.5 and edited the system path to point to this release. I am using Anaconda to manage my python environment so I opened the Anaconda prompt window and tried the following:
(base) C:\Users\dougwood>vips --version
vips-8.6.5-Wed Jul 25 09:46:22 UTC 2018
(base) C:\Users\dougwood>echo %PATH%
C:\Users\dougwood\Anaconda3;C:\Users\dougwood\Anaconda3\Library\mingw-w64\bin;C:\Users\dougwood\Anaconda3\Library\usr\bin;C:\Users\dougwood\Anaconda3\Library\bin;C:\Users\dougwood\Anaconda3\Scripts;C:\Users\dougwood\Anaconda3\bin;C:\Program Files (x86)\Parallels\Parallels Tools\Applications;C:\Program Files\ImageMagick-7.0.6-Q16;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Users\dougwood.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm;C:\Program Files (x86)\CMake\bin;C:\dev\qt\Tools\mingw492_32\bin;C:\dev\qt\5.5\mingw492_32\bin;C:\dev\OpenCV-3.1.0\opencv\build\x64\vc14\bin;C:\Program Files\MATLAB\MATLAB Compiler Runtime\v81\runtime\win64;C:\Program Files\MATLAB\MATLAB Runtime\v85\runtime\win64;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\dev\Matlab;C:\dev\bftools;C:\dev\ultivue\UltivueTools\x64\Release;C:\Program Files\BackupClient\CommandLineTool;C:\Program Files\BackupClient\PyShell\bin;C:\Program Files (x86)\Common Files\Acronis\SnapAPI;C:\dev\vips\vips-dev-8.6\bin;C:\dev\vips\vips-dev-8.6\lib;C:\dev\ultivue\MPCoreFinder\x64\Release;C:\dev\OpenCV-3.3.0\opencv\build\x64\vc14\bin;C:\Program Files (x86)\Common Files\Acronis\FileProtector;C:\Program Files (x86)\Common Files\Acronis\FileProtector64;C:\dev\ultivue\IFImageSynth\x64\Release;C:\dev\ultivue\DCEImageSynth\x64\Release;C:\dev\ultivue\DCDecoder\x64\Release;C:\Program Files\TortoiseGit\bin;C:\WINDOWS\System32\OpenSSH;C:\Users\dougwood\AppData\Local\Programs\Python\Python35-32\Scripts;C:\dev\Qt\5.6\msvc2015_64\bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC;C:\dev\bftools;C:\Users\dougwood\AppData\Local\Microsoft\WindowsApps;
(base) C:\Users\dougwood>python
Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 15 2017, 03:27:45) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
import logging
logging.basicConfig(level=logging.DEBUG)
import pyvips
DEBUG:pyvips:Binary module load failed: No module named 'libvips'
DEBUG:pyvips:Falling back to ABI mode
Traceback (most recent call last):
File "C:\Users\dougwood\AppData\Roaming\Python\Python36\site-packages\pyvips_init.py", line 19, in
import _libvips
ModuleNotFoundError: No module named '_libvips'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\dougwood\AppData\Roaming\Python\Python36\site-packages\pyvips_init_.py", line 54, in
vips_lib = ffi.dlopen(_vips_libname)
File "C:\Users\dougwood\Anaconda3\lib\site-packages\cffi\api.py", line 140, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "C:\Users\dougwood\Anaconda3\lib\site-packages\cffi\api.py", line 786, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "C:\Users\dougwood\Anaconda3\lib\site-packages\cffi\api.py", line 782, in _load_backend_lib
return backend.load_library(path, flags)
OSError: cannot load library C:\dev\vips\vips-dev-8.6\bin\libvips-42.dll: error 0x7f
As soon as I type 'import pyvips' I see a series of error alerts appear. A screen shot of the first alert is attached. They all come from python.exe and say they are unable to find an entry point in various dlls.
Am I doing something wrong with the installation? Is this an issue with using Anaconda? I have also tried importing pyvips in code written in the python IDE Spyder and it has the same issue with loading the libs.
Thank you for your help with this! I look forward to using VIPS in python!
-Doug
Hello All,
I have written a program in python to stitch an 15 * 153 images using libvips on windows platfrom.
The program stiches till 13 * 42 images and after that i get the below mentioned error.
Traceback (most recent call last):
File "C:/Users/thermo/PycharmProjects/stiching/code/mosaicing/stitcher.py", line 232, in <module>
stitch(coor)
File "C:/Users/thermo/PycharmProjects/stiching/code/mosaicing/stitcher.py", line 202, in stitch
stitch_img.dzsave(output_path + '/' + output_path.split('/')[-1])
File "C:\Users\thermo\sticher\lib\site-packages\pyvips\vimage.py", line 799, in call_function
return pyvips.Operation.call(name, self, *args, **kwargs)
File "C:\Users\thermo\sticher\lib\site-packages\pyvips\voperation.py", line 189, in call
raise Error('unable to call {0}'.format(operation_name))
pyvips.error.Error: unable to call dzsave
vips__file_open_read: unable to open file "..\samples\Testing\13_43.jpg" for reading
windows error: The program issued a command but the command length is incorrect.
vips__file_open_read: unable to open file "..\samples\Testing\13_44.jpg" for reading
windows error: The program issued a command but the command length is incorrect.
stitcher.py ..\samples\Testing\13_42.jpg: done in 0.00695s
stitcher.py temp-18906: done in 149s
Process finished with exit code 1
I tried to search for the problem but could not find any relevant information.
Hello,
I have a question related to an issue I am having while using libvips, bear with me I find out about this library just yesterday so I am quite a beginner.
I am using libvips only for image resizing because is superfast.
in my test case I am loading an image from a filepath inside a loop, the image that point to that path can change so every loop I am expecting to load a different image evethough the filepath is the same. for instance
test.py
while True:
jobs = disque-client.get_job(['ses-faced.in'])
for queue_name, job_id, job in jobs:
img = pyvips.Image.new_from_file("/test/camera-capture.jpg", shrink=2)
..... do some image processing stuff with opencv....
cv2.write("output", img)
/test/camera-capture.jpg is updated with a new camera sample by another process which then create a job that triggers the code above.
The problem I am experiencing is that even though the /test/camera-capture.jpg file changes on the filesystem, the call to pyvips.Image.new_from_file("/test/camera-capture.jpg", shrink=2) always return the first image loaded at the first iteration of the loop, so basically at the first run.
so this is what happens:
start this program (test.py)
first job arrives
load image from "/test/camera-capture.jpg"
do stuff
wait for next job
next job arrives (the camera process has ovewritten the camera-capture.jpg with a new image)
load image from "/test/camera-capture.jpg" ---> but the image loaded is the same as the previous job as if a cache, that points to that filename loaded during the first job, is used instead.
Is this the case, are the images loaded with this method eventually cached?
Is there any way one can close the pyvips.Image and start fresh at each loop iteration?
Many thanks,
Massimo
Both the Travis CI tests for libvips and my local mac running macOS 10.13.5 are randomly crashing when running the tests/test_conversion.py::TestConversion::test_cache
under homebrew python@2 with libvips master.
Output from test run:
============================================================================================= test session starts ==============================================================================================
platform darwin -- Python 2.7.15, pytest-3.6.1, py-1.5.3, pluggy-0.6.0 -- /usr/local/opt/python@2/bin/python2.7
cachedir: pyvips-master/.pytest_cache
rootdir: /Users/felix/dev/misc/libvips/pyvips-master, inifile: tox.ini
plugins: flake8-1.0.1
collected 37 items
pyvips-master/tests/test_conversion.py::TestConversion::test_band_and PASSED [ 2%]
pyvips-master/tests/test_conversion.py::TestConversion::test_band_or PASSED [ 5%]
pyvips-master/tests/test_conversion.py::TestConversion::test_band_eor PASSED [ 8%]
pyvips-master/tests/test_conversion.py::TestConversion::test_bandjoin PASSED [ 10%]
pyvips-master/tests/test_conversion.py::TestConversion::test_bandjoin_const PASSED [ 13%]
pyvips-master/tests/test_conversion.py::TestConversion::test_bandmean PASSED [ 16%]
pyvips-master/tests/test_conversion.py::TestConversion::test_bandrank PASSED [ 18%]
pyvips-master/tests/test_conversion.py::TestConversion::test_cache [1] 18572 segmentation fault DYLD_LIBRARY_PATH=$PWD/libvips/.libs python2 -m pytest -v
It's not clear to me right now wether the crash is caused by the pyvips bindings or libvips, so I'm reporting it here.
Here's a link to a backtrace pulled from a core dump:
And a .crash file generated by macOS:
All the crashes are listing sink_screen
as the crashed thread during g_mutex_lock
.
It looks like this is inside a libvips processing thread, so it's likely a libvips or glib problem and not a pyvips bug.
For reproducing I used the following script:
for i in `seq 1 1000`; do
echo "Try $i ..."
DYLD_LIBRARY_PATH=$PWD/libvips/.libs python2 -m pytest -v pyvips-master/tests/test_conversion.py::TestConversion::test_cache
done
The crash usually happened multiple times within the first 50 invocations.
First I'm creating (canvasSize is 20000):
background = pyvips.Image.black(canvasSize, canvasSize, bands=4)
I'm iterating over about 180 PIL images (m), converting them, positioning them and then compositing:
memory_area = io.BytesIO()
m.im.save(memory_area,'PNG')
image_str = memory_area.getvalue()
background = pyvips.Image.new_from_buffer(image_str, "").embed(x, z, canvasSize, canvasSize, background=[0, 0, 0, 0]).composite(background, "over")
if I do:
background.write_to_file(outPngFile)
or
background.dzsave(os.path.join(mapOutputPath, "{}".format(dimDict[d])), suffix=".png")
I get
Bus error: 10
and a crash log. Any idea what's going on? If I iterate over slightly less (around 140) of these PIL images, everything is fine, all gets output, no errors.
Hello @jcupitt ,
I have written a code for mosaicing large number of images. I have used merge
function to join the images. I am facing tow issue while saving the result.
Traceback (most recent call last):
File "merge_2.py", line 337, in <module>
result.write_to_file('result.tif')
File "/home/lab/.virtualenvs/project/local/lib/python2.7/site-packages/pyvips/vimage.py", line 481, in write_to_file
), **kwargs)
File "/home/lab/.virtualenvs/project/local/lib/python2.7/site-packages/pyvips/voperation.py", line 188, in call
raise Error('unable to call {0}'.format(operation_name))
pyvips.error.Error: unable to call VipsForeignSaveTiffFile
TIFFSetField: result.tif: Unknown tag 317
VipsJpeg: out of order read at line 640
VipsJpeg: out of order read at line 640
VipsJpeg: out of order read at line 640
VipsJpeg: out of order read at line 640
VipsJpeg: out of order read at line 640
VipsJpeg: out of order read at line 640
VipsJpeg: out of order read at line 640
VipsJpeg: out of order read at line 640
VipsJpeg: out of order read at line 640
VipsJpeg: out of order read at line 640
VipsJpeg: out of order read at line 640
VipsJpeg: out of order read at line 640
VipsJpeg: out of order read at line 640
VipsJpeg: out of order read at line 640
VipsJpeg: out of order read at line 640
VipsJpeg: out of order read at line 640
Code:
from os import listdir,remove
from os.path import isfile, join
import re
import cv2
import numpy as np
import matplotlib.pyplot as plt
import pyvips
import time
def connect(img,r_overlap,c_overlap):
#########################################
# Used for finding information in image #
#########################################
print " connect function : finding regional information"
r=img.shape[0]
c=img.shape[1]
r_overlap,c_overlap=int(round(r_overlap)),int(round(c_overlap))
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
lower_red = np.array([20,20,20])
upper_red = np.array([200,200,200])
mask = cv2.inRange(hsv, lower_red, upper_red)
img=mask
white_space=np.sum(img)/(r*c)
right_connectivity=img[:,c-c_overlap:]
right_score=np.sum(right_connectivity)/(r*c_overlap)
left_connectivity=img[:,:c_overlap]
left_score=np.sum(left_connectivity)/(r*c_overlap)
bottom_connectivity=img[r-r_overlap:,:]
bottom_score=np.sum(bottom_connectivity)/(r_overlap*c)
up_connectivity=img[:r_overlap,:]
up_score=np.sum(up_connectivity)/(r_overlap*c)
right,left,up,bottom=0,0,0,0
white=1
if right_score>0.5:
right=1
if bottom_score>0.5:
bottom=1
if left_score>0.5:
left=1
if up_score>0.5:
up=1
if white_space<0.5:
white=0
score={'white_space':white,'right_score':right,'left_score':left,'bottom_score':bottom_score,'up_score':up}
return score
def vips_image(img):
###########################
# vips to numpy converter #
###########################
format_to_dtype = {
'uchar': np.uint8,
'char': np.int8,
'ushort': np.uint16,
'short': np.int16,
'uint': np.uint32,
'int': np.int32,
'float': np.float32,
'double': np.float64,
'complex': np.complex64,
'dpcomplex': np.complex128,
}
# img = pyvips.Image.new_from_file(sys.argv[1], access='sequential')
np_3d = np.ndarray(buffer=img.write_to_memory(),
dtype=format_to_dtype[img.format],
shape=[img.height, img.width, img.bands])
return np_3d
def warpImages(img1, img2, H):
###############################
# warp image using homography #
###############################
print "warpImages function : finding coordinates"
h1,w1 = img1.shape[:2]
h2,w2 = img2.shape[:2]
pts1 = np.float32([[0,0],[0,h1],[w1,h1],[w1,0]]).reshape(-1,1,2)
pts2 = np.float32([[0,0],[0,h2],[w2,h2],[w2,0]]).reshape(-1,1,2)
pts2_ = cv2.perspectiveTransform(pts2, H)
x_pts2_=pts2_[0][0]
y_pts2_=pts2_[2][0]
pts = np.concatenate((pts1, pts2_), axis=0)
[xmin, ymin] = np.int32(pts.min(axis=0).ravel() - 0.5)
[xmax, ymax] = np.int32(pts.max(axis=0).ravel() + 0.5)
t = [-xmin,-ymin]
Ht = np.array([[1,0,t[0]],[0,1,t[1]],[0,0,1]]) # translation matrixfor negative co-ordinates
H1=np.dot(Ht,H) #getting modified homography matrix
t_pts=np.dot(H1,[img2.shape[1],img2.shape[0],1])
axis=[int(t_pts[0]-img2.shape[1]),int(t_pts[1]-img2.shape[0])]
warped=np.zeros((ymax-ymin,xmax-xmin,3),img2.dtype)
warped[axis[1]:h2+axis[1],axis[0]:w2+axis[0]] = img2
warped[t[1]:h1+t[1],t[0]:w1+t[0]] = img1
return warped,[t[1],h1+t[1],t[0],w1+t[0]],[axis[1],h2+axis[1],axis[0],w2+axis[0]]
def Stitch(imageA,imageB,fx,switch):
#############################
# stitching images in a row #
#############################
print " rowStitch function : finding homography"
res_max=-1
xA1=-1
yA1=-1
intervalx=16
intervaly=16
print "grid size x:%i y:%i"%(intervalx,intervaly)
temp=imageB[:,:int(imageB.shape[1]*0.25)] #temp
if switch==1:
temp = cv2.Laplacian(temp,cv2.CV_32F)
print "laplacian filter in use"
if switch==0:
sobelx = cv2.Sobel(temp,cv2.CV_32F,1,0,ksize=11)
sobely = cv2.Sobel(temp,cv2.CV_32F,0,1,ksize=11)
temp=sobelx+sobely # to get gradient of image in both direction
print "sobel filter in use"
temp=cv2.subtract(temp,cv2.mean(temp))
score=[]
coor=[]
steps=16
print "steps size for scaning = %i"%steps
intervaly=imageA.shape[0]-20
for i in range(imageA.shape[1]-int(0.25*imageB.shape[1]),imageA.shape[1],steps):
for j in range(0,20,steps):
template=imageA[j:j+intervaly,i:i+intervalx] #template
if switch==1:
template = cv2.Laplacian(template,cv2.CV_32F)
if switch==0:
# print "using soble filter"
sobelx = cv2.Sobel(template,cv2.CV_32F,1,0,ksize=11)
sobely = cv2.Sobel(template,cv2.CV_32F,0,1,ksize=11)
template=sobelx+sobely#to get gradient of image
template=cv2.subtract(template,cv2.mean(template))
res=cv2.matchTemplate(temp,template,3)
_, val, _, loc = cv2.minMaxLoc(res)#val stores highest correlation from temp, loc stores coresponding starting location in temp
score.append(val)
coor.append(loc)
if(val > res_max):
res_max=val
xA1=i
yA1=j
xB1=loc[0]
yB1=loc[1]
print(val)
overlap=(1-float(xA1)/imageA.shape[1])
pointsA=[[xA1,yA1],[xA1+intervalx,yA1],[xA1,yA1+intervaly],[xA1+intervalx,yA1+intervaly]]
pointsB=[[xB1,yB1],[xB1+intervalx,yB1],[xB1,yB1+intervaly],[xB1+intervalx,yB1+intervaly]]
xB1=xB1*(1/fx)
yB1=yB1*(1/fx)
xA1=xA1*(1/fx)
yA1=yA1*(1/fx)
pointsA=[[xA1,yA1],[xA1+intervalx,yA1],[xA1,yA1+intervaly],[xA1+intervalx,yA1+intervaly]]
pointsB=[[xB1,yB1],[xB1+intervalx,yB1],[xB1,yB1+intervaly],[xB1+intervalx,yB1+intervaly]]
H,mask=cv2.findHomography(np.asarray(pointsB,float),np.asarray(pointsA,float),cv2.RANSAC,3)
return H,res_max
def rowStitch(imageA,imageB,fx,switch):
##################################################
# finding information between stiched row images #
##################################################
print " rowStitch function : finding homography"
res_max=-1
xA1=-1
yA1=-1
intervalx=16
intervaly=16
temp=imageB[:,:int(imageB.shape[1]*0.35)] #temp
if switch==1:
temp = cv2.Laplacian(temp,cv2.CV_32F)
if switch==0:
sobelx = cv2.Sobel(temp,cv2.CV_32F,1,0,ksize=11)
sobely = cv2.Sobel(temp,cv2.CV_32F,0,1,ksize=11)
temp=sobelx+sobely # to get gradient of image in both direction
temp=cv2.subtract(temp,cv2.mean(temp))
score=[]
coor=[]
steps=16
intervaly=imageA.shape[0]-100
for i in range(imageA.shape[1]-int(0.35*imageB.shape[1]),imageA.shape[1],steps):
for j in range(0,100,steps):
template=imageA[j:j+intervaly,i:i+intervalx] #template
if switch==1:
template = cv2.Laplacian(template,cv2.CV_32F)
if switch==0:
sobelx = cv2.Sobel(template,cv2.CV_32F,1,0,ksize=11)
sobely = cv2.Sobel(template,cv2.CV_32F,0,1,ksize=11)
template=sobelx+sobely#to get gradient of image
template=cv2.subtract(template,cv2.mean(template))
res=cv2.matchTemplate(temp,template,3)
_, val, _, loc = cv2.minMaxLoc(res)#val stores highest correlation from temp, loc stores coresponding starting location in temp
if(val > res_max):
res_max=val
xA1=i
yA1=j
xB1=loc[0]
yB1=loc[1]
print(val)
pointsA=[[xA1,yA1],[xA1+intervalx,yA1],[xA1,yA1+intervaly],[xA1+intervalx,yA1+intervaly]]
pointsB=[[xB1,yB1],[xB1+intervalx,yB1],[xB1,yB1+intervaly],[xB1+intervalx,yB1+intervaly]]
xB1=xB1*(1/fx)
yB1=yB1*(1/fx)
xA1=xA1*(1/fx)
yA1=yA1*(1/fx)
pointsA=[[xA1,yA1],[xA1+intervalx,yA1],[xA1,yA1+intervaly],[xA1+intervalx,yA1+intervaly]]
pointsB=[[xB1,yB1],[xB1+intervalx,yB1],[xB1,yB1+intervaly],[xB1+intervalx,yB1+intervaly]]
H,mask=cv2.findHomography(np.asarray(pointsB,float),np.asarray(pointsA,float),cv2.RANSAC,3)
return H,res_max
if __name__=="__main__":
########################################
# intializing parameters for stitching #
########################################
mypath='../CASE4A_1_focused'
# mypath='./images'
t1=time.time()
onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ]
images = np.empty(len(onlyfiles), dtype=object)
onlyfiles.sort(key=lambda var:[int(x) if x.isdigit() else x for x in re.findall(r'[^0-9]|[0-9]+', var)])
onlyfiles=onlyfiles[10*156:]
##############
# PARAMETERS #
##############
row=2 # set number of rows
column=156 # set number of columns
fx=0.5 # set resizing factor for finding pairwise coordinates
x00,y00=0,0
output_size_x=column*10
output_size_y=row*10
coor=[]
score=[]
info=[]
r_overlap=int(round(0.35*640)) # row overlap information
c_overlap=int(round(0.25*480)) # column overlap information
for i in range(row):
row_1=[]
score.append([])
coor.append([])
files=onlyfiles[i*column:(i+1)*column]
if i%2==0:
files.reverse()
x,y=column*10,row*10
for j in range(column-1):
im1=cv2.imread( join(mypath,files[j]))
im2=cv2.imread( join(mypath,files[j+1]))
if j==0:
tile1 = pyvips.Image.new_from_file(join(mypath,files[j]), access="sequential")
bg = pyvips.Image.black(output_size_x,output_size_y)
tile1 = bg.merge(tile1, 'horizontal', -x, -y, mblend =False) #merging first image of each row with black mask to make coordinate system easier
coor[i].append([x,y])
tile2 = pyvips.Image.new_from_file(join(mypath,files[j+1]), access="sequential")
im1_s=cv2.resize(im1,None,fx=fx, fy=fx, interpolation = cv2.INTER_AREA)
im2_s=cv2.resize(im2,None,fx=fx, fy=fx, interpolation = cv2.INTER_AREA)
score[i].append(connect(im1_s,fx*r_overlap,fx*c_overlap)['bottom_score'])
H,val=Stitch(im1_s,im2_s,fx,0)
warped,im1_coor,im2_coor=warpImages(im1, im2, H)
# plt.imshow(warped)
# plt.show()
print im1_coor,im2_coor, "im1 coor"
x1,y1=im1_coor[2],im1_coor[0]
x2,y2=im2_coor[2],im2_coor[0]
print x,"xxxxx",x2,"xxxxx22222"
x=x+x2-x1
y=y+y2-y1
if y<0:
y=y2-y1
tile1 = tile1.merge(tile2, 'horizontal', -x, -y, mblend =False) # merging rest of the images in a row
coor[i].append([x,y])
score[i].append(connect(im2_s,fx*r_overlap,fx*c_overlap)['bottom_score'])
# tile1.write_to_file('tiles/images/tile1_%i.tiff'%i) #to save rows, stitched images of a row
if i>0:
print score,"score"
if i%2==1:
#finding index of best image in a row to match with corresponding row
r_index_1=score[i-1].index(max(score[i-1]))
r_index=score[i].index(max(score[i]))
else:
r_index_1=r_index
row_tile2=tile1
im1=cv2.imread( join(mypath,prior_files[r_index_1]))
im2=cv2.imread( join(mypath,files[r_index_1]))
im1=np.rot90(im1)
im2=np.rot90(im2)
im1_s=cv2.resize(im1,None,fx=fx, fy=fx, interpolation = cv2.INTER_AREA)
im2_s=cv2.resize(im2,None,fx=fx, fy=fx, interpolation = cv2.INTER_AREA)
H,val=rowStitch(im1_s,im2_s,fx,0) #finding homography
warped,im1_coor,im2_coor=warpImages(im1, im2, H) #finding coordinates
#calcualting coordinates
y1,x1=im1_coor[2],im1_coor[0]
y2,x2=im2_coor[2],im2_coor[0]
x_a,y_a=coor[i-1][r_index_1][0],coor[i-1][r_index_1][1]
x_b,y_b=coor[i][r_index_1][0],coor[i][r_index_1][1]
y_r=y00+y2
x_r=x00-x2+x1
y_r=y_a-(y_b-y_r)
x_r=x_a-(x_b-x_r)
print x_r,y_r,"vertical coordinates"
# for nn in range(len(coor[i])):
# coor[i][nn][0]=coor[i][nn][0]-x_r
info.append([x_r,y_r])
np.save("tiles/coor",info)
if i==1:
result= row_tile1.merge(row_tile2, 'vertical', -x_r, -y_r, mblend = False) #merging first and second row
else:
result= result.merge(row_tile2, 'vertical', -x_r, -y_r, mblend = False) #merging rest of the rows
x00,y00=x_r,y_r
# y00=y_r
prior_files=files
# print coor,"coordinates"
if i==0:
row_tile1=tile1
print "saving result"
result.write_to_file('result.tif')
print time.time()-t1, "time taken for stitching %i images"%(row*column)
To test this code change following parameters:
mypath = 'path of images'
row = number of rows
column =number of columns
r_overlap=int(round(0.35*640)) # 0.35 is the overlap in between each rows, 640 is the height of image
c_overlap=int(round(0.25*480)) # 0.25 is the overlap between pairwise images, 480 is the width of images
Change mypath,rows,column, images size
Hello,
I read a.tiff file with pyvips as pyimage. pyimage.interpretation gives rgb as output but pyimage.bands gives 4 as output. I want to ignore alpha band and reshape the image into (height*width)X3 that to sequentially as numpy reshape is giving memory overflow.
After trying all the workarounds mentioned in your issues section, I still cannot get rid of this error.
Posting the traceback of the error
(base) C:\Users\IIIT\Downloads\vips-dev-w64-all-8.6.3-1\vips-dev-8.6\bin>python
Python 3.6.4 |Anaconda custom (64-bit)| (default, Mar 12 2018, 20:20:50) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.import pyvips
Traceback (most recent call last):
File "C:\Users\IIIT\AppData\Roaming\Python\Python36\site-packages\pyvips_init_.py", line 19, in
import _libvips
ModuleNotFoundError: No module named '_libvips'During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\IIIT\AppData\Roaming\Python\Python36\site-packages\pyvips_init_.py", line 54, in
vips_lib = ffi.dlopen(_vips_libname)
File "C:\Users\IIIT\Anaconda3\lib\site-packages\cffi\api.py", line 141, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "C:\Users\IIIT\Anaconda3\lib\site-packages\cffi\api.py", line 802, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "C:\Users\IIIT\Anaconda3\lib\site-packages\cffi\api.py", line 798, in _load_backend_lib
return backend.load_library(path, flags)
OSError: cannot load library 'libvips-42.dll': error 0x7f
Any other information if needed, please ask.
We should have a test for fail
handling, it seems to be rather fragile.
Hello,
I'm trying to find how I can load a Mirax file (ext .mrsx
) into vips.
So far I tried:
vip = pyvips.Image.openslideload(file, level=2)
and
vip = pyvips.Image.new_from_file(file, access='sequential')
The first call give me a VipsOperation: class "openslideload" not found
and the second one opens the file but it seems only to load a thumbnail of the WSI, not the actual WSI.
I have libvips v8.6.4 and pyvips installed from master
. Thanks.
pyvips is very dynamic, and as a result, not very quick.
We should experiment with cffi API mode, where a binary extension is built for the glue layer. It'd be much faster, but on the downside would need rebuilding occasionally.
This occurs if you use the same code to load PDFs and TIFFs. PDFs require a DPI while TIFFs don't, which is fine. The problem is that the error message is a bit vague.
There should either be a better error/warning message ("DPI is not supported for filetype of TIFF") or the dpi parameter should be ignored.
Minimal example:
>>> import pyvips
# loading with no kwargs works fine
>>> pyvips.Image.new_from_file("/tmp/test_document.tiff")
<pyvips.Image 2480x3507 uchar, 1 bands, b-w>
# specifying dpi fails with slightly obscure error:
>>> pyvips.Image.new_from_file("/tmp/test_document.tiff", dpi=100)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/app/venv/lib/python3.5/site-packages/pyvips/vimage.py", line 254, in new_from_file
), **kwargs)
File "/home/app/venv/lib/python3.5/site-packages/pyvips/voperation.py", line 208, in call
op.set(name, flags_from_name[name], match_image, value)
KeyError: 'dpi'
We could remove a bit of code:
https://docs.python.org/2/library/functools.html#functools.total_ordering
Should explain xres/yres/set plus copy somewhere.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.