Skip to content

Instantly share code, notes, and snippets.

@jcupitt
jcupitt / pil-vips.py
Created January 19, 2021 10:04
pil - pyvips image resize benchmark
#!/usr/bin/python3
import time
import sys
from io import BytesIO
import pyvips
from PIL import Image # Pillow-SIMD
@jcupitt
jcupitt / error.log
Created November 30, 2020 15:50
error log
+ mirtk convert-pointset surfaces/CC00058XX09-11300/vtk/CC00058XX09-11300.L.whit
e.native.surf.vtk surfaces/CC00058XX09-11300/workbench//temp-CC00058XX09-11300.L
.white.native.surf.gii
Warning: In /usr/src/structural-pipeline/build/VTK/IO/Legacy/vtkDataReader.cxx,
line 462
vtkGenericDataObjectReader (0xf0d9e0): Reading file version: 5.1 with older read
er version 4.0
Warning: In /usr/src/structural-pipeline/build/VTK/IO/Legacy/vtkDataReader.cxx,
line 462
@jcupitt
jcupitt / structure-data.sh
Created November 27, 2020 13:57
final stage of struct pipeline
#!/bin/bash
run() {
cmd="$*"
$cmd
if [ $? != 0 ]; then
echo =====================
echo $cmd
echo failed
exit 1
@jcupitt
jcupitt / bench-read.py
Created August 21, 2020 00:35
benchmark pyvips vs cv2 for image read
#!/usr/bin/python3
# setup with:
#
# mkdir sample
# cd sample
# for i in {1..300}; do cp ~/pics/k2.png $i.png; done
#
# on this modest 2015 laptop running Ubuntu 20.04, I see:
#
@jcupitt
jcupitt / litecor.py
Created August 4, 2020 14:33
light correction example with pyvips
#!/usr/bin/python3
import sys
import os
import pyvips
if len(sys.argv) < 3:
print(f"usage: {sys.argv[0]} grey-card-image image1 image2 ...")
print(f" light-correct a set of images with a grey card")
print(f" corrected images writtem to lc_image1, lc_image2, etc.")
@jcupitt
jcupitt / Vips-8.0.gir
Created July 7, 2020 09:44
sample libvips GIR
This file has been truncated, but you can view the full file.
<?xml version="1.0"?>
<!-- This file was automatically generated from C sources - DO NOT EDIT!
To affect the contents of this file, edit the original C definitions,
and/or use gtk-doc annotations. -->
<repository version="1.2"
xmlns="http://www.gtk.org/introspection/core/1.0"
xmlns:c="http://www.gtk.org/introspection/c/1.0"
xmlns:glib="http://www.gtk.org/introspection/glib/1.0">
<include name="GObject" version="2.0"/>
<c:include name="vips/vips.h"/>
@jcupitt
jcupitt / custom.c
Created March 22, 2020 17:12
custom libvips source and target in C
/* Compile with:
*
* gcc -g -Wall custom.c `pkg-config vips --cflags --libs`
*
* Run with:
*
* ./a.out ~/pics/k2.jpg x.jpg
*
*/
@jcupitt
jcupitt / watermark_fax2.c
Created March 3, 2020 09:52
render dithered text with libvips
/* watermark a fax image with vips8 C
*
* compile with
gcc -g -Wall watermark_fax.c `pkg-config vips --cflags --libs`
*/
#include <vips/vips.h>
@jcupitt
jcupitt / watermark_fax.c
Created March 2, 2020 11:40
watermark a fax image with libvips
/* watermark a fax image with vips8 C
*
* compile with
gcc -g -Wall watermark_fax.c `pkg-config vips --cflags --libs`
*/
#include <vips/vips.h>
@jcupitt
jcupitt / dominant.php
Last active November 5, 2019 20:49
make a solid image of the dominant colour
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
use Jcupitt\Vips;
$im = Vips\Image::newFromFile($argv[1], ['access' => 'sequential']);
# 3D histogram ... make 10 x 10 x 10 bins, so 1000 possible colours
$n_bins = 10;