From da8ff125c446bfa5e7b3d461b44be4189f58d396 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Tue, 3 Nov 2009 20:01:22 +0100 Subject: [PATCH 01/43] beginning of qt fancy imshow --- scikits/image/io/_plugins/qt_plugin.py | 67 +++++++++++++++++++++----- 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index 032d6409..504d7e8a 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -14,7 +14,7 @@ except GuiLockError, gle: else: try: from PyQt4.QtGui import (QApplication, QMainWindow, QImage, QPixmap, - QLabel) + QLabel, QWidget, QVBoxLayout) except ImportError: print 'PyQT4 libraries not installed. Plugin not loaded.' @@ -24,19 +24,20 @@ else: app = None + class LabelImage(QLabel): + def __init__(self, parent, arr): + QLabel.__init__(self) + self.img = QImage(arr.data, arr.shape[1], arr.shape[0], + arr.strides[0], QImage.Format_RGB888) + self.pm = QPixmap.fromImage(self.img) + self.setPixmap(self.pm) + + class ImageWindow(QMainWindow): def __init__(self, arr, mgr): QMainWindow.__init__(self) self.mgr = mgr - img = QImage(arr.data, arr.shape[1], arr.shape[0], - QImage.Format_RGB888) - pm = QPixmap.fromImage(img) - - label = QLabel() - label.setPixmap(pm) - label.show() - - self.label = label + self.label = LabelImage(self, arr) self.setCentralWidget(self.label) self.mgr.add_window(self) @@ -45,7 +46,45 @@ else: # references to it self.mgr.remove_window(self) - def imshow(arr): + + class FancyImageWindow(ImageWindow): + def __init__(self, arr, mgr): + ImageWindow.__init__(self, arr, mgr) + + # we need to hold a reference to arr, + # if we want to access the data later, + # because QImage does not copy the data. + self.arr = arr + + self.statusBar().showMessage('X: Y: ') + self.label.setScaledContents(True) + self.label.setMouseTracking(True) + self.label.mouseMoveEvent = self.label_mouseMoveEvent + + def scale_mouse_pos(self, x, y): + width = self.label.width() + height = self.label.height() + x_frac = 1. * x / width + y_frac = 1. * y / height + width = self.arr.shape[1] + height = self.arr.shape[0] + new_x = int(width * x_frac) + new_y = int(height * y_frac) + return(new_x, new_y) + + def label_mouseMoveEvent(self, evt): + x = evt.x() + y = evt.y() + x, y = self.scale_mouse_pos(x, y) + msg = 'X: %d, Y: %d ' % (x, y) + R = self.arr[y,x,0] + G = self.arr[y,x,1] + B = self.arr[y,x,2] + msg += 'R: %s, G:, %s, B: %s' % (R, G, B) + self.statusBar().showMessage(msg) + + + def imshow(arr, fancy=False): global app if not app: @@ -53,7 +92,11 @@ else: arr = prepare_for_display(arr) - iw = ImageWindow(arr, window_manager) + if not fancy: + iw = ImageWindow(arr, window_manager) + else: + iw = FancyImageWindow(arr, window_manager) + iw.show() def _app_show(): From b00566a52cd6b86f259b722e924e28817befe992 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Tue, 3 Nov 2009 21:53:30 +0100 Subject: [PATCH 02/43] fixed event flow order for fancy imshow --- scikits/image/analysis/spath.c | 3289 ++++++++++-------------- scikits/image/io/_plugins/qt_plugin.py | 38 +- 2 files changed, 1437 insertions(+), 1890 deletions(-) diff --git a/scikits/image/analysis/spath.c b/scikits/image/analysis/spath.c index 48ac8a0e..c18145f5 100644 --- a/scikits/image/analysis/spath.c +++ b/scikits/image/analysis/spath.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.11.3 on Tue Nov 3 08:57:50 2009 */ +/* Generated by Cython 0.11.3 on Tue Nov 3 12:29:34 2009 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -15,7 +15,6 @@ #if PY_VERSION_HEX < 0x02040000 #define METH_COEXIST 0 #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) - #define PyDict_Contains(d,o) PySequence_Contains(d,o) #endif #if PY_VERSION_HEX < 0x02050000 typedef int Py_ssize_t; @@ -34,7 +33,6 @@ #define PyVarObject_HEAD_INIT(type, size) \ PyObject_HEAD_INIT(type) size, #define PyType_Modified(t) - #define PyBytes_CheckExact PyString_CheckExact typedef struct { void *buf; @@ -75,8 +73,8 @@ #endif #if PY_MAJOR_VERSION >= 3 #define PyBaseString_Type PyUnicode_Type - #define PyString_Type PyUnicode_Type - #define PyString_CheckExact PyUnicode_CheckExact + #define PyString_Type PyBytes_Type + #define PyString_CheckExact PyBytes_CheckExact #define PyInt_Type PyLong_Type #define PyInt_Check(op) PyLong_Check(op) #define PyInt_CheckExact(op) PyLong_CheckExact(op) @@ -137,8 +135,9 @@ #include "stdlib.h" #include "stdio.h" #include "numpy/arrayobject.h" -#include "numpy/ufuncobject.h" #include "math.h" +#define __PYX_USE_C99_COMPLEX defined(_Complex_I) + #ifdef __GNUC__ #define INLINE __inline__ @@ -148,7 +147,11 @@ #define INLINE #endif -typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ +typedef struct {PyObject **p; char *s; long n; char is_unicode; char intern; char is_identifier;} __Pyx_StringTabEntry; /*proto*/ + + + +static int __pyx_skip_dispatch = 0; /* Type Conversion Predeclarations */ @@ -264,83 +267,366 @@ static const char *__pyx_filename; static const char **__pyx_f; -#if !defined(CYTHON_CCOMPLEX) - #if defined(__cplusplus) - #define CYTHON_CCOMPLEX 1 - #elif defined(_Complex_I) - #define CYTHON_CCOMPLEX 1 - #else - #define CYTHON_CCOMPLEX 0 - #endif +#ifdef CYTHON_REFNANNY +typedef struct { + void (*INCREF)(void*, PyObject*, int); + void (*DECREF)(void*, PyObject*, int); + void (*GOTREF)(void*, PyObject*, int); + void (*GIVEREF)(void*, PyObject*, int); + void* (*NewContext)(const char*, int, const char*); + void (*FinishContext)(void**); +} __Pyx_RefnannyAPIStruct; +static __Pyx_RefnannyAPIStruct *__Pyx_Refnanny = NULL; +#define __Pyx_ImportRefcountAPI(name) (__Pyx_RefnannyAPIStruct *) PyCObject_Import((char *)name, (char *)"RefnannyAPI") +#define __Pyx_INCREF(r) __Pyx_Refnanny->INCREF(__pyx_refchk, (PyObject *)(r), __LINE__) +#define __Pyx_DECREF(r) __Pyx_Refnanny->DECREF(__pyx_refchk, (PyObject *)(r), __LINE__) +#define __Pyx_GOTREF(r) __Pyx_Refnanny->GOTREF(__pyx_refchk, (PyObject *)(r), __LINE__) +#define __Pyx_GIVEREF(r) __Pyx_Refnanny->GIVEREF(__pyx_refchk, (PyObject *)(r), __LINE__) +#define __Pyx_XDECREF(r) if((r) == NULL) ; else __Pyx_DECREF(r) +#define __Pyx_SetupRefcountContext(name) void* __pyx_refchk = __Pyx_Refnanny->NewContext((name), __LINE__, __FILE__) +#define __Pyx_FinishRefcountContext() __Pyx_Refnanny->FinishContext(&__pyx_refchk) +#else +#define __Pyx_INCREF(r) Py_INCREF(r) +#define __Pyx_DECREF(r) Py_DECREF(r) +#define __Pyx_GOTREF(r) +#define __Pyx_GIVEREF(r) +#define __Pyx_XDECREF(r) Py_XDECREF(r) +#define __Pyx_SetupRefcountContext(name) +#define __Pyx_FinishRefcountContext() +#endif /* CYTHON_REFNANNY */ +#define __Pyx_XGIVEREF(r) if((r) == NULL) ; else __Pyx_GIVEREF(r) +#define __Pyx_XGOTREF(r) if((r) == NULL) ; else __Pyx_GOTREF(r) + +static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ + +/* Run-time type information about structs used with buffers */ +struct __Pyx_StructField_; + +typedef struct { + const char* name; /* for error messages only */ + struct __Pyx_StructField_* fields; + size_t size; /* sizeof(type) */ + char typegroup; /* _R_eal, _C_omplex, Signed _I_nt, _U_nsigned int, _S_truct, _P_ointer, _O_bject */ +} __Pyx_TypeInfo; + +typedef struct __Pyx_StructField_ { + __Pyx_TypeInfo* type; + const char* name; + size_t offset; +} __Pyx_StructField; + +typedef struct { + __Pyx_StructField* field; + size_t parent_offset; +} __Pyx_BufFmt_StackElem; + + +static INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info); +static int __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack); +static void __Pyx_RaiseBufferIndexError(int axis); /*proto*/ +#define __Pyx_BufPtrStrided2d(type, buf, i0, s0, i1, s1) (type)((char*)buf + i0 * s0 + i1 * s1) +#define __Pyx_BufPtrStrided1d(type, buf, i0, s0) (type)((char*)buf + i0 * s0) + +static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ +static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ + +static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, PyObject* kw_name); /*proto*/ + +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ + +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/ + +static INLINE void __Pyx_RaiseNoneNotIterableError(void); + +static INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); + +static INLINE void __Pyx_RaiseTooManyValuesError(void); + +static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); /*proto*/ + +static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, + const char *name, int exact); /*proto*/ +#if PY_MAJOR_VERSION < 3 +static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags); +static void __Pyx_ReleaseBuffer(Py_buffer *view); +#else +#define __Pyx_GetBuffer PyObject_GetBuffer +#define __Pyx_ReleaseBuffer PyBuffer_Release #endif -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - #include - #else - #include - #endif +Py_ssize_t __Pyx_zeros[] = {0, 0}; +Py_ssize_t __Pyx_minusones[] = {-1, -1}; + +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/ + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ + +static int __Pyx_Print(PyObject *, int); /*proto*/ +#if PY_MAJOR_VERSION >= 3 +static PyObject* __pyx_print = 0; +static PyObject* __pyx_print_kwargs = 0; #endif -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - typedef ::std::complex< float > __pyx_t_float_complex; - #else +static int __Pyx_PrintOne(PyObject *o); /*proto*/ + +#if __PYX_USE_C99_COMPLEX + #define __Pyx_REAL_PART(z) __real__(z) + #define __Pyx_IMAG_PART(z) __imag__(z) +#else + #define __Pyx_REAL_PART(z) ((z).real) + #define __Pyx_IMAG_PART(z) ((z).imag) +#endif + +#define __pyx_PyObject_from_complex(z) PyComplex_FromDoubles((double)__Pyx_REAL_PART(z), (double)__Pyx_IMAG_PART(z)) + +#if __PYX_USE_C99_COMPLEX + typedef float _Complex __pyx_t_float_complex; - #endif + static INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { + return x + y*(__pyx_t_float_complex)_Complex_I; + } + + #define __pyx_t_float_complex_is_zero(a) ((a) == 0) + #define __pyx_t_float_complex_eq(a, b) ((a) == (b)) + #define __pyx_t_float_complex_add(a, b) ((a)+(b)) + #define __pyx_t_float_complex_sub(a, b) ((a)-(b)) + #define __pyx_t_float_complex_mul(a, b) ((a)*(b)) + #define __pyx_t_float_complex_div(a, b) ((a)/(b)) + #define __pyx_t_float_complex_neg(a) (-(a)) + #else + typedef struct { float real, imag; } __pyx_t_float_complex; + static INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { + __pyx_t_float_complex c; c.real = x; c.imag = y; return c; + } + + static INLINE int __pyx_t_float_complex_is_zero(__pyx_t_float_complex a) { + return (a.real == 0) & (a.imag == 0); + } + + static INLINE int __pyx_t_float_complex_eq(__pyx_t_float_complex a, __pyx_t_float_complex b) { + return (a.real == b.real) & (a.imag == b.imag); + } + + static INLINE __pyx_t_float_complex __pyx_t_float_complex_add(__pyx_t_float_complex a, __pyx_t_float_complex b) { + __pyx_t_float_complex z; + z.real = a.real + b.real; + z.imag = a.imag + b.imag; + return z; + } + + static INLINE __pyx_t_float_complex __pyx_t_float_complex_sub(__pyx_t_float_complex a, __pyx_t_float_complex b) { + __pyx_t_float_complex z; + z.real = a.real - b.real; + z.imag = a.imag - b.imag; + return z; + } + + static INLINE __pyx_t_float_complex __pyx_t_float_complex_mul(__pyx_t_float_complex a, __pyx_t_float_complex b) { + __pyx_t_float_complex z; + z.real = a.real * b.real - a.imag * b.imag; + z.imag = a.real * b.imag + a.imag * b.real; + return z; + } + + static INLINE __pyx_t_float_complex __pyx_t_float_complex_div(__pyx_t_float_complex a, __pyx_t_float_complex b) { + __pyx_t_float_complex z; + float denom = b.real*b.real + b.imag*b.imag; + z.real = (a.real * b.real + a.imag * b.imag) / denom; + z.imag = (a.imag * b.real - a.real * b.imag) / denom; + return z; + } + + static INLINE __pyx_t_float_complex __pyx_t_float_complex_neg(__pyx_t_float_complex a) { + __pyx_t_float_complex z; + z.real = -a.real; + z.imag = -a.imag; + return z; + } + #endif -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - static INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float); - #else - static INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float); - #endif -#else - static INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float); -#endif +#if __PYX_USE_C99_COMPLEX -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - typedef ::std::complex< double > __pyx_t_double_complex; - #else typedef double _Complex __pyx_t_double_complex; - #endif + static INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) { + return x + y*(__pyx_t_double_complex)_Complex_I; + } + + #define __pyx_t_double_complex_is_zero(a) ((a) == 0) + #define __pyx_t_double_complex_eq(a, b) ((a) == (b)) + #define __pyx_t_double_complex_add(a, b) ((a)+(b)) + #define __pyx_t_double_complex_sub(a, b) ((a)-(b)) + #define __pyx_t_double_complex_mul(a, b) ((a)*(b)) + #define __pyx_t_double_complex_div(a, b) ((a)/(b)) + #define __pyx_t_double_complex_neg(a) (-(a)) + #else + typedef struct { double real, imag; } __pyx_t_double_complex; + static INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) { + __pyx_t_double_complex c; c.real = x; c.imag = y; return c; + } + + static INLINE int __pyx_t_double_complex_is_zero(__pyx_t_double_complex a) { + return (a.real == 0) & (a.imag == 0); + } + + static INLINE int __pyx_t_double_complex_eq(__pyx_t_double_complex a, __pyx_t_double_complex b) { + return (a.real == b.real) & (a.imag == b.imag); + } + + static INLINE __pyx_t_double_complex __pyx_t_double_complex_add(__pyx_t_double_complex a, __pyx_t_double_complex b) { + __pyx_t_double_complex z; + z.real = a.real + b.real; + z.imag = a.imag + b.imag; + return z; + } + + static INLINE __pyx_t_double_complex __pyx_t_double_complex_sub(__pyx_t_double_complex a, __pyx_t_double_complex b) { + __pyx_t_double_complex z; + z.real = a.real - b.real; + z.imag = a.imag - b.imag; + return z; + } + + static INLINE __pyx_t_double_complex __pyx_t_double_complex_mul(__pyx_t_double_complex a, __pyx_t_double_complex b) { + __pyx_t_double_complex z; + z.real = a.real * b.real - a.imag * b.imag; + z.imag = a.real * b.imag + a.imag * b.real; + return z; + } + + static INLINE __pyx_t_double_complex __pyx_t_double_complex_div(__pyx_t_double_complex a, __pyx_t_double_complex b) { + __pyx_t_double_complex z; + double denom = b.real*b.real + b.imag*b.imag; + z.real = (a.real * b.real + a.imag * b.imag) / denom; + z.imag = (a.imag * b.real - a.real * b.imag) / denom; + return z; + } + + static INLINE __pyx_t_double_complex __pyx_t_double_complex_neg(__pyx_t_double_complex a) { + __pyx_t_double_complex z; + z.real = -a.real; + z.imag = -a.imag; + return z; + } + #endif -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - static INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double); - #else - static INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double); - #endif +#if __PYX_USE_C99_COMPLEX + + typedef long double _Complex __pyx_t_long__double_complex; + static INLINE __pyx_t_long__double_complex __pyx_t_long__double_complex_from_parts(long double x, long double y) { + return x + y*(__pyx_t_long__double_complex)_Complex_I; + } + + #define __pyx_t_long__double_complex_is_zero(a) ((a) == 0) + #define __pyx_t_long__double_complex_eq(a, b) ((a) == (b)) + #define __pyx_t_long__double_complex_add(a, b) ((a)+(b)) + #define __pyx_t_long__double_complex_sub(a, b) ((a)-(b)) + #define __pyx_t_long__double_complex_mul(a, b) ((a)*(b)) + #define __pyx_t_long__double_complex_div(a, b) ((a)/(b)) + #define __pyx_t_long__double_complex_neg(a) (-(a)) + #else - static INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double); + + typedef struct { long double real, imag; } __pyx_t_long__double_complex; + static INLINE __pyx_t_long__double_complex __pyx_t_long__double_complex_from_parts(long double x, long double y) { + __pyx_t_long__double_complex c; c.real = x; c.imag = y; return c; + } + + static INLINE int __pyx_t_long__double_complex_is_zero(__pyx_t_long__double_complex a) { + return (a.real == 0) & (a.imag == 0); + } + + static INLINE int __pyx_t_long__double_complex_eq(__pyx_t_long__double_complex a, __pyx_t_long__double_complex b) { + return (a.real == b.real) & (a.imag == b.imag); + } + + static INLINE __pyx_t_long__double_complex __pyx_t_long__double_complex_add(__pyx_t_long__double_complex a, __pyx_t_long__double_complex b) { + __pyx_t_long__double_complex z; + z.real = a.real + b.real; + z.imag = a.imag + b.imag; + return z; + } + + static INLINE __pyx_t_long__double_complex __pyx_t_long__double_complex_sub(__pyx_t_long__double_complex a, __pyx_t_long__double_complex b) { + __pyx_t_long__double_complex z; + z.real = a.real - b.real; + z.imag = a.imag - b.imag; + return z; + } + + static INLINE __pyx_t_long__double_complex __pyx_t_long__double_complex_mul(__pyx_t_long__double_complex a, __pyx_t_long__double_complex b) { + __pyx_t_long__double_complex z; + z.real = a.real * b.real - a.imag * b.imag; + z.imag = a.real * b.imag + a.imag * b.real; + return z; + } + + static INLINE __pyx_t_long__double_complex __pyx_t_long__double_complex_div(__pyx_t_long__double_complex a, __pyx_t_long__double_complex b) { + __pyx_t_long__double_complex z; + long double denom = b.real*b.real + b.imag*b.imag; + z.real = (a.real * b.real + a.imag * b.imag) / denom; + z.imag = (a.imag * b.real - a.real * b.imag) / denom; + return z; + } + + static INLINE __pyx_t_long__double_complex __pyx_t_long__double_complex_neg(__pyx_t_long__double_complex a) { + __pyx_t_long__double_complex z; + z.real = -a.real; + z.imag = -a.imag; + return z; + } + #endif -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - typedef ::std::complex< long double > __pyx_t_long_double_complex; - #else - typedef long double _Complex __pyx_t_long_double_complex; - #endif -#else - typedef struct { long double real, imag; } __pyx_t_long_double_complex; -#endif +static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/ +static int __Pyx_EndUnpack(PyObject *); /*proto*/ -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - static INLINE __pyx_t_long_double_complex __pyx_t_long_double_complex_from_parts(long double, long double); - #else - static INLINE __pyx_t_long_double_complex __pyx_t_long_double_complex_from_parts(long double, long double); - #endif -#else - static INLINE __pyx_t_long_double_complex __pyx_t_long_double_complex_from_parts(long double, long double); -#endif +static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); + +static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); + +static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); + +static INLINE char __Pyx_PyInt_AsChar(PyObject *); + +static INLINE short __Pyx_PyInt_AsShort(PyObject *); + +static INLINE int __Pyx_PyInt_AsInt(PyObject *); + +static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); + +static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); + +static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); + +static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); + +static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); + +static INLINE long __Pyx_PyInt_AsLong(PyObject *); + +static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); + +static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); + +static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); + +static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, long size); /*proto*/ + +static PyObject *__Pyx_ImportModule(const char *name); /*proto*/ + +static void __Pyx_AddTraceback(const char *funcname); /*proto*/ + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Type declarations */ @@ -390,7 +676,7 @@ typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t; typedef npy_cdouble __pyx_t_5numpy_complex_t; -/* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":9 +/* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":9 * double fabs(double f) * * cpdef shortest_path(np.ndarray arr, int reach=1): # <<<<<<<<<<<<<< @@ -402,254 +688,8 @@ struct __pyx_opt_args_7scikits_5image_8analysis_5spath_shortest_path { int __pyx_n; int reach; }; - -#ifdef CYTHON_REFNANNY -typedef struct { - void (*INCREF)(void*, PyObject*, int); - void (*DECREF)(void*, PyObject*, int); - void (*GOTREF)(void*, PyObject*, int); - void (*GIVEREF)(void*, PyObject*, int); - void* (*NewContext)(const char*, int, const char*); - void (*FinishContext)(void**); -} __Pyx_RefnannyAPIStruct; -static __Pyx_RefnannyAPIStruct *__Pyx_Refnanny = NULL; -#define __Pyx_ImportRefcountAPI(name) (__Pyx_RefnannyAPIStruct *) PyCObject_Import((char *)name, (char *)"RefnannyAPI") -#define __Pyx_INCREF(r) __Pyx_Refnanny->INCREF(__pyx_refchk, (PyObject *)(r), __LINE__) -#define __Pyx_DECREF(r) __Pyx_Refnanny->DECREF(__pyx_refchk, (PyObject *)(r), __LINE__) -#define __Pyx_GOTREF(r) __Pyx_Refnanny->GOTREF(__pyx_refchk, (PyObject *)(r), __LINE__) -#define __Pyx_GIVEREF(r) __Pyx_Refnanny->GIVEREF(__pyx_refchk, (PyObject *)(r), __LINE__) -#define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0) -#define __Pyx_SetupRefcountContext(name) void* __pyx_refchk = __Pyx_Refnanny->NewContext((name), __LINE__, __FILE__) -#define __Pyx_FinishRefcountContext() __Pyx_Refnanny->FinishContext(&__pyx_refchk) -#else -#define __Pyx_INCREF(r) Py_INCREF(r) -#define __Pyx_DECREF(r) Py_DECREF(r) -#define __Pyx_GOTREF(r) -#define __Pyx_GIVEREF(r) -#define __Pyx_XDECREF(r) Py_XDECREF(r) -#define __Pyx_SetupRefcountContext(name) -#define __Pyx_FinishRefcountContext() -#endif /* CYTHON_REFNANNY */ -#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0) -#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0) - -static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ - -/* Run-time type information about structs used with buffers */ -struct __Pyx_StructField_; - -typedef struct { - const char* name; /* for error messages only */ - struct __Pyx_StructField_* fields; - size_t size; /* sizeof(type) */ - char typegroup; /* _R_eal, _C_omplex, Signed _I_nt, _U_nsigned int, _S_truct, _P_ointer, _O_bject */ -} __Pyx_TypeInfo; - -typedef struct __Pyx_StructField_ { - __Pyx_TypeInfo* type; - const char* name; - size_t offset; -} __Pyx_StructField; - -typedef struct { - __Pyx_StructField* field; - size_t parent_offset; -} __Pyx_BufFmt_StackElem; - - -static INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info); -static int __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack); -static void __Pyx_RaiseBufferIndexError(int axis); /*proto*/ -#define __Pyx_BufPtrStrided2d(type, buf, i0, s0, i1, s1) (type)((char*)buf + i0 * s0 + i1 * s1) -#define __Pyx_BufPtrStrided1d(type, buf, i0, s0) (type)((char*)buf + i0 * s0) - -static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ -static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ - -static void __Pyx_RaiseDoubleKeywordsError( - const char* func_name, PyObject* kw_name); /*proto*/ - -static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, - Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ - -static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/ - -static INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); - -static INLINE void __Pyx_RaiseTooManyValuesError(void); - -static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/ -static int __Pyx_EndUnpack(PyObject *); /*proto*/ - -static INLINE void __Pyx_RaiseNoneNotIterableError(void); - -static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); /*proto*/ - -static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, - const char *name, int exact); /*proto*/ -#if PY_MAJOR_VERSION < 3 -static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags); -static void __Pyx_ReleaseBuffer(Py_buffer *view); -#else -#define __Pyx_GetBuffer PyObject_GetBuffer -#define __Pyx_ReleaseBuffer PyBuffer_Release -#endif - -Py_ssize_t __Pyx_zeros[] = {0, 0}; -Py_ssize_t __Pyx_minusones[] = {-1, -1}; - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/ - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ - -static int __Pyx_Print(PyObject *, int); /*proto*/ -#if PY_MAJOR_VERSION >= 3 -static PyObject* __pyx_print = 0; -static PyObject* __pyx_print_kwargs = 0; -#endif - -static int __Pyx_PrintOne(PyObject *o); /*proto*/ - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - #define __Pyx_CREAL(z) ((z).real()) - #define __Pyx_CIMAG(z) ((z).imag()) - #else - #define __Pyx_CREAL(z) (__real__(z)) - #define __Pyx_CIMAG(z) (__imag__(z)) - #endif -#else - #define __Pyx_CREAL(z) ((z).real) - #define __Pyx_CIMAG(z) ((z).imag) -#endif - -#if CYTHON_CCOMPLEX - #define __Pyx_c_eqf(a, b) ((a)==(b)) - #define __Pyx_c_sumf(a, b) ((a)+(b)) - #define __Pyx_c_difff(a, b) ((a)-(b)) - #define __Pyx_c_prodf(a, b) ((a)*(b)) - #define __Pyx_c_quotf(a, b) ((a)/(b)) - #define __Pyx_c_negf(a) (-(a)) - #ifdef __cplusplus - #define __Pyx_c_is_zerof(z) ((z)==0.0) - #define __Pyx_c_conjf(z) (::std::conj(z)) - /*#define __Pyx_c_absf(z) (::std::abs(z))*/ - #else - #define __Pyx_c_is_zerof(z) ((z)==0) - #define __Pyx_c_conjf(z) (conjf(z)) - /*#define __Pyx_c_absf(z) (cabsf(z))*/ - #endif -#else - static INLINE int __Pyx_c_eqf(__pyx_t_float_complex, __pyx_t_float_complex); - static INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex, __pyx_t_float_complex); - static INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex, __pyx_t_float_complex); - static INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex, __pyx_t_float_complex); - static INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex, __pyx_t_float_complex); - static INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex); - static INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex); - static INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex); - /*static INLINE float __Pyx_c_absf(__pyx_t_float_complex);*/ -#endif - -#if CYTHON_CCOMPLEX - #define __Pyx_c_eq(a, b) ((a)==(b)) - #define __Pyx_c_sum(a, b) ((a)+(b)) - #define __Pyx_c_diff(a, b) ((a)-(b)) - #define __Pyx_c_prod(a, b) ((a)*(b)) - #define __Pyx_c_quot(a, b) ((a)/(b)) - #define __Pyx_c_neg(a) (-(a)) - #ifdef __cplusplus - #define __Pyx_c_is_zero(z) ((z)==0.0) - #define __Pyx_c_conj(z) (::std::conj(z)) - /*#define __Pyx_c_abs(z) (::std::abs(z))*/ - #else - #define __Pyx_c_is_zero(z) ((z)==0) - #define __Pyx_c_conj(z) (conj(z)) - /*#define __Pyx_c_abs(z) (cabs(z))*/ - #endif -#else - static INLINE int __Pyx_c_eq(__pyx_t_double_complex, __pyx_t_double_complex); - static INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex, __pyx_t_double_complex); - static INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex, __pyx_t_double_complex); - static INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex, __pyx_t_double_complex); - static INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex, __pyx_t_double_complex); - static INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex); - static INLINE int __Pyx_c_is_zero(__pyx_t_double_complex); - static INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex); - /*static INLINE double __Pyx_c_abs(__pyx_t_double_complex);*/ -#endif - -#if CYTHON_CCOMPLEX - #define __Pyx_c_eql(a, b) ((a)==(b)) - #define __Pyx_c_suml(a, b) ((a)+(b)) - #define __Pyx_c_diffl(a, b) ((a)-(b)) - #define __Pyx_c_prodl(a, b) ((a)*(b)) - #define __Pyx_c_quotl(a, b) ((a)/(b)) - #define __Pyx_c_negl(a) (-(a)) - #ifdef __cplusplus - #define __Pyx_c_is_zerol(z) ((z)==0.0) - #define __Pyx_c_conjl(z) (::std::conj(z)) - /*#define __Pyx_c_absl(z) (::std::abs(z))*/ - #else - #define __Pyx_c_is_zerol(z) ((z)==0) - #define __Pyx_c_conjl(z) (conjl(z)) - /*#define __Pyx_c_absl(z) (cabsl(z))*/ - #endif -#else - static INLINE int __Pyx_c_eql(__pyx_t_long_double_complex, __pyx_t_long_double_complex); - static INLINE __pyx_t_long_double_complex __Pyx_c_suml(__pyx_t_long_double_complex, __pyx_t_long_double_complex); - static INLINE __pyx_t_long_double_complex __Pyx_c_diffl(__pyx_t_long_double_complex, __pyx_t_long_double_complex); - static INLINE __pyx_t_long_double_complex __Pyx_c_prodl(__pyx_t_long_double_complex, __pyx_t_long_double_complex); - static INLINE __pyx_t_long_double_complex __Pyx_c_quotl(__pyx_t_long_double_complex, __pyx_t_long_double_complex); - static INLINE __pyx_t_long_double_complex __Pyx_c_negl(__pyx_t_long_double_complex); - static INLINE int __Pyx_c_is_zerol(__pyx_t_long_double_complex); - static INLINE __pyx_t_long_double_complex __Pyx_c_conjl(__pyx_t_long_double_complex); - /*static INLINE long double __Pyx_c_absl(__pyx_t_long_double_complex);*/ -#endif - -static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); - -static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); - -static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); - -static INLINE char __Pyx_PyInt_AsChar(PyObject *); - -static INLINE short __Pyx_PyInt_AsShort(PyObject *); - -static INLINE int __Pyx_PyInt_AsInt(PyObject *); - -static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); - -static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); - -static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); - -static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); - -static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); - -static INLINE long __Pyx_PyInt_AsLong(PyObject *); - -static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); - -static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); - -static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); - -static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, long size); /*proto*/ - -static PyObject *__Pyx_ImportModule(const char *name); /*proto*/ - -static void __Pyx_AddTraceback(const char *funcname); /*proto*/ - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Module declarations from python_buffer */ -/* Module declarations from python_object */ - /* Module declarations from stdlib */ /* Module declarations from stdio */ @@ -662,12 +702,6 @@ static PyTypeObject *__pyx_ptype_5numpy_dtype = 0; static PyTypeObject *__pyx_ptype_5numpy_flatiter = 0; static PyTypeObject *__pyx_ptype_5numpy_broadcast = 0; static PyTypeObject *__pyx_ptype_5numpy_ndarray = 0; -static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0; -static INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *); /*proto*/ -static INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *, PyObject *); /*proto*/ -static INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *, PyObject *, PyObject *); /*proto*/ -static INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *, PyObject *, PyObject *, PyObject *); /*proto*/ -static INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *, PyObject *, PyObject *, PyObject *, PyObject *); /*proto*/ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *, char *, char *, int *); /*proto*/ /* Module declarations from scikits.image.analysis.spath */ @@ -678,109 +712,91 @@ static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int_t = { "numpy.int_t", int __pyx_module_is_main_scikits__image__analysis__spath = 0; /* Implementation of scikits.image.analysis.spath */ +static PyObject *__pyx_int_0; +static PyObject *__pyx_int_1; +static PyObject *__pyx_int_neg_1; +static char __pyx_k___main__[] = "__main__"; +static PyObject *__pyx_kp___main__; +static char __pyx_k_shortest_path[] = "shortest_path"; +static PyObject *__pyx_kp_shortest_path; +static char __pyx_k_arr[] = "arr"; +static PyObject *__pyx_kp_arr; +static char __pyx_k_reach[] = "reach"; +static PyObject *__pyx_kp_reach; +static char __pyx_k_numpy[] = "numpy"; +static PyObject *__pyx_kp_numpy; +static char __pyx_k_np[] = "np"; +static PyObject *__pyx_kp_np; +static char __pyx_k_ValueError[] = "ValueError"; +static PyObject *__pyx_kp_ValueError; +static char __pyx_k_ascontiguousarray[] = "ascontiguousarray"; +static PyObject *__pyx_kp_ascontiguousarray; +static char __pyx_k_dtype[] = "dtype"; +static PyObject *__pyx_kp_dtype; +static char __pyx_k_double[] = "double"; +static PyObject *__pyx_kp_double; +static char __pyx_k_empty[] = "empty"; +static PyObject *__pyx_kp_empty; +static char __pyx_k_range[] = "range"; +static PyObject *__pyx_kp_range; +static char __pyx_k_argmin[] = "argmin"; +static PyObject *__pyx_kp_argmin; static PyObject *__pyx_builtin_ValueError; static PyObject *__pyx_builtin_range; -static PyObject *__pyx_builtin_RuntimeError; -static char __pyx_k_1[] = "Expected 2-D array as input"; -static char __pyx_k_2[] = "ndarray is not C contiguous"; -static char __pyx_k_3[] = "ndarray is not Fortran contiguous"; -static char __pyx_k_4[] = ">"; -static char __pyx_k_5[] = "<"; -static char __pyx_k_6[] = "Non-native byte order not supported"; -static char __pyx_k_7[] = "unknown dtype code in numpy.pxd (%d)"; -static char __pyx_k_8[] = "Format string allocated too short, see comment in numpy.pxd"; -static char __pyx_k_9[] = "Format string allocated too short."; -static char __pyx_k_10[] = "shortest_path (line 9)"; -static char __pyx_k__B[] = "B"; -static char __pyx_k__H[] = "H"; -static char __pyx_k__I[] = "I"; -static char __pyx_k__L[] = "L"; -static char __pyx_k__O[] = "O"; -static char __pyx_k__Q[] = "Q"; -static char __pyx_k__b[] = "b"; -static char __pyx_k__d[] = "d"; -static char __pyx_k__f[] = "f"; -static char __pyx_k__g[] = "g"; -static char __pyx_k__h[] = "h"; -static char __pyx_k__i[] = "i"; -static char __pyx_k__l[] = "l"; -static char __pyx_k__q[] = "q"; -static char __pyx_k__Zd[] = "Zd"; -static char __pyx_k__Zf[] = "Zf"; -static char __pyx_k__Zg[] = "Zg"; -static char __pyx_k__np[] = "np"; -static char __pyx_k__arr[] = "arr"; -static char __pyx_k__buf[] = "buf"; -static char __pyx_k__obj[] = "obj"; -static char __pyx_k__ndim[] = "ndim"; -static char __pyx_k__descr[] = "descr"; -static char __pyx_k__dtype[] = "dtype"; -static char __pyx_k__empty[] = "empty"; -static char __pyx_k__names[] = "names"; -static char __pyx_k__numpy[] = "numpy"; -static char __pyx_k__range[] = "range"; -static char __pyx_k__reach[] = "reach"; -static char __pyx_k__shape[] = "shape"; -static char __pyx_k__argmin[] = "argmin"; -static char __pyx_k__double[] = "double"; -static char __pyx_k__fields[] = "fields"; -static char __pyx_k__format[] = "format"; -static char __pyx_k__strides[] = "strides"; -static char __pyx_k____main__[] = "__main__"; -static char __pyx_k____test__[] = "__test__"; -static char __pyx_k__itemsize[] = "itemsize"; -static char __pyx_k__readonly[] = "readonly"; -static char __pyx_k__type_num[] = "type_num"; -static char __pyx_k__byteorder[] = "byteorder"; -static char __pyx_k__ValueError[] = "ValueError"; -static char __pyx_k__suboffsets[] = "suboffsets"; -static char __pyx_k__RuntimeError[] = "RuntimeError"; -static char __pyx_k__shortest_path[] = "shortest_path"; -static char __pyx_k__ascontiguousarray[] = "ascontiguousarray"; -static PyObject *__pyx_kp_s_1; -static PyObject *__pyx_kp_u_10; -static PyObject *__pyx_kp_u_2; -static PyObject *__pyx_kp_u_3; -static PyObject *__pyx_kp_s_4; -static PyObject *__pyx_kp_s_5; -static PyObject *__pyx_kp_u_6; -static PyObject *__pyx_kp_u_7; -static PyObject *__pyx_kp_u_8; -static PyObject *__pyx_kp_u_9; -static PyObject *__pyx_n_s__RuntimeError; -static PyObject *__pyx_n_s__ValueError; -static PyObject *__pyx_n_s____main__; -static PyObject *__pyx_n_s____test__; -static PyObject *__pyx_n_s__argmin; -static PyObject *__pyx_n_s__arr; -static PyObject *__pyx_n_s__ascontiguousarray; -static PyObject *__pyx_n_s__buf; -static PyObject *__pyx_n_s__byteorder; -static PyObject *__pyx_n_s__descr; -static PyObject *__pyx_n_s__double; -static PyObject *__pyx_n_s__dtype; -static PyObject *__pyx_n_s__empty; -static PyObject *__pyx_n_s__fields; -static PyObject *__pyx_n_s__format; -static PyObject *__pyx_n_s__itemsize; -static PyObject *__pyx_n_s__names; -static PyObject *__pyx_n_s__ndim; -static PyObject *__pyx_n_s__np; -static PyObject *__pyx_n_s__numpy; -static PyObject *__pyx_n_s__obj; -static PyObject *__pyx_n_s__range; -static PyObject *__pyx_n_s__reach; -static PyObject *__pyx_n_s__readonly; -static PyObject *__pyx_n_s__shape; -static PyObject *__pyx_n_s__shortest_path; -static PyObject *__pyx_n_s__strides; -static PyObject *__pyx_n_s__suboffsets; -static PyObject *__pyx_n_s__type_num; -static PyObject *__pyx_int_0; -static PyObject *__pyx_int_neg_1; +static PyObject *__pyx_kp_31; +static char __pyx_k_31[] = "Expected 2-D array as input"; static PyObject *__pyx_int_15; +static char __pyx_k___getbuffer__[] = "__getbuffer__"; +static PyObject *__pyx_kp___getbuffer__; +static char __pyx_k___releasebuffer__[] = "__releasebuffer__"; +static PyObject *__pyx_kp___releasebuffer__; +static char __pyx_k_info[] = "info"; +static PyObject *__pyx_kp_info; +static char __pyx_k_flags[] = "flags"; +static PyObject *__pyx_kp_flags; +static char __pyx_k_RuntimeError[] = "RuntimeError"; +static PyObject *__pyx_kp_RuntimeError; +static PyObject *__pyx_kp_1; +static PyObject *__pyx_kp_2; +static PyObject *__pyx_kp_5; +static PyObject *__pyx_kp_23; +static PyObject *__pyx_builtin_RuntimeError; +static char __pyx_k_1[] = "ndarray is not C contiguous"; +static char __pyx_k_2[] = "ndarray is not Fortran contiguous"; +static char __pyx_k_3[] = ">"; +static char __pyx_k_4[] = "<"; +static char __pyx_k_5[] = "Non-native byte order not supported"; +static char __pyx_k_6[] = "b"; +static char __pyx_k_7[] = "B"; +static char __pyx_k_8[] = "h"; +static char __pyx_k_9[] = "H"; +static char __pyx_k_10[] = "i"; +static char __pyx_k_11[] = "I"; +static char __pyx_k_12[] = "l"; +static char __pyx_k_13[] = "L"; +static char __pyx_k_14[] = "q"; +static char __pyx_k_15[] = "Q"; +static char __pyx_k_16[] = "f"; +static char __pyx_k_17[] = "d"; +static char __pyx_k_18[] = "g"; +static char __pyx_k_19[] = "Zf"; +static char __pyx_k_20[] = "Zd"; +static char __pyx_k_21[] = "Zg"; +static char __pyx_k_22[] = "O"; +static char __pyx_k_23[] = "unknown dtype code in numpy.pxd (%d)"; +static char __pyx_k_24[] = "^"; +static PyObject *__pyx_kp_25; +static PyObject *__pyx_kp_28; +static PyObject *__pyx_kp_29; +static PyObject *__pyx_kp_30; +static char __pyx_k_25[] = "Format string allocated too short, see comment in numpy.pxd"; +static char __pyx_k_26[] = ">"; +static char __pyx_k_27[] = "<"; +static char __pyx_k_28[] = "Non-native byte order not supported"; +static char __pyx_k_29[] = "Format string allocated too short."; +static char __pyx_k_30[] = "unknown dtype code in numpy.pxd (%d)"; -/* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":9 +/* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":9 * double fabs(double f) * * cpdef shortest_path(np.ndarray arr, int reach=1): # <<<<<<<<<<<<<< @@ -790,7 +806,7 @@ static PyObject *__pyx_int_15; static PyObject *__pyx_pf_7scikits_5image_8analysis_5spath_shortest_path(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArrayObject *__pyx_v_arr, int __pyx_skip_dispatch, struct __pyx_opt_args_7scikits_5image_8analysis_5spath_shortest_path *__pyx_optional_args) { - int __pyx_v_reach = ((int)1); + int __pyx_v_reach = 1; PyArrayObject *__pyx_v_data = 0; int __pyx_v_M; int __pyx_v_N; @@ -824,16 +840,18 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray Py_ssize_t __pyx_bstride_0_out = 0; Py_ssize_t __pyx_bshape_0_out = 0; PyObject *__pyx_r = NULL; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; + PyArrayObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; PyArrayObject *__pyx_t_7 = NULL; PyArrayObject *__pyx_t_8 = NULL; PyArrayObject *__pyx_t_9 = NULL; - PyArrayObject *__pyx_t_10 = NULL; + int __pyx_t_10; int __pyx_t_11; int __pyx_t_12; int __pyx_t_13; @@ -845,43 +863,40 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray int __pyx_t_19; int __pyx_t_20; int __pyx_t_21; - long __pyx_t_22; + int __pyx_t_22; int __pyx_t_23; - int __pyx_t_24; - int __pyx_t_25; + __pyx_t_5numpy_int_t __pyx_t_24; + long __pyx_t_25; int __pyx_t_26; int __pyx_t_27; - __pyx_t_5numpy_int_t __pyx_t_28; - long __pyx_t_29; - int __pyx_t_30; + int __pyx_t_28; + __pyx_t_5numpy_int_t __pyx_t_29; + long __pyx_t_30; int __pyx_t_31; int __pyx_t_32; - __pyx_t_5numpy_int_t __pyx_t_33; + int __pyx_t_33; int __pyx_t_34; - int __pyx_t_35; - int __pyx_t_36; + __pyx_t_5numpy_int_t __pyx_t_35; + long __pyx_t_36; int __pyx_t_37; - __pyx_t_5numpy_int_t __pyx_t_38; + int __pyx_t_38; long __pyx_t_39; - int __pyx_t_40; + __pyx_t_5numpy_int_t __pyx_t_40; int __pyx_t_41; long __pyx_t_42; - __pyx_t_5numpy_int_t __pyx_t_43; - long __pyx_t_44; - long __pyx_t_45; + long __pyx_t_43; __Pyx_SetupRefcountContext("shortest_path"); if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_reach = __pyx_optional_args->reach; } } - __Pyx_INCREF((PyObject *)__pyx_v_arr); __pyx_bstruct_data.buf = NULL; __pyx_bstruct_node.buf = NULL; __pyx_bstruct_cost.buf = NULL; __pyx_bstruct_out.buf = NULL; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":31 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":31 * * """ * if arr.ndim != 2: # <<<<<<<<<<<<<< @@ -891,7 +906,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_t_1 = (__pyx_v_arr->nd != 2); if (__pyx_t_1) { - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":32 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":32 * """ * if arr.ndim != 2: * raise ValueError("Expected 2-D array as input") # <<<<<<<<<<<<<< @@ -899,13 +914,13 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray * cdef np.ndarray[np.double_t, ndim=2] data = \ */ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_1)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1)); - __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_INCREF(__pyx_kp_31); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_31); + __Pyx_GIVEREF(__pyx_kp_31); + __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -913,53 +928,53 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } __pyx_L3:; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":35 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":35 * * cdef np.ndarray[np.double_t, ndim=2] data = \ * np.ascontiguousarray(arr, dtype=np.double) # <<<<<<<<<<<<<< * * cdef int M = arr.shape[0] */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__ascontiguousarray); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_np); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_1); + __pyx_t_3 = PyObject_GetAttr(__pyx_1, __pyx_kp_ascontiguousarray); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(((PyObject *)__pyx_v_arr)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_arr)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_arr)); __Pyx_GIVEREF(((PyObject *)__pyx_v_arr)); - __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__double); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyEval_CallObjectWithKeywords(__pyx_t_2, __pyx_t_3, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_1 = PyDict_New(); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_1)); + __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_kp_np); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_2); + __pyx_t_4 = PyObject_GetAttr(__pyx_2, __pyx_kp_double); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_2); __pyx_2 = 0; + if (PyDict_SetItem(__pyx_1, __pyx_kp_dtype, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyEval_CallObjectWithKeywords(__pyx_t_3, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - if (!(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_7 = ((PyArrayObject *)__pyx_t_6); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_1)); __pyx_1 = 0; + if (!(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = ((PyArrayObject *)__pyx_t_4); { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_data, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_data, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { __pyx_v_data = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_data.buf = NULL; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_bstride_0_data = __pyx_bstruct_data.strides[0]; __pyx_bstride_1_data = __pyx_bstruct_data.strides[1]; __pyx_bshape_0_data = __pyx_bstruct_data.shape[0]; __pyx_bshape_1_data = __pyx_bstruct_data.shape[1]; } } - __pyx_t_7 = 0; - __pyx_v_data = ((PyArrayObject *)__pyx_t_6); - __pyx_t_6 = 0; + __pyx_t_5 = 0; + __pyx_v_data = ((PyArrayObject *)__pyx_t_4); + __pyx_t_4 = 0; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":37 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":37 * np.ascontiguousarray(arr, dtype=np.double) * * cdef int M = arr.shape[0] # <<<<<<<<<<<<<< @@ -968,7 +983,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray */ __pyx_v_M = (__pyx_v_arr->dimensions[0]); - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":38 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":38 * * cdef int M = arr.shape[0] * cdef int N = arr.shape[1] # <<<<<<<<<<<<<< @@ -977,164 +992,164 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray */ __pyx_v_N = (__pyx_v_arr->dimensions[1]); - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":41 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":41 * * cdef np.ndarray[np.int_t, ndim=2] node = \ * np.empty((M, N), dtype=int) # <<<<<<<<<<<<<< * * cdef np.ndarray[np.double_t, ndim=2] cost = \ */ - __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_kp_np); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_2); + __pyx_t_4 = PyObject_GetAttr(__pyx_2, __pyx_kp_empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyInt_FromLong(__pyx_v_M); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_2); __pyx_2 = 0; + __pyx_t_2 = PyInt_FromLong(__pyx_v_M); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_6 = 0; + __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)((PyObject*)&PyInt_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_6 = PyEval_CallObjectWithKeywords(__pyx_t_4, __pyx_t_3, ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_6)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); + __pyx_t_6 = 0; + __pyx_1 = PyDict_New(); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_1)); + if (PyDict_SetItem(__pyx_1, __pyx_kp_dtype, ((PyObject *)((PyObject*)&PyInt_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyEval_CallObjectWithKeywords(__pyx_t_4, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_1)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_1)); __pyx_1 = 0; if (!(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_8 = ((PyArrayObject *)__pyx_t_6); + __pyx_t_7 = ((PyArrayObject *)__pyx_t_6); { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_node, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_node, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_node = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_node.buf = NULL; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_bstride_0_node = __pyx_bstruct_node.strides[0]; __pyx_bstride_1_node = __pyx_bstruct_node.strides[1]; __pyx_bshape_0_node = __pyx_bstruct_node.shape[0]; __pyx_bshape_1_node = __pyx_bstruct_node.shape[1]; } } - __pyx_t_8 = 0; + __pyx_t_7 = 0; __pyx_v_node = ((PyArrayObject *)__pyx_t_6); __pyx_t_6 = 0; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":44 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":44 * * cdef np.ndarray[np.double_t, ndim=2] cost = \ * np.empty((M, N), dtype=np.double) # <<<<<<<<<<<<<< * * cdef np.ndarray[np.int_t] out = np.empty((N,), dtype=int) */ - __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_kp_np); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_2); + __pyx_t_6 = PyObject_GetAttr(__pyx_2, __pyx_kp_empty); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_2); __pyx_2 = 0; + __pyx_t_3 = PyInt_FromLong(__pyx_v_M); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_1 = PyDict_New(); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_1)); + __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_kp_np); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_2); + __pyx_t_2 = PyObject_GetAttr(__pyx_2, __pyx_kp_double); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_2); __pyx_2 = 0; + if (PyDict_SetItem(__pyx_1, __pyx_kp_dtype, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyEval_CallObjectWithKeywords(__pyx_t_6, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyInt_FromLong(__pyx_v_M); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_6 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__double); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyEval_CallObjectWithKeywords(__pyx_t_2, __pyx_t_3, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - if (!(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_9 = ((PyArrayObject *)__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_1)); __pyx_1 = 0; + if (!(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = ((PyArrayObject *)__pyx_t_2); { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_cost, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_cost, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_cost = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_cost.buf = NULL; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_bstride_0_cost = __pyx_bstruct_cost.strides[0]; __pyx_bstride_1_cost = __pyx_bstruct_cost.strides[1]; __pyx_bshape_0_cost = __pyx_bstruct_cost.shape[0]; __pyx_bshape_1_cost = __pyx_bstruct_cost.shape[1]; } } - __pyx_t_9 = 0; - __pyx_v_cost = ((PyArrayObject *)__pyx_t_5); - __pyx_t_5 = 0; + __pyx_t_8 = 0; + __pyx_v_cost = ((PyArrayObject *)__pyx_t_2); + __pyx_t_2 = 0; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":46 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":46 * np.empty((M, N), dtype=np.double) * * cdef np.ndarray[np.int_t] out = np.empty((N,), dtype=int) # <<<<<<<<<<<<<< * * cdef int c, r, rb, r_min_node */ - __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)((PyObject*)&PyInt_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyEval_CallObjectWithKeywords(__pyx_t_4, __pyx_t_5, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_kp_np); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_2); + __pyx_t_2 = PyObject_GetAttr(__pyx_2, __pyx_kp_empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - if (!(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_10 = ((PyArrayObject *)__pyx_t_2); + __Pyx_DECREF(__pyx_2); __pyx_2 = 0; + __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_6)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); + __pyx_t_6 = 0; + __pyx_1 = PyDict_New(); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_1)); + if (PyDict_SetItem(__pyx_1, __pyx_kp_dtype, ((PyObject *)((PyObject*)&PyInt_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyEval_CallObjectWithKeywords(__pyx_t_2, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_1)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_1)); __pyx_1 = 0; + if (!(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = ((PyArrayObject *)__pyx_t_6); { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_out, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_out, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { __pyx_v_out = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_out.buf = NULL; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_bstride_0_out = __pyx_bstruct_out.strides[0]; __pyx_bshape_0_out = __pyx_bstruct_out.shape[0]; } } - __pyx_t_10 = 0; - __pyx_v_out = ((PyArrayObject *)__pyx_t_2); - __pyx_t_2 = 0; + __pyx_t_9 = 0; + __pyx_v_out = ((PyArrayObject *)__pyx_t_6); + __pyx_t_6 = 0; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":49 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":49 * * cdef int c, r, rb, r_min_node * cdef int r_bracket_min = 0, r_bracket_max = 0 # <<<<<<<<<<<<<< @@ -1144,7 +1159,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_v_r_bracket_min = 0; __pyx_v_r_bracket_max = 0; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":50 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":50 * cdef int c, r, rb, r_min_node * cdef int r_bracket_min = 0, r_bracket_max = 0 * cdef double delta0 = 0, delta1 = 0 # <<<<<<<<<<<<<< @@ -1154,49 +1169,47 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_v_delta0 = 0; __pyx_v_delta1 = 0; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":52 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":52 * cdef double delta0 = 0, delta1 = 0 * * cost[:, 0] = 0 # <<<<<<<<<<<<<< * * for c in range(1, N): */ - __pyx_t_2 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); + __pyx_2 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_2); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_2); + __Pyx_GIVEREF(__pyx_2); __Pyx_INCREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_int_0); __Pyx_GIVEREF(__pyx_int_0); - __pyx_t_2 = 0; - if (PyObject_SetItem(((PyObject *)__pyx_v_cost), __pyx_t_3, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_2 = 0; + if (PyObject_SetItem(((PyObject *)__pyx_v_cost), ((PyObject *)__pyx_t_6), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":54 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":54 * cost[:, 0] = 0 * * for c in range(1, N): # <<<<<<<<<<<<<< * for r in range(M): * r_bracket_min = r - reach */ - __pyx_t_11 = __pyx_v_N; - for (__pyx_t_12 = 1; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { - __pyx_v_c = __pyx_t_12; + for (__pyx_t_10 = 1; __pyx_t_10 < __pyx_v_N; __pyx_t_10+=1) { + __pyx_v_c = __pyx_t_10; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":55 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":55 * * for c in range(1, N): * for r in range(M): # <<<<<<<<<<<<<< * r_bracket_min = r - reach * r_bracket_max = r + reach */ - __pyx_t_13 = __pyx_v_M; - for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) { - __pyx_v_r = __pyx_t_14; + for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_v_M; __pyx_t_11+=1) { + __pyx_v_r = __pyx_t_11; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":56 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":56 * for c in range(1, N): * for r in range(M): * r_bracket_min = r - reach # <<<<<<<<<<<<<< @@ -1205,7 +1218,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray */ __pyx_v_r_bracket_min = (__pyx_v_r - __pyx_v_reach); - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":57 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":57 * for r in range(M): * r_bracket_min = r - reach * r_bracket_max = r + reach # <<<<<<<<<<<<<< @@ -1214,7 +1227,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray */ __pyx_v_r_bracket_max = (__pyx_v_r + __pyx_v_reach); - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":59 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":59 * r_bracket_max = r + reach * * if r_bracket_min < 0: # <<<<<<<<<<<<<< @@ -1224,7 +1237,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_t_1 = (__pyx_v_r_bracket_min < 0); if (__pyx_t_1) { - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":60 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":60 * * if r_bracket_min < 0: * r_bracket_min = 0 # <<<<<<<<<<<<<< @@ -1236,7 +1249,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } __pyx_L8:; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":61 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":61 * if r_bracket_min < 0: * r_bracket_min = 0 * if r_bracket_max > M - 1: # <<<<<<<<<<<<<< @@ -1246,7 +1259,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_t_1 = (__pyx_v_r_bracket_max > (__pyx_v_M - 1)); if (__pyx_t_1) { - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":62 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":62 * r_bracket_min = 0 * if r_bracket_max > M - 1: * r_bracket_max = M - 1 # <<<<<<<<<<<<<< @@ -1258,47 +1271,85 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } __pyx_L9:; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":64 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":64 * r_bracket_max = M - 1 * * node[r, c] = r_bracket_min # <<<<<<<<<<<<<< * for rb in range(r_bracket_min, r_bracket_max + 1): * delta0 = fabs(data[r, c] - data[rb, c - 1]) */ - __pyx_t_15 = __pyx_v_r; - __pyx_t_16 = __pyx_v_c; - __pyx_t_17 = -1; - if (__pyx_t_15 < 0) { - __pyx_t_15 += __pyx_bshape_0_node; - if (unlikely(__pyx_t_15 < 0)) __pyx_t_17 = 0; - } else if (unlikely(__pyx_t_15 >= __pyx_bshape_0_node)) __pyx_t_17 = 0; - if (__pyx_t_16 < 0) { - __pyx_t_16 += __pyx_bshape_1_node; - if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 1; - } else if (unlikely(__pyx_t_16 >= __pyx_bshape_1_node)) __pyx_t_17 = 1; - if (unlikely(__pyx_t_17 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_17); + __pyx_t_12 = __pyx_v_r; + __pyx_t_13 = __pyx_v_c; + __pyx_t_14 = -1; + if (__pyx_t_12 < 0) { + __pyx_t_12 += __pyx_bshape_0_node; + if (unlikely(__pyx_t_12 < 0)) __pyx_t_14 = 0; + } else if (unlikely(__pyx_t_12 >= __pyx_bshape_0_node)) __pyx_t_14 = 0; + if (__pyx_t_13 < 0) { + __pyx_t_13 += __pyx_bshape_1_node; + if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 1; + } else if (unlikely(__pyx_t_13 >= __pyx_bshape_1_node)) __pyx_t_14 = 1; + if (unlikely(__pyx_t_14 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_14); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_15, __pyx_bstride_0_node, __pyx_t_16, __pyx_bstride_1_node) = __pyx_v_r_bracket_min; + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_12, __pyx_bstride_0_node, __pyx_t_13, __pyx_bstride_1_node) = __pyx_v_r_bracket_min; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":65 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":65 * * node[r, c] = r_bracket_min * for rb in range(r_bracket_min, r_bracket_max + 1): # <<<<<<<<<<<<<< * delta0 = fabs(data[r, c] - data[rb, c - 1]) * delta1 = fabs(data[r, c] - data[node[r, c], c - 1]) */ - __pyx_t_18 = (__pyx_v_r_bracket_max + 1); - for (__pyx_t_17 = __pyx_v_r_bracket_min; __pyx_t_17 < __pyx_t_18; __pyx_t_17+=1) { - __pyx_v_rb = __pyx_t_17; + for (__pyx_t_14 = __pyx_v_r_bracket_min; __pyx_t_14 < (__pyx_v_r_bracket_max + 1); __pyx_t_14+=1) { + __pyx_v_rb = __pyx_t_14; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":66 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":66 * node[r, c] = r_bracket_min * for rb in range(r_bracket_min, r_bracket_max + 1): * delta0 = fabs(data[r, c] - data[rb, c - 1]) # <<<<<<<<<<<<<< * delta1 = fabs(data[r, c] - data[node[r, c], c - 1]) * if delta0 < delta1: + */ + __pyx_t_15 = __pyx_v_r; + __pyx_t_16 = __pyx_v_c; + __pyx_t_17 = -1; + if (__pyx_t_15 < 0) { + __pyx_t_15 += __pyx_bshape_0_data; + if (unlikely(__pyx_t_15 < 0)) __pyx_t_17 = 0; + } else if (unlikely(__pyx_t_15 >= __pyx_bshape_0_data)) __pyx_t_17 = 0; + if (__pyx_t_16 < 0) { + __pyx_t_16 += __pyx_bshape_1_data; + if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 1; + } else if (unlikely(__pyx_t_16 >= __pyx_bshape_1_data)) __pyx_t_17 = 1; + if (unlikely(__pyx_t_17 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_17); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_17 = __pyx_v_rb; + __pyx_t_18 = (__pyx_v_c - 1); + __pyx_t_19 = -1; + if (__pyx_t_17 < 0) { + __pyx_t_17 += __pyx_bshape_0_data; + if (unlikely(__pyx_t_17 < 0)) __pyx_t_19 = 0; + } else if (unlikely(__pyx_t_17 >= __pyx_bshape_0_data)) __pyx_t_19 = 0; + if (__pyx_t_18 < 0) { + __pyx_t_18 += __pyx_bshape_1_data; + if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 1; + } else if (unlikely(__pyx_t_18 >= __pyx_bshape_1_data)) __pyx_t_19 = 1; + if (unlikely(__pyx_t_19 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_19); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_delta0 = fabs(((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_15, __pyx_bstride_0_data, __pyx_t_16, __pyx_bstride_1_data)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_17, __pyx_bstride_0_data, __pyx_t_18, __pyx_bstride_1_data)))); + + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":67 + * for rb in range(r_bracket_min, r_bracket_max + 1): + * delta0 = fabs(data[r, c] - data[rb, c - 1]) + * delta1 = fabs(data[r, c] - data[node[r, c], c - 1]) # <<<<<<<<<<<<<< + * if delta0 < delta1: + * node[r, c] = rb */ __pyx_t_19 = __pyx_v_r; __pyx_t_20 = __pyx_v_c; @@ -1313,80 +1364,41 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray } else if (unlikely(__pyx_t_20 >= __pyx_bshape_1_data)) __pyx_t_21 = 1; if (unlikely(__pyx_t_21 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_21); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_21 = __pyx_v_rb; - __pyx_t_22 = (__pyx_v_c - 1); + __pyx_t_21 = __pyx_v_r; + __pyx_t_22 = __pyx_v_c; __pyx_t_23 = -1; if (__pyx_t_21 < 0) { - __pyx_t_21 += __pyx_bshape_0_data; + __pyx_t_21 += __pyx_bshape_0_node; if (unlikely(__pyx_t_21 < 0)) __pyx_t_23 = 0; - } else if (unlikely(__pyx_t_21 >= __pyx_bshape_0_data)) __pyx_t_23 = 0; + } else if (unlikely(__pyx_t_21 >= __pyx_bshape_0_node)) __pyx_t_23 = 0; if (__pyx_t_22 < 0) { - __pyx_t_22 += __pyx_bshape_1_data; + __pyx_t_22 += __pyx_bshape_1_node; if (unlikely(__pyx_t_22 < 0)) __pyx_t_23 = 1; - } else if (unlikely(__pyx_t_22 >= __pyx_bshape_1_data)) __pyx_t_23 = 1; + } else if (unlikely(__pyx_t_22 >= __pyx_bshape_1_node)) __pyx_t_23 = 1; if (unlikely(__pyx_t_23 != -1)) { __Pyx_RaiseBufferIndexError(__pyx_t_23); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_v_delta0 = fabs(((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_19, __pyx_bstride_0_data, __pyx_t_20, __pyx_bstride_1_data)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_21, __pyx_bstride_0_data, __pyx_t_22, __pyx_bstride_1_data)))); - - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":67 - * for rb in range(r_bracket_min, r_bracket_max + 1): - * delta0 = fabs(data[r, c] - data[rb, c - 1]) - * delta1 = fabs(data[r, c] - data[node[r, c], c - 1]) # <<<<<<<<<<<<<< - * if delta0 < delta1: - * node[r, c] = rb - */ - __pyx_t_23 = __pyx_v_r; - __pyx_t_24 = __pyx_v_c; - __pyx_t_25 = -1; - if (__pyx_t_23 < 0) { - __pyx_t_23 += __pyx_bshape_0_data; - if (unlikely(__pyx_t_23 < 0)) __pyx_t_25 = 0; - } else if (unlikely(__pyx_t_23 >= __pyx_bshape_0_data)) __pyx_t_25 = 0; + __pyx_t_24 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_21, __pyx_bstride_0_node, __pyx_t_22, __pyx_bstride_1_node)); + __pyx_t_25 = (__pyx_v_c - 1); + __pyx_t_23 = -1; if (__pyx_t_24 < 0) { - __pyx_t_24 += __pyx_bshape_1_data; - if (unlikely(__pyx_t_24 < 0)) __pyx_t_25 = 1; - } else if (unlikely(__pyx_t_24 >= __pyx_bshape_1_data)) __pyx_t_25 = 1; - if (unlikely(__pyx_t_25 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_25); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_25 = __pyx_v_r; - __pyx_t_26 = __pyx_v_c; - __pyx_t_27 = -1; + __pyx_t_24 += __pyx_bshape_0_data; + if (unlikely(__pyx_t_24 < 0)) __pyx_t_23 = 0; + } else if (unlikely(__pyx_t_24 >= __pyx_bshape_0_data)) __pyx_t_23 = 0; if (__pyx_t_25 < 0) { - __pyx_t_25 += __pyx_bshape_0_node; - if (unlikely(__pyx_t_25 < 0)) __pyx_t_27 = 0; - } else if (unlikely(__pyx_t_25 >= __pyx_bshape_0_node)) __pyx_t_27 = 0; - if (__pyx_t_26 < 0) { - __pyx_t_26 += __pyx_bshape_1_node; - if (unlikely(__pyx_t_26 < 0)) __pyx_t_27 = 1; - } else if (unlikely(__pyx_t_26 >= __pyx_bshape_1_node)) __pyx_t_27 = 1; - if (unlikely(__pyx_t_27 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_27); + __pyx_t_25 += __pyx_bshape_1_data; + if (unlikely(__pyx_t_25 < 0)) __pyx_t_23 = 1; + } else if (unlikely(__pyx_t_25 >= __pyx_bshape_1_data)) __pyx_t_23 = 1; + if (unlikely(__pyx_t_23 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_23); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_28 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_25, __pyx_bstride_0_node, __pyx_t_26, __pyx_bstride_1_node)); - __pyx_t_29 = (__pyx_v_c - 1); - __pyx_t_27 = -1; - if (__pyx_t_28 < 0) { - __pyx_t_28 += __pyx_bshape_0_data; - if (unlikely(__pyx_t_28 < 0)) __pyx_t_27 = 0; - } else if (unlikely(__pyx_t_28 >= __pyx_bshape_0_data)) __pyx_t_27 = 0; - if (__pyx_t_29 < 0) { - __pyx_t_29 += __pyx_bshape_1_data; - if (unlikely(__pyx_t_29 < 0)) __pyx_t_27 = 1; - } else if (unlikely(__pyx_t_29 >= __pyx_bshape_1_data)) __pyx_t_27 = 1; - if (unlikely(__pyx_t_27 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_27); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_delta1 = fabs(((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_23, __pyx_bstride_0_data, __pyx_t_24, __pyx_bstride_1_data)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_28, __pyx_bstride_0_data, __pyx_t_29, __pyx_bstride_1_data)))); + __pyx_v_delta1 = fabs(((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_19, __pyx_bstride_0_data, __pyx_t_20, __pyx_bstride_1_data)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_24, __pyx_bstride_0_data, __pyx_t_25, __pyx_bstride_1_data)))); - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":68 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":68 * delta0 = fabs(data[r, c] - data[rb, c - 1]) * delta1 = fabs(data[r, c] - data[node[r, c], c - 1]) * if delta0 < delta1: # <<<<<<<<<<<<<< @@ -1396,152 +1408,152 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __pyx_t_1 = (__pyx_v_delta0 < __pyx_v_delta1); if (__pyx_t_1) { - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":69 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":69 * delta1 = fabs(data[r, c] - data[node[r, c], c - 1]) * if delta0 < delta1: * node[r, c] = rb # <<<<<<<<<<<<<< * * cost[r, c] = cost[node[r, c], c - 1] + \ */ - __pyx_t_27 = __pyx_v_r; - __pyx_t_30 = __pyx_v_c; - __pyx_t_31 = -1; - if (__pyx_t_27 < 0) { - __pyx_t_27 += __pyx_bshape_0_node; - if (unlikely(__pyx_t_27 < 0)) __pyx_t_31 = 0; - } else if (unlikely(__pyx_t_27 >= __pyx_bshape_0_node)) __pyx_t_31 = 0; - if (__pyx_t_30 < 0) { - __pyx_t_30 += __pyx_bshape_1_node; - if (unlikely(__pyx_t_30 < 0)) __pyx_t_31 = 1; - } else if (unlikely(__pyx_t_30 >= __pyx_bshape_1_node)) __pyx_t_31 = 1; - if (unlikely(__pyx_t_31 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_31); + __pyx_t_23 = __pyx_v_r; + __pyx_t_26 = __pyx_v_c; + __pyx_t_27 = -1; + if (__pyx_t_23 < 0) { + __pyx_t_23 += __pyx_bshape_0_node; + if (unlikely(__pyx_t_23 < 0)) __pyx_t_27 = 0; + } else if (unlikely(__pyx_t_23 >= __pyx_bshape_0_node)) __pyx_t_27 = 0; + if (__pyx_t_26 < 0) { + __pyx_t_26 += __pyx_bshape_1_node; + if (unlikely(__pyx_t_26 < 0)) __pyx_t_27 = 1; + } else if (unlikely(__pyx_t_26 >= __pyx_bshape_1_node)) __pyx_t_27 = 1; + if (unlikely(__pyx_t_27 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_27); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_27, __pyx_bstride_0_node, __pyx_t_30, __pyx_bstride_1_node) = __pyx_v_rb; + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_23, __pyx_bstride_0_node, __pyx_t_26, __pyx_bstride_1_node) = __pyx_v_rb; goto __pyx_L12; } __pyx_L12:; } - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":71 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":71 * node[r, c] = rb * * cost[r, c] = cost[node[r, c], c - 1] + \ # <<<<<<<<<<<<<< * fabs(data[r, c] - data[node[r, c], c - 1]) * */ - __pyx_t_17 = __pyx_v_r; - __pyx_t_31 = __pyx_v_c; - __pyx_t_32 = -1; - if (__pyx_t_17 < 0) { - __pyx_t_17 += __pyx_bshape_0_node; - if (unlikely(__pyx_t_17 < 0)) __pyx_t_32 = 0; - } else if (unlikely(__pyx_t_17 >= __pyx_bshape_0_node)) __pyx_t_32 = 0; - if (__pyx_t_31 < 0) { - __pyx_t_31 += __pyx_bshape_1_node; - if (unlikely(__pyx_t_31 < 0)) __pyx_t_32 = 1; - } else if (unlikely(__pyx_t_31 >= __pyx_bshape_1_node)) __pyx_t_32 = 1; - if (unlikely(__pyx_t_32 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_32); + __pyx_t_14 = __pyx_v_r; + __pyx_t_27 = __pyx_v_c; + __pyx_t_28 = -1; + if (__pyx_t_14 < 0) { + __pyx_t_14 += __pyx_bshape_0_node; + if (unlikely(__pyx_t_14 < 0)) __pyx_t_28 = 0; + } else if (unlikely(__pyx_t_14 >= __pyx_bshape_0_node)) __pyx_t_28 = 0; + if (__pyx_t_27 < 0) { + __pyx_t_27 += __pyx_bshape_1_node; + if (unlikely(__pyx_t_27 < 0)) __pyx_t_28 = 1; + } else if (unlikely(__pyx_t_27 >= __pyx_bshape_1_node)) __pyx_t_28 = 1; + if (unlikely(__pyx_t_28 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_28); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_33 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_17, __pyx_bstride_0_node, __pyx_t_31, __pyx_bstride_1_node)); - __pyx_t_18 = (__pyx_v_c - 1); - __pyx_t_32 = -1; - if (__pyx_t_33 < 0) { - __pyx_t_33 += __pyx_bshape_0_cost; - if (unlikely(__pyx_t_33 < 0)) __pyx_t_32 = 0; - } else if (unlikely(__pyx_t_33 >= __pyx_bshape_0_cost)) __pyx_t_32 = 0; - if (__pyx_t_18 < 0) { - __pyx_t_18 += __pyx_bshape_1_cost; - if (unlikely(__pyx_t_18 < 0)) __pyx_t_32 = 1; - } else if (unlikely(__pyx_t_18 >= __pyx_bshape_1_cost)) __pyx_t_32 = 1; - if (unlikely(__pyx_t_32 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_32); + __pyx_t_29 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_14, __pyx_bstride_0_node, __pyx_t_27, __pyx_bstride_1_node)); + __pyx_t_30 = (__pyx_v_c - 1); + __pyx_t_28 = -1; + if (__pyx_t_29 < 0) { + __pyx_t_29 += __pyx_bshape_0_cost; + if (unlikely(__pyx_t_29 < 0)) __pyx_t_28 = 0; + } else if (unlikely(__pyx_t_29 >= __pyx_bshape_0_cost)) __pyx_t_28 = 0; + if (__pyx_t_30 < 0) { + __pyx_t_30 += __pyx_bshape_1_cost; + if (unlikely(__pyx_t_30 < 0)) __pyx_t_28 = 1; + } else if (unlikely(__pyx_t_30 >= __pyx_bshape_1_cost)) __pyx_t_28 = 1; + if (unlikely(__pyx_t_28 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_28); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":72 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":72 * * cost[r, c] = cost[node[r, c], c - 1] + \ * fabs(data[r, c] - data[node[r, c], c - 1]) # <<<<<<<<<<<<<< * * # Find minimum cost path */ + __pyx_t_28 = __pyx_v_r; + __pyx_t_31 = __pyx_v_c; + __pyx_t_32 = -1; + if (__pyx_t_28 < 0) { + __pyx_t_28 += __pyx_bshape_0_data; + if (unlikely(__pyx_t_28 < 0)) __pyx_t_32 = 0; + } else if (unlikely(__pyx_t_28 >= __pyx_bshape_0_data)) __pyx_t_32 = 0; + if (__pyx_t_31 < 0) { + __pyx_t_31 += __pyx_bshape_1_data; + if (unlikely(__pyx_t_31 < 0)) __pyx_t_32 = 1; + } else if (unlikely(__pyx_t_31 >= __pyx_bshape_1_data)) __pyx_t_32 = 1; + if (unlikely(__pyx_t_32 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_32); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } __pyx_t_32 = __pyx_v_r; - __pyx_t_34 = __pyx_v_c; - __pyx_t_35 = -1; + __pyx_t_33 = __pyx_v_c; + __pyx_t_34 = -1; if (__pyx_t_32 < 0) { - __pyx_t_32 += __pyx_bshape_0_data; - if (unlikely(__pyx_t_32 < 0)) __pyx_t_35 = 0; - } else if (unlikely(__pyx_t_32 >= __pyx_bshape_0_data)) __pyx_t_35 = 0; - if (__pyx_t_34 < 0) { - __pyx_t_34 += __pyx_bshape_1_data; - if (unlikely(__pyx_t_34 < 0)) __pyx_t_35 = 1; - } else if (unlikely(__pyx_t_34 >= __pyx_bshape_1_data)) __pyx_t_35 = 1; - if (unlikely(__pyx_t_35 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_35); + __pyx_t_32 += __pyx_bshape_0_node; + if (unlikely(__pyx_t_32 < 0)) __pyx_t_34 = 0; + } else if (unlikely(__pyx_t_32 >= __pyx_bshape_0_node)) __pyx_t_34 = 0; + if (__pyx_t_33 < 0) { + __pyx_t_33 += __pyx_bshape_1_node; + if (unlikely(__pyx_t_33 < 0)) __pyx_t_34 = 1; + } else if (unlikely(__pyx_t_33 >= __pyx_bshape_1_node)) __pyx_t_34 = 1; + if (unlikely(__pyx_t_34 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_34); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_35 = __pyx_v_r; - __pyx_t_36 = __pyx_v_c; - __pyx_t_37 = -1; + __pyx_t_35 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_32, __pyx_bstride_0_node, __pyx_t_33, __pyx_bstride_1_node)); + __pyx_t_36 = (__pyx_v_c - 1); + __pyx_t_34 = -1; if (__pyx_t_35 < 0) { - __pyx_t_35 += __pyx_bshape_0_node; - if (unlikely(__pyx_t_35 < 0)) __pyx_t_37 = 0; - } else if (unlikely(__pyx_t_35 >= __pyx_bshape_0_node)) __pyx_t_37 = 0; + __pyx_t_35 += __pyx_bshape_0_data; + if (unlikely(__pyx_t_35 < 0)) __pyx_t_34 = 0; + } else if (unlikely(__pyx_t_35 >= __pyx_bshape_0_data)) __pyx_t_34 = 0; if (__pyx_t_36 < 0) { - __pyx_t_36 += __pyx_bshape_1_node; - if (unlikely(__pyx_t_36 < 0)) __pyx_t_37 = 1; - } else if (unlikely(__pyx_t_36 >= __pyx_bshape_1_node)) __pyx_t_37 = 1; - if (unlikely(__pyx_t_37 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_37); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_38 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_35, __pyx_bstride_0_node, __pyx_t_36, __pyx_bstride_1_node)); - __pyx_t_39 = (__pyx_v_c - 1); - __pyx_t_37 = -1; - if (__pyx_t_38 < 0) { - __pyx_t_38 += __pyx_bshape_0_data; - if (unlikely(__pyx_t_38 < 0)) __pyx_t_37 = 0; - } else if (unlikely(__pyx_t_38 >= __pyx_bshape_0_data)) __pyx_t_37 = 0; - if (__pyx_t_39 < 0) { - __pyx_t_39 += __pyx_bshape_1_data; - if (unlikely(__pyx_t_39 < 0)) __pyx_t_37 = 1; - } else if (unlikely(__pyx_t_39 >= __pyx_bshape_1_data)) __pyx_t_37 = 1; - if (unlikely(__pyx_t_37 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_37); + __pyx_t_36 += __pyx_bshape_1_data; + if (unlikely(__pyx_t_36 < 0)) __pyx_t_34 = 1; + } else if (unlikely(__pyx_t_36 >= __pyx_bshape_1_data)) __pyx_t_34 = 1; + if (unlikely(__pyx_t_34 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_34); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":71 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":71 * node[r, c] = rb * * cost[r, c] = cost[node[r, c], c - 1] + \ # <<<<<<<<<<<<<< * fabs(data[r, c] - data[node[r, c], c - 1]) * */ - __pyx_t_37 = __pyx_v_r; - __pyx_t_40 = __pyx_v_c; - __pyx_t_41 = -1; + __pyx_t_34 = __pyx_v_r; + __pyx_t_37 = __pyx_v_c; + __pyx_t_38 = -1; + if (__pyx_t_34 < 0) { + __pyx_t_34 += __pyx_bshape_0_cost; + if (unlikely(__pyx_t_34 < 0)) __pyx_t_38 = 0; + } else if (unlikely(__pyx_t_34 >= __pyx_bshape_0_cost)) __pyx_t_38 = 0; if (__pyx_t_37 < 0) { - __pyx_t_37 += __pyx_bshape_0_cost; - if (unlikely(__pyx_t_37 < 0)) __pyx_t_41 = 0; - } else if (unlikely(__pyx_t_37 >= __pyx_bshape_0_cost)) __pyx_t_41 = 0; - if (__pyx_t_40 < 0) { - __pyx_t_40 += __pyx_bshape_1_cost; - if (unlikely(__pyx_t_40 < 0)) __pyx_t_41 = 1; - } else if (unlikely(__pyx_t_40 >= __pyx_bshape_1_cost)) __pyx_t_41 = 1; - if (unlikely(__pyx_t_41 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_41); + __pyx_t_37 += __pyx_bshape_1_cost; + if (unlikely(__pyx_t_37 < 0)) __pyx_t_38 = 1; + } else if (unlikely(__pyx_t_37 >= __pyx_bshape_1_cost)) __pyx_t_38 = 1; + if (unlikely(__pyx_t_38 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_38); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_cost.buf, __pyx_t_37, __pyx_bstride_0_cost, __pyx_t_40, __pyx_bstride_1_cost) = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_cost.buf, __pyx_t_33, __pyx_bstride_0_cost, __pyx_t_18, __pyx_bstride_1_cost)) + fabs(((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_32, __pyx_bstride_0_data, __pyx_t_34, __pyx_bstride_1_data)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_38, __pyx_bstride_0_data, __pyx_t_39, __pyx_bstride_1_data))))); + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_cost.buf, __pyx_t_34, __pyx_bstride_0_cost, __pyx_t_37, __pyx_bstride_1_cost) = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_cost.buf, __pyx_t_29, __pyx_bstride_0_cost, __pyx_t_30, __pyx_bstride_1_cost)) + fabs(((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_28, __pyx_bstride_0_data, __pyx_t_31, __pyx_bstride_1_data)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_data.buf, __pyx_t_35, __pyx_bstride_0_data, __pyx_t_36, __pyx_bstride_1_data))))); } } - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":75 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":75 * * # Find minimum cost path * print arr # <<<<<<<<<<<<<< @@ -1550,7 +1562,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray */ if (__Pyx_PrintOne(((PyObject *)__pyx_v_arr)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":76 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":76 * # Find minimum cost path * print arr * print cost # <<<<<<<<<<<<<< @@ -1559,7 +1571,7 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray */ if (__Pyx_PrintOne(((PyObject *)__pyx_v_cost)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":77 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":77 * print arr * print cost * print node # <<<<<<<<<<<<<< @@ -1568,152 +1580,153 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray */ if (__Pyx_PrintOne(((PyObject *)__pyx_v_node)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":78 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":78 * print cost * print node * r_min_node = cost[:,-1].argmin() # <<<<<<<<<<<<<< * * # Backtrack */ - __pyx_t_3 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); + __pyx_1 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_1); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_1); + __Pyx_GIVEREF(__pyx_1); __Pyx_INCREF(__pyx_int_neg_1); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_int_neg_1); __Pyx_GIVEREF(__pyx_int_neg_1); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_cost), __pyx_t_2); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__argmin); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_11 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_r_min_node = __pyx_t_11; + __pyx_1 = 0; + __pyx_2 = PyObject_GetItem(((PyObject *)__pyx_v_cost), ((PyObject *)__pyx_t_6)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_2); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_t_6 = PyObject_GetAttr(__pyx_2, __pyx_kp_argmin); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_2); __pyx_2 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_r_min_node = __pyx_t_10; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":81 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":81 * * # Backtrack * out[N - 1] = r_min_node # <<<<<<<<<<<<<< * for c in range(N - 1, 0, -1): * out[c - 1] = node[out[c], c] */ - __pyx_t_42 = (__pyx_v_N - 1); - __pyx_t_11 = -1; - if (__pyx_t_42 < 0) { - __pyx_t_42 += __pyx_bshape_0_out; - if (unlikely(__pyx_t_42 < 0)) __pyx_t_11 = 0; - } else if (unlikely(__pyx_t_42 >= __pyx_bshape_0_out)) __pyx_t_11 = 0; - if (unlikely(__pyx_t_11 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_11); + __pyx_t_39 = (__pyx_v_N - 1); + __pyx_t_10 = -1; + if (__pyx_t_39 < 0) { + __pyx_t_39 += __pyx_bshape_0_out; + if (unlikely(__pyx_t_39 < 0)) __pyx_t_10 = 0; + } else if (unlikely(__pyx_t_39 >= __pyx_bshape_0_out)) __pyx_t_10 = 0; + if (unlikely(__pyx_t_10 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_10); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_bstruct_out.buf, __pyx_t_42, __pyx_bstride_0_out) = __pyx_v_r_min_node; + *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_bstruct_out.buf, __pyx_t_39, __pyx_bstride_0_out) = __pyx_v_r_min_node; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":82 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":82 * # Backtrack * out[N - 1] = r_min_node * for c in range(N - 1, 0, -1): # <<<<<<<<<<<<<< * out[c - 1] = node[out[c], c] * */ - for (__pyx_t_11 = (__pyx_v_N - 1); __pyx_t_11 > 0; __pyx_t_11-=1) { - __pyx_v_c = __pyx_t_11; + for (__pyx_t_10 = (__pyx_v_N - 1); __pyx_t_10 > 0; __pyx_t_10-=1) { + __pyx_v_c = __pyx_t_10; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":83 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":83 * out[N - 1] = r_min_node * for c in range(N - 1, 0, -1): * out[c - 1] = node[out[c], c] # <<<<<<<<<<<<<< * * return out, cost[r_min_node, N - 1] */ - __pyx_t_12 = __pyx_v_c; - __pyx_t_13 = -1; - if (__pyx_t_12 < 0) { - __pyx_t_12 += __pyx_bshape_0_out; - if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 0; - } else if (unlikely(__pyx_t_12 >= __pyx_bshape_0_out)) __pyx_t_13 = 0; - if (unlikely(__pyx_t_13 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_13); + __pyx_t_11 = __pyx_v_c; + __pyx_t_38 = -1; + if (__pyx_t_11 < 0) { + __pyx_t_11 += __pyx_bshape_0_out; + if (unlikely(__pyx_t_11 < 0)) __pyx_t_38 = 0; + } else if (unlikely(__pyx_t_11 >= __pyx_bshape_0_out)) __pyx_t_38 = 0; + if (unlikely(__pyx_t_38 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_38); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_43 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_bstruct_out.buf, __pyx_t_12, __pyx_bstride_0_out)); - __pyx_t_13 = __pyx_v_c; - __pyx_t_14 = -1; - if (__pyx_t_43 < 0) { - __pyx_t_43 += __pyx_bshape_0_node; - if (unlikely(__pyx_t_43 < 0)) __pyx_t_14 = 0; - } else if (unlikely(__pyx_t_43 >= __pyx_bshape_0_node)) __pyx_t_14 = 0; - if (__pyx_t_13 < 0) { - __pyx_t_13 += __pyx_bshape_1_node; - if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 1; - } else if (unlikely(__pyx_t_13 >= __pyx_bshape_1_node)) __pyx_t_14 = 1; - if (unlikely(__pyx_t_14 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_14); + __pyx_t_40 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_bstruct_out.buf, __pyx_t_11, __pyx_bstride_0_out)); + __pyx_t_38 = __pyx_v_c; + __pyx_t_41 = -1; + if (__pyx_t_40 < 0) { + __pyx_t_40 += __pyx_bshape_0_node; + if (unlikely(__pyx_t_40 < 0)) __pyx_t_41 = 0; + } else if (unlikely(__pyx_t_40 >= __pyx_bshape_0_node)) __pyx_t_41 = 0; + if (__pyx_t_38 < 0) { + __pyx_t_38 += __pyx_bshape_1_node; + if (unlikely(__pyx_t_38 < 0)) __pyx_t_41 = 1; + } else if (unlikely(__pyx_t_38 >= __pyx_bshape_1_node)) __pyx_t_41 = 1; + if (unlikely(__pyx_t_41 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_41); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_44 = (__pyx_v_c - 1); - __pyx_t_14 = -1; - if (__pyx_t_44 < 0) { - __pyx_t_44 += __pyx_bshape_0_out; - if (unlikely(__pyx_t_44 < 0)) __pyx_t_14 = 0; - } else if (unlikely(__pyx_t_44 >= __pyx_bshape_0_out)) __pyx_t_14 = 0; - if (unlikely(__pyx_t_14 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_14); + __pyx_t_42 = (__pyx_v_c - 1); + __pyx_t_41 = -1; + if (__pyx_t_42 < 0) { + __pyx_t_42 += __pyx_bshape_0_out; + if (unlikely(__pyx_t_42 < 0)) __pyx_t_41 = 0; + } else if (unlikely(__pyx_t_42 >= __pyx_bshape_0_out)) __pyx_t_41 = 0; + if (unlikely(__pyx_t_41 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_41); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_bstruct_out.buf, __pyx_t_44, __pyx_bstride_0_out) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_43, __pyx_bstride_0_node, __pyx_t_13, __pyx_bstride_1_node)); + *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_bstruct_out.buf, __pyx_t_42, __pyx_bstride_0_out) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_node.buf, __pyx_t_40, __pyx_bstride_0_node, __pyx_t_38, __pyx_bstride_1_node)); } - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":85 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":85 * out[c - 1] = node[out[c], c] * * return out, cost[r_min_node, N - 1] # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); - __pyx_t_11 = __pyx_v_r_min_node; - __pyx_t_45 = (__pyx_v_N - 1); - __pyx_t_14 = -1; - if (__pyx_t_11 < 0) { - __pyx_t_11 += __pyx_bshape_0_cost; - if (unlikely(__pyx_t_11 < 0)) __pyx_t_14 = 0; - } else if (unlikely(__pyx_t_11 >= __pyx_bshape_0_cost)) __pyx_t_14 = 0; - if (__pyx_t_45 < 0) { - __pyx_t_45 += __pyx_bshape_1_cost; - if (unlikely(__pyx_t_45 < 0)) __pyx_t_14 = 1; - } else if (unlikely(__pyx_t_45 >= __pyx_bshape_1_cost)) __pyx_t_14 = 1; - if (unlikely(__pyx_t_14 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_14); + __pyx_t_10 = __pyx_v_r_min_node; + __pyx_t_43 = (__pyx_v_N - 1); + __pyx_t_41 = -1; + if (__pyx_t_10 < 0) { + __pyx_t_10 += __pyx_bshape_0_cost; + if (unlikely(__pyx_t_10 < 0)) __pyx_t_41 = 0; + } else if (unlikely(__pyx_t_10 >= __pyx_bshape_0_cost)) __pyx_t_41 = 0; + if (__pyx_t_43 < 0) { + __pyx_t_43 += __pyx_bshape_1_cost; + if (unlikely(__pyx_t_43 < 0)) __pyx_t_41 = 1; + } else if (unlikely(__pyx_t_43 >= __pyx_bshape_1_cost)) __pyx_t_41 = 1; + if (unlikely(__pyx_t_41 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_41); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_3 = PyFloat_FromDouble((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_cost.buf, __pyx_t_11, __pyx_bstride_0_cost, __pyx_t_45, __pyx_bstride_1_cost))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyFloat_FromDouble((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_cost.buf, __pyx_t_10, __pyx_bstride_0_cost, __pyx_t_43, __pyx_bstride_1_cost))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); __Pyx_INCREF(((PyObject *)__pyx_v_out)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_out)); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_out)); __Pyx_GIVEREF(((PyObject *)__pyx_v_out)); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_r = ((PyObject *)__pyx_t_6); + __pyx_t_6 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_1); + __Pyx_XDECREF(__pyx_2); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); @@ -1735,13 +1748,12 @@ static PyObject *__pyx_f_7scikits_5image_8analysis_5spath_shortest_path(PyArray __Pyx_XDECREF((PyObject *)__pyx_v_node); __Pyx_XDECREF((PyObject *)__pyx_v_cost); __Pyx_XDECREF((PyObject *)__pyx_v_out); - __Pyx_DECREF((PyObject *)__pyx_v_arr); __Pyx_XGIVEREF(__pyx_r); __Pyx_FinishRefcountContext(); return __pyx_r; } -/* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":9 +/* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":9 * double fabs(double f) * * cpdef shortest_path(np.ndarray arr, int reach=1): # <<<<<<<<<<<<<< @@ -1755,9 +1767,9 @@ static PyObject *__pyx_pf_7scikits_5image_8analysis_5spath_shortest_path(PyObjec PyArrayObject *__pyx_v_arr = 0; int __pyx_v_reach; PyObject *__pyx_r = NULL; + struct __pyx_opt_args_7scikits_5image_8analysis_5spath_shortest_path __pyx_1; PyObject *__pyx_t_1 = NULL; - struct __pyx_opt_args_7scikits_5image_8analysis_5spath_shortest_path __pyx_t_2; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__arr,&__pyx_n_s__reach,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_kp_arr,&__pyx_kp_reach,0}; __Pyx_SetupRefcountContext("shortest_path"); __pyx_self = __pyx_self; if (unlikely(__pyx_kwds)) { @@ -1771,12 +1783,12 @@ static PyObject *__pyx_pf_7scikits_5image_8analysis_5spath_shortest_path(PyObjec } switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__arr); + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_arr); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reach); + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_reach); if (unlikely(value)) { values[1] = value; kw_args--; } } } @@ -1787,10 +1799,10 @@ static PyObject *__pyx_pf_7scikits_5image_8analysis_5spath_shortest_path(PyObjec if (values[1]) { __pyx_v_reach = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_reach == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { - __pyx_v_reach = ((int)1); + __pyx_v_reach = 1; } } else { - __pyx_v_reach = ((int)1); + __pyx_v_reach = 1; switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: __pyx_v_reach = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_reach == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} case 1: __pyx_v_arr = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); @@ -1807,9 +1819,9 @@ static PyObject *__pyx_pf_7scikits_5image_8analysis_5spath_shortest_path(PyObjec __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_arr), __pyx_ptype_5numpy_ndarray, 1, "arr", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_XDECREF(__pyx_r); - __pyx_t_2.__pyx_n = 1; - __pyx_t_2.reach = __pyx_v_reach; - __pyx_t_1 = __pyx_f_7scikits_5image_8analysis_5spath_shortest_path(__pyx_v_arr, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_1.__pyx_n = 1; + __pyx_1.reach = __pyx_v_reach; + __pyx_t_1 = __pyx_f_7scikits_5image_8analysis_5spath_shortest_path(__pyx_v_arr, 0, &__pyx_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -1827,7 +1839,7 @@ static PyObject *__pyx_pf_7scikits_5image_8analysis_5spath_shortest_path(PyObjec return __pyx_r; } -/* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":158 +/* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":152 * # experimental exception made for __getbuffer__ and __releasebuffer__ * # -- the details of this may change. * def __getbuffer__(ndarray self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< @@ -1854,16 +1866,13 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf int __pyx_t_4; int __pyx_t_5; int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - char *__pyx_t_9; + char *__pyx_t_7; __Pyx_SetupRefcountContext("__getbuffer__"); if (__pyx_v_info == NULL) return 0; __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); __Pyx_GIVEREF(__pyx_v_info->obj); - __Pyx_INCREF((PyObject *)__pyx_v_self); - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":164 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":158 * # of flags * cdef int copy_shape, i, ndim * cdef int endian_detector = 1 # <<<<<<<<<<<<<< @@ -1872,7 +1881,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_endian_detector = 1; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":165 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":159 * cdef int copy_shape, i, ndim * cdef int endian_detector = 1 * cdef bint little_endian = ((&endian_detector)[0] != 0) # <<<<<<<<<<<<<< @@ -1881,7 +1890,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0); - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":167 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":161 * cdef bint little_endian = ((&endian_detector)[0] != 0) * * ndim = PyArray_NDIM(self) # <<<<<<<<<<<<<< @@ -1890,7 +1899,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_ndim = PyArray_NDIM(((PyArrayObject *)__pyx_v_self)); - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":169 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":163 * ndim = PyArray_NDIM(self) * * if sizeof(npy_intp) != sizeof(Py_ssize_t): # <<<<<<<<<<<<<< @@ -1900,7 +1909,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t))); if (__pyx_t_1) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":170 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":164 * * if sizeof(npy_intp) != sizeof(Py_ssize_t): * copy_shape = 1 # <<<<<<<<<<<<<< @@ -1912,7 +1921,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf } /*else*/ { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":172 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":166 * copy_shape = 1 * else: * copy_shape = 0 # <<<<<<<<<<<<<< @@ -1923,20 +1932,20 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf } __pyx_L5:; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":174 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":168 * copy_shape = 0 * * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) # <<<<<<<<<<<<<< * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): - * raise ValueError(u"ndarray is not C contiguous") + * raise ValueError("ndarray is not C contiguous") */ if (((__pyx_v_flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS)) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":175 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":169 * * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): # <<<<<<<<<<<<<< - * raise ValueError(u"ndarray is not C contiguous") + * raise ValueError("ndarray is not C contiguous") * */ __pyx_t_1 = (!PyArray_CHKFLAGS(((PyArrayObject *)__pyx_v_self), NPY_C_CONTIGUOUS)); @@ -1945,42 +1954,42 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf } if (__pyx_t_1) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":176 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":170 * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): - * raise ValueError(u"ndarray is not C contiguous") # <<<<<<<<<<<<<< + * raise ValueError("ndarray is not C contiguous") # <<<<<<<<<<<<<< * * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_2)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_u_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_2)); - __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_INCREF(__pyx_kp_1); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_1); + __Pyx_GIVEREF(__pyx_kp_1); + __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L6; } __pyx_L6:; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":178 - * raise ValueError(u"ndarray is not C contiguous") + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":172 + * raise ValueError("ndarray is not C contiguous") * * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) # <<<<<<<<<<<<<< * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): - * raise ValueError(u"ndarray is not Fortran contiguous") + * raise ValueError("ndarray is not Fortran contiguous") */ if (((__pyx_v_flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS)) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":179 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":173 * * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): # <<<<<<<<<<<<<< - * raise ValueError(u"ndarray is not Fortran contiguous") + * raise ValueError("ndarray is not Fortran contiguous") * */ __pyx_t_1 = (!PyArray_CHKFLAGS(((PyArrayObject *)__pyx_v_self), NPY_F_CONTIGUOUS)); @@ -1989,30 +1998,30 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf } if (__pyx_t_1) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":180 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":174 * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): - * raise ValueError(u"ndarray is not Fortran contiguous") # <<<<<<<<<<<<<< + * raise ValueError("ndarray is not Fortran contiguous") # <<<<<<<<<<<<<< * * info.buf = PyArray_DATA(self) */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_3)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_u_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_3)); - __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_INCREF(__pyx_kp_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_2); + __Pyx_GIVEREF(__pyx_kp_2); + __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L7; } __pyx_L7:; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":182 - * raise ValueError(u"ndarray is not Fortran contiguous") + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":176 + * raise ValueError("ndarray is not Fortran contiguous") * * info.buf = PyArray_DATA(self) # <<<<<<<<<<<<<< * info.ndim = ndim @@ -2020,7 +2029,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_info->buf = PyArray_DATA(((PyArrayObject *)__pyx_v_self)); - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":183 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":177 * * info.buf = PyArray_DATA(self) * info.ndim = ndim # <<<<<<<<<<<<<< @@ -2029,7 +2038,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_info->ndim = __pyx_v_ndim; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":184 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":178 * info.buf = PyArray_DATA(self) * info.ndim = ndim * if copy_shape: # <<<<<<<<<<<<<< @@ -2039,7 +2048,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf __pyx_t_4 = __pyx_v_copy_shape; if (__pyx_t_4) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":187 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":181 * # Allocate new buffer for strides and shape info. This is allocated * # as one block, strides first. * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) # <<<<<<<<<<<<<< @@ -2048,7 +2057,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_info->strides = ((Py_ssize_t *)malloc((((sizeof(Py_ssize_t)) * __pyx_v_ndim) * 2))); - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":188 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":182 * # as one block, strides first. * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) * info.shape = info.strides + ndim # <<<<<<<<<<<<<< @@ -2057,18 +2066,17 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_info->shape = (__pyx_v_info->strides + __pyx_v_ndim); - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":189 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":183 * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) * info.shape = info.strides + ndim * for i in range(ndim): # <<<<<<<<<<<<<< * info.strides[i] = PyArray_STRIDES(self)[i] * info.shape[i] = PyArray_DIMS(self)[i] */ - __pyx_t_4 = __pyx_v_ndim; - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_v_i = __pyx_t_5; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_v_ndim; __pyx_t_4+=1) { + __pyx_v_i = __pyx_t_4; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":190 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":184 * info.shape = info.strides + ndim * for i in range(ndim): * info.strides[i] = PyArray_STRIDES(self)[i] # <<<<<<<<<<<<<< @@ -2077,7 +2085,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ (__pyx_v_info->strides[__pyx_v_i]) = (PyArray_STRIDES(((PyArrayObject *)__pyx_v_self))[__pyx_v_i]); - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":191 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":185 * for i in range(ndim): * info.strides[i] = PyArray_STRIDES(self)[i] * info.shape[i] = PyArray_DIMS(self)[i] # <<<<<<<<<<<<<< @@ -2090,7 +2098,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf } /*else*/ { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":193 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":187 * info.shape[i] = PyArray_DIMS(self)[i] * else: * info.strides = PyArray_STRIDES(self) # <<<<<<<<<<<<<< @@ -2099,7 +2107,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_info->strides = ((Py_ssize_t *)PyArray_STRIDES(((PyArrayObject *)__pyx_v_self))); - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":194 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":188 * else: * info.strides = PyArray_STRIDES(self) * info.shape = PyArray_DIMS(self) # <<<<<<<<<<<<<< @@ -2110,7 +2118,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf } __pyx_L8:; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":195 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":189 * info.strides = PyArray_STRIDES(self) * info.shape = PyArray_DIMS(self) * info.suboffsets = NULL # <<<<<<<<<<<<<< @@ -2119,7 +2127,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_info->suboffsets = NULL; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":196 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":190 * info.shape = PyArray_DIMS(self) * info.suboffsets = NULL * info.itemsize = PyArray_ITEMSIZE(self) # <<<<<<<<<<<<<< @@ -2128,7 +2136,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_info->itemsize = PyArray_ITEMSIZE(((PyArrayObject *)__pyx_v_self)); - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":197 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":191 * info.suboffsets = NULL * info.itemsize = PyArray_ITEMSIZE(self) * info.readonly = not PyArray_ISWRITEABLE(self) # <<<<<<<<<<<<<< @@ -2137,7 +2145,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_info->readonly = (!PyArray_ISWRITEABLE(((PyArrayObject *)__pyx_v_self))); - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":200 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":194 * * cdef int t * cdef char* f = NULL # <<<<<<<<<<<<<< @@ -2146,7 +2154,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_f = NULL; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":201 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":195 * cdef int t * cdef char* f = NULL * cdef dtype descr = self.descr # <<<<<<<<<<<<<< @@ -2156,7 +2164,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_v_self)->descr)); __pyx_v_descr = ((PyArrayObject *)__pyx_v_self)->descr; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":205 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":199 * cdef int offset * * cdef bint hasfields = PyDataType_HASFIELDS(descr) # <<<<<<<<<<<<<< @@ -2165,7 +2173,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_hasfields = PyDataType_HASFIELDS(__pyx_v_descr); - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":207 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":201 * cdef bint hasfields = PyDataType_HASFIELDS(descr) * * if not hasfields and not copy_shape: # <<<<<<<<<<<<<< @@ -2179,7 +2187,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf } if (__pyx_t_1) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":209 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":203 * if not hasfields and not copy_shape: * # do not call releasebuffer * info.obj = None # <<<<<<<<<<<<<< @@ -2195,7 +2203,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf } /*else*/ { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":212 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":206 * else: * # need to call releasebuffer * info.obj = self # <<<<<<<<<<<<<< @@ -2210,7 +2218,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf } __pyx_L11:; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":214 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":208 * info.obj = self * * if not hasfields: # <<<<<<<<<<<<<< @@ -2220,7 +2228,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf __pyx_t_1 = (!__pyx_v_hasfields); if (__pyx_t_1) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":215 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":209 * * if not hasfields: * t = descr.type_num # <<<<<<<<<<<<<< @@ -2229,335 +2237,319 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_t = __pyx_v_descr->type_num; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":216 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":210 * if not hasfields: * t = descr.type_num * if ((descr.byteorder == '>' and little_endian) or # <<<<<<<<<<<<<< * (descr.byteorder == '<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") + * raise ValueError("Non-native byte order not supported") */ - __pyx_t_2 = PyInt_FromLong(__pyx_v_descr->byteorder); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_kp_s_4), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_1) { - __pyx_t_6 = __pyx_v_little_endian; - __pyx_t_7 = __pyx_t_6; + if ((__pyx_v_descr->byteorder == '>')) { + __pyx_t_1 = __pyx_v_little_endian; } else { - __pyx_t_7 = __pyx_t_1; + __pyx_t_1 = (__pyx_v_descr->byteorder == '>'); } - if (!__pyx_t_7) { + if (!__pyx_t_1) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":217 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":211 * t = descr.type_num * if ((descr.byteorder == '>' and little_endian) or * (descr.byteorder == '<' and not little_endian)): # <<<<<<<<<<<<<< - * raise ValueError(u"Non-native byte order not supported") + * raise ValueError("Non-native byte order not supported") * if t == NPY_BYTE: f = "b" */ - __pyx_t_3 = PyInt_FromLong(__pyx_v_descr->byteorder); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, ((PyObject *)__pyx_kp_s_5), Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_1) { - __pyx_t_6 = (!__pyx_v_little_endian); - __pyx_t_8 = __pyx_t_6; + if ((__pyx_v_descr->byteorder == '<')) { + __pyx_t_5 = (!__pyx_v_little_endian); } else { - __pyx_t_8 = __pyx_t_1; + __pyx_t_5 = (__pyx_v_descr->byteorder == '<'); } - __pyx_t_1 = __pyx_t_8; + __pyx_t_6 = __pyx_t_5; } else { - __pyx_t_1 = __pyx_t_7; + __pyx_t_6 = __pyx_t_1; } - if (__pyx_t_1) { + if (__pyx_t_6) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":218 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":212 * if ((descr.byteorder == '>' and little_endian) or * (descr.byteorder == '<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< + * raise ValueError("Non-native byte order not supported") # <<<<<<<<<<<<<< * if t == NPY_BYTE: f = "b" * elif t == NPY_UBYTE: f = "B" */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_6)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_u_6)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_6)); - __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_INCREF(__pyx_kp_5); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_5); + __Pyx_GIVEREF(__pyx_kp_5); + __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L13; } __pyx_L13:; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":219 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":213 * (descr.byteorder == '<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") + * raise ValueError("Non-native byte order not supported") * if t == NPY_BYTE: f = "b" # <<<<<<<<<<<<<< * elif t == NPY_UBYTE: f = "B" * elif t == NPY_SHORT: f = "h" */ - __pyx_t_1 = (__pyx_v_t == NPY_BYTE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__b; + __pyx_t_6 = (__pyx_v_t == NPY_BYTE); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_6; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":220 - * raise ValueError(u"Non-native byte order not supported") + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":214 + * raise ValueError("Non-native byte order not supported") * if t == NPY_BYTE: f = "b" * elif t == NPY_UBYTE: f = "B" # <<<<<<<<<<<<<< * elif t == NPY_SHORT: f = "h" * elif t == NPY_USHORT: f = "H" */ - __pyx_t_1 = (__pyx_v_t == NPY_UBYTE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__B; + __pyx_t_6 = (__pyx_v_t == NPY_UBYTE); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_7; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":221 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":215 * if t == NPY_BYTE: f = "b" * elif t == NPY_UBYTE: f = "B" * elif t == NPY_SHORT: f = "h" # <<<<<<<<<<<<<< * elif t == NPY_USHORT: f = "H" * elif t == NPY_INT: f = "i" */ - __pyx_t_1 = (__pyx_v_t == NPY_SHORT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__h; + __pyx_t_6 = (__pyx_v_t == NPY_SHORT); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_8; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":222 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":216 * elif t == NPY_UBYTE: f = "B" * elif t == NPY_SHORT: f = "h" * elif t == NPY_USHORT: f = "H" # <<<<<<<<<<<<<< * elif t == NPY_INT: f = "i" * elif t == NPY_UINT: f = "I" */ - __pyx_t_1 = (__pyx_v_t == NPY_USHORT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__H; + __pyx_t_6 = (__pyx_v_t == NPY_USHORT); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_9; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":223 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":217 * elif t == NPY_SHORT: f = "h" * elif t == NPY_USHORT: f = "H" * elif t == NPY_INT: f = "i" # <<<<<<<<<<<<<< * elif t == NPY_UINT: f = "I" * elif t == NPY_LONG: f = "l" */ - __pyx_t_1 = (__pyx_v_t == NPY_INT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__i; + __pyx_t_6 = (__pyx_v_t == NPY_INT); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_10; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":224 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":218 * elif t == NPY_USHORT: f = "H" * elif t == NPY_INT: f = "i" * elif t == NPY_UINT: f = "I" # <<<<<<<<<<<<<< * elif t == NPY_LONG: f = "l" * elif t == NPY_ULONG: f = "L" */ - __pyx_t_1 = (__pyx_v_t == NPY_UINT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__I; + __pyx_t_6 = (__pyx_v_t == NPY_UINT); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_11; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":225 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":219 * elif t == NPY_INT: f = "i" * elif t == NPY_UINT: f = "I" * elif t == NPY_LONG: f = "l" # <<<<<<<<<<<<<< * elif t == NPY_ULONG: f = "L" * elif t == NPY_LONGLONG: f = "q" */ - __pyx_t_1 = (__pyx_v_t == NPY_LONG); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__l; + __pyx_t_6 = (__pyx_v_t == NPY_LONG); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_12; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":226 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":220 * elif t == NPY_UINT: f = "I" * elif t == NPY_LONG: f = "l" * elif t == NPY_ULONG: f = "L" # <<<<<<<<<<<<<< * elif t == NPY_LONGLONG: f = "q" * elif t == NPY_ULONGLONG: f = "Q" */ - __pyx_t_1 = (__pyx_v_t == NPY_ULONG); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__L; + __pyx_t_6 = (__pyx_v_t == NPY_ULONG); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_13; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":227 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":221 * elif t == NPY_LONG: f = "l" * elif t == NPY_ULONG: f = "L" * elif t == NPY_LONGLONG: f = "q" # <<<<<<<<<<<<<< * elif t == NPY_ULONGLONG: f = "Q" * elif t == NPY_FLOAT: f = "f" */ - __pyx_t_1 = (__pyx_v_t == NPY_LONGLONG); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__q; + __pyx_t_6 = (__pyx_v_t == NPY_LONGLONG); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_14; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":228 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":222 * elif t == NPY_ULONG: f = "L" * elif t == NPY_LONGLONG: f = "q" * elif t == NPY_ULONGLONG: f = "Q" # <<<<<<<<<<<<<< * elif t == NPY_FLOAT: f = "f" * elif t == NPY_DOUBLE: f = "d" */ - __pyx_t_1 = (__pyx_v_t == NPY_ULONGLONG); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__Q; + __pyx_t_6 = (__pyx_v_t == NPY_ULONGLONG); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_15; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":229 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":223 * elif t == NPY_LONGLONG: f = "q" * elif t == NPY_ULONGLONG: f = "Q" * elif t == NPY_FLOAT: f = "f" # <<<<<<<<<<<<<< * elif t == NPY_DOUBLE: f = "d" * elif t == NPY_LONGDOUBLE: f = "g" */ - __pyx_t_1 = (__pyx_v_t == NPY_FLOAT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__f; + __pyx_t_6 = (__pyx_v_t == NPY_FLOAT); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_16; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":230 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":224 * elif t == NPY_ULONGLONG: f = "Q" * elif t == NPY_FLOAT: f = "f" * elif t == NPY_DOUBLE: f = "d" # <<<<<<<<<<<<<< * elif t == NPY_LONGDOUBLE: f = "g" * elif t == NPY_CFLOAT: f = "Zf" */ - __pyx_t_1 = (__pyx_v_t == NPY_DOUBLE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__d; + __pyx_t_6 = (__pyx_v_t == NPY_DOUBLE); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_17; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":231 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":225 * elif t == NPY_FLOAT: f = "f" * elif t == NPY_DOUBLE: f = "d" * elif t == NPY_LONGDOUBLE: f = "g" # <<<<<<<<<<<<<< * elif t == NPY_CFLOAT: f = "Zf" * elif t == NPY_CDOUBLE: f = "Zd" */ - __pyx_t_1 = (__pyx_v_t == NPY_LONGDOUBLE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__g; + __pyx_t_6 = (__pyx_v_t == NPY_LONGDOUBLE); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_18; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":232 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":226 * elif t == NPY_DOUBLE: f = "d" * elif t == NPY_LONGDOUBLE: f = "g" * elif t == NPY_CFLOAT: f = "Zf" # <<<<<<<<<<<<<< * elif t == NPY_CDOUBLE: f = "Zd" * elif t == NPY_CLONGDOUBLE: f = "Zg" */ - __pyx_t_1 = (__pyx_v_t == NPY_CFLOAT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__Zf; + __pyx_t_6 = (__pyx_v_t == NPY_CFLOAT); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_19; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":233 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":227 * elif t == NPY_LONGDOUBLE: f = "g" * elif t == NPY_CFLOAT: f = "Zf" * elif t == NPY_CDOUBLE: f = "Zd" # <<<<<<<<<<<<<< * elif t == NPY_CLONGDOUBLE: f = "Zg" * elif t == NPY_OBJECT: f = "O" */ - __pyx_t_1 = (__pyx_v_t == NPY_CDOUBLE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__Zd; + __pyx_t_6 = (__pyx_v_t == NPY_CDOUBLE); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_20; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":234 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":228 * elif t == NPY_CFLOAT: f = "Zf" * elif t == NPY_CDOUBLE: f = "Zd" * elif t == NPY_CLONGDOUBLE: f = "Zg" # <<<<<<<<<<<<<< * elif t == NPY_OBJECT: f = "O" * else: */ - __pyx_t_1 = (__pyx_v_t == NPY_CLONGDOUBLE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__Zg; + __pyx_t_6 = (__pyx_v_t == NPY_CLONGDOUBLE); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_21; goto __pyx_L14; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":235 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":229 * elif t == NPY_CDOUBLE: f = "Zd" * elif t == NPY_CLONGDOUBLE: f = "Zg" * elif t == NPY_OBJECT: f = "O" # <<<<<<<<<<<<<< * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) + * raise ValueError("unknown dtype code in numpy.pxd (%d)" % t) */ - __pyx_t_1 = (__pyx_v_t == NPY_OBJECT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__O; + __pyx_t_6 = (__pyx_v_t == NPY_OBJECT); + if (__pyx_t_6) { + __pyx_v_f = __pyx_k_22; goto __pyx_L14; } /*else*/ { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":237 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":231 * elif t == NPY_OBJECT: f = "O" * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) # <<<<<<<<<<<<<< + * raise ValueError("unknown dtype code in numpy.pxd (%d)" % t) # <<<<<<<<<<<<<< * info.format = f * return */ - __pyx_t_3 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_7), __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyNumber_Remainder(__pyx_kp_23, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L14:; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":238 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":232 * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) + * raise ValueError("unknown dtype code in numpy.pxd (%d)" % t) * info.format = f # <<<<<<<<<<<<<< * return * else: */ __pyx_v_info->format = __pyx_v_f; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":239 - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":233 + * raise ValueError("unknown dtype code in numpy.pxd (%d)" % t) * info.format = f * return # <<<<<<<<<<<<<< * else: @@ -2569,7 +2561,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf } /*else*/ { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":241 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":235 * return * else: * info.format = stdlib.malloc(_buffer_format_string_len) # <<<<<<<<<<<<<< @@ -2578,7 +2570,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_info->format = ((char *)malloc(255)); - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":242 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":236 * else: * info.format = stdlib.malloc(_buffer_format_string_len) * info.format[0] = '^' # Native data types, manual alignment # <<<<<<<<<<<<<< @@ -2587,7 +2579,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ (__pyx_v_info->format[0]) = '^'; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":243 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":237 * info.format = stdlib.malloc(_buffer_format_string_len) * info.format[0] = '^' # Native data types, manual alignment * offset = 0 # <<<<<<<<<<<<<< @@ -2596,17 +2588,17 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf */ __pyx_v_offset = 0; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":246 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":240 * f = _util_dtypestring(descr, info.format + 1, * info.format + _buffer_format_string_len, * &offset) # <<<<<<<<<<<<<< * f[0] = 0 # Terminate format string * */ - __pyx_t_9 = __pyx_f_5numpy__util_dtypestring(__pyx_v_descr, (__pyx_v_info->format + 1), (__pyx_v_info->format + 255), (&__pyx_v_offset)); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_f = __pyx_t_9; + __pyx_t_7 = __pyx_f_5numpy__util_dtypestring(__pyx_v_descr, (__pyx_v_info->format + 1), (__pyx_v_info->format + 255), (&__pyx_v_offset)); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_f = __pyx_t_7; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":247 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":241 * info.format + _buffer_format_string_len, * &offset) * f[0] = 0 # Terminate format string # <<<<<<<<<<<<<< @@ -2634,12 +2626,11 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buf } __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_descr); - __Pyx_DECREF((PyObject *)__pyx_v_self); __Pyx_FinishRefcountContext(); return __pyx_r; } -/* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":249 +/* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":243 * f[0] = 0 # Terminate format string * * def __releasebuffer__(ndarray self, Py_buffer* info): # <<<<<<<<<<<<<< @@ -2651,9 +2642,8 @@ static void __pyx_pf_5numpy_7ndarray___releasebuffer__(PyObject *__pyx_v_self, P static void __pyx_pf_5numpy_7ndarray___releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) { int __pyx_t_1; __Pyx_SetupRefcountContext("__releasebuffer__"); - __Pyx_INCREF((PyObject *)__pyx_v_self); - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":250 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":244 * * def __releasebuffer__(ndarray self, Py_buffer* info): * if PyArray_HASFIELDS(self): # <<<<<<<<<<<<<< @@ -2663,7 +2653,7 @@ static void __pyx_pf_5numpy_7ndarray___releasebuffer__(PyObject *__pyx_v_self, P __pyx_t_1 = PyArray_HASFIELDS(((PyArrayObject *)__pyx_v_self)); if (__pyx_t_1) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":251 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":245 * def __releasebuffer__(ndarray self, Py_buffer* info): * if PyArray_HASFIELDS(self): * stdlib.free(info.format) # <<<<<<<<<<<<<< @@ -2675,7 +2665,7 @@ static void __pyx_pf_5numpy_7ndarray___releasebuffer__(PyObject *__pyx_v_self, P } __pyx_L5:; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":252 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":246 * if PyArray_HASFIELDS(self): * stdlib.free(info.format) * if sizeof(npy_intp) != sizeof(Py_ssize_t): # <<<<<<<<<<<<<< @@ -2685,7 +2675,7 @@ static void __pyx_pf_5numpy_7ndarray___releasebuffer__(PyObject *__pyx_v_self, P __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t))); if (__pyx_t_1) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":253 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":247 * stdlib.free(info.format) * if sizeof(npy_intp) != sizeof(Py_ssize_t): * stdlib.free(info.strides) # <<<<<<<<<<<<<< @@ -2697,208 +2687,12 @@ static void __pyx_pf_5numpy_7ndarray___releasebuffer__(PyObject *__pyx_v_self, P } __pyx_L6:; - __Pyx_DECREF((PyObject *)__pyx_v_self); __Pyx_FinishRefcountContext(); } -/* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":704 +/* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":690 * ctypedef npy_cdouble complex_t * - * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(1, a) - * - */ - -static INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__pyx_v_a) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_SetupRefcountContext("PyArray_MultiIterNew1"); - - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":705 - * - * cdef inline object PyArray_MultiIterNew1(a): - * return PyArray_MultiIterNew(1, a) # <<<<<<<<<<<<<< - * - * cdef inline object PyArray_MultiIterNew2(a, b): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("numpy.PyArray_MultiIterNew1"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":707 - * return PyArray_MultiIterNew(1, a) - * - * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(2, a, b) - * - */ - -static INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__pyx_v_a, PyObject *__pyx_v_b) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_SetupRefcountContext("PyArray_MultiIterNew2"); - - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":708 - * - * cdef inline object PyArray_MultiIterNew2(a, b): - * return PyArray_MultiIterNew(2, a, b) # <<<<<<<<<<<<<< - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(2, ((void *)__pyx_v_a), ((void *)__pyx_v_b)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("numpy.PyArray_MultiIterNew2"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":710 - * return PyArray_MultiIterNew(2, a, b) - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(3, a, b, c) - * - */ - -static INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_SetupRefcountContext("PyArray_MultiIterNew3"); - - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":711 - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): - * return PyArray_MultiIterNew(3, a, b, c) # <<<<<<<<<<<<<< - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(3, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 711; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("numpy.PyArray_MultiIterNew3"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":713 - * return PyArray_MultiIterNew(3, a, b, c) - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(4, a, b, c, d) - * - */ - -static INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_SetupRefcountContext("PyArray_MultiIterNew4"); - - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":714 - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): - * return PyArray_MultiIterNew(4, a, b, c, d) # <<<<<<<<<<<<<< - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(4, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("numpy.PyArray_MultiIterNew4"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":716 - * return PyArray_MultiIterNew(4, a, b, c, d) - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(5, a, b, c, d, e) - * - */ - -static INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d, PyObject *__pyx_v_e) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_SetupRefcountContext("PyArray_MultiIterNew5"); - - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":717 - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): - * return PyArray_MultiIterNew(5, a, b, c, d, e) # <<<<<<<<<<<<<< - * - * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL: - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(5, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d), ((void *)__pyx_v_e)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 717; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("numpy.PyArray_MultiIterNew5"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":719 - * return PyArray_MultiIterNew(5, a, b, c, d, e) - * * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL: # <<<<<<<<<<<<<< * # Recursive utility function used in __getbuffer__ to get format * # string. The new location in the format string is returned. @@ -2913,6 +2707,9 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc PyObject *__pyx_v_new_offset; PyObject *__pyx_v_t; char *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_3 = 0; Py_ssize_t __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; @@ -2921,17 +2718,15 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc int __pyx_t_6; int __pyx_t_7; int __pyx_t_8; - int __pyx_t_9; - char *__pyx_t_10; + char *__pyx_t_9; __Pyx_SetupRefcountContext("_util_dtypestring"); - __Pyx_INCREF((PyObject *)__pyx_v_descr); __pyx_v_child = ((PyArray_Descr *)Py_None); __Pyx_INCREF(Py_None); __pyx_v_fields = ((PyObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_v_childname = Py_None; __Pyx_INCREF(Py_None); __pyx_v_new_offset = Py_None; __Pyx_INCREF(Py_None); __pyx_v_t = Py_None; __Pyx_INCREF(Py_None); - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":726 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":697 * cdef int delta_offset * cdef tuple i * cdef int endian_detector = 1 # <<<<<<<<<<<<<< @@ -2940,7 +2735,7 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc */ __pyx_v_endian_detector = 1; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":727 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":698 * cdef tuple i * cdef int endian_detector = 1 * cdef bint little_endian = ((&endian_detector)[0] != 0) # <<<<<<<<<<<<<< @@ -2949,7 +2744,7 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc */ __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0); - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":730 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":701 * cdef tuple fields * * for childname in descr.names: # <<<<<<<<<<<<<< @@ -2959,7 +2754,7 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc if (likely(((PyObject *)__pyx_v_descr->names) != Py_None)) { __pyx_t_1 = 0; __pyx_t_2 = ((PyObject *)__pyx_v_descr->names); __Pyx_INCREF(__pyx_t_2); } else { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 730; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } for (;;) { if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_2)) break; @@ -2968,21 +2763,21 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc __pyx_v_childname = __pyx_t_3; __pyx_t_3 = 0; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":731 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":702 * * for childname in descr.names: * fields = descr.fields[childname] # <<<<<<<<<<<<<< * child, new_offset = fields * */ - __pyx_t_3 = PyObject_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (!__pyx_t_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (!(likely(PyTuple_CheckExact(__pyx_t_3)) || (__pyx_t_3) == Py_None || (PyErr_Format(PyExc_TypeError, "Expected tuple, got %s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_1 = PyObject_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (!__pyx_1) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_1); + if (!(likely(PyTuple_CheckExact(__pyx_1)) || (__pyx_1) == Py_None || (PyErr_Format(PyExc_TypeError, "Expected tuple, got %s", Py_TYPE(__pyx_1)->tp_name), 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_v_fields)); - __pyx_v_fields = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 0; + __pyx_v_fields = ((PyObject *)__pyx_1); + __pyx_1 = 0; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":732 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":703 * for childname in descr.names: * fields = descr.fields[childname] * child, new_offset = fields # <<<<<<<<<<<<<< @@ -2991,138 +2786,122 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc */ if (likely(((PyObject *)__pyx_v_fields) != Py_None) && likely(PyTuple_GET_SIZE(((PyObject *)__pyx_v_fields)) == 2)) { PyObject* tuple = ((PyObject *)__pyx_v_fields); - __pyx_t_3 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_3); - if (!(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_dtype))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_4); + __pyx_2 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_2); + if (!(__Pyx_TypeTest(__pyx_2, __pyx_ptype_5numpy_dtype))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_3); __Pyx_DECREF(((PyObject *)__pyx_v_child)); - __pyx_v_child = ((PyArray_Descr *)__pyx_t_3); - __pyx_t_3 = 0; + __pyx_v_child = ((PyArray_Descr *)__pyx_2); + __pyx_2 = 0; __Pyx_DECREF(__pyx_v_new_offset); - __pyx_v_new_offset = __pyx_t_4; - __pyx_t_4 = 0; + __pyx_v_new_offset = __pyx_3; + __pyx_3 = 0; } else { __Pyx_UnpackTupleError(((PyObject *)__pyx_v_fields), 2); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":734 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":705 * child, new_offset = fields * * if (end - f) - (new_offset - offset[0]) < 15: # <<<<<<<<<<<<<< - * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") + * raise RuntimeError("Format string allocated too short, see comment in numpy.pxd") * */ - __pyx_t_4 = PyInt_FromLong((__pyx_v_end - __pyx_v_f)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong((__pyx_v_end - __pyx_v_f)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Subtract(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_int_15, Py_LT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyNumber_Subtract(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_int_15, Py_LT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_6) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":735 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":706 * * if (end - f) - (new_offset - offset[0]) < 15: - * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") # <<<<<<<<<<<<<< + * raise RuntimeError("Format string allocated too short, see comment in numpy.pxd") # <<<<<<<<<<<<<< * * if ((child.byteorder == '>' and little_endian) or */ - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 735; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_8)); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_u_8)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_8)); - __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 735; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 735; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __Pyx_INCREF(__pyx_kp_25); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_kp_25); + __Pyx_GIVEREF(__pyx_kp_25); + __pyx_t_4 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L5; } __pyx_L5:; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":737 - * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":708 + * raise RuntimeError("Format string allocated too short, see comment in numpy.pxd") * * if ((child.byteorder == '>' and little_endian) or # <<<<<<<<<<<<<< * (child.byteorder == '<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") + * raise ValueError("Non-native byte order not supported") */ - __pyx_t_3 = PyInt_FromLong(__pyx_v_child->byteorder); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 737; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, ((PyObject *)__pyx_kp_s_4), Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 737; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 737; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { - __pyx_t_7 = __pyx_v_little_endian; + if ((__pyx_v_child->byteorder == '>')) { + __pyx_t_6 = __pyx_v_little_endian; + } else { + __pyx_t_6 = (__pyx_v_child->byteorder == '>'); + } + if (!__pyx_t_6) { + + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":709 + * + * if ((child.byteorder == '>' and little_endian) or + * (child.byteorder == '<' and not little_endian)): # <<<<<<<<<<<<<< + * raise ValueError("Non-native byte order not supported") + * # One could encode it in the format string and have Cython + */ + if ((__pyx_v_child->byteorder == '<')) { + __pyx_t_7 = (!__pyx_v_little_endian); + } else { + __pyx_t_7 = (__pyx_v_child->byteorder == '<'); + } __pyx_t_8 = __pyx_t_7; } else { __pyx_t_8 = __pyx_t_6; } - if (!__pyx_t_8) { + if (__pyx_t_8) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":738 - * - * if ((child.byteorder == '>' and little_endian) or - * (child.byteorder == '<' and not little_endian)): # <<<<<<<<<<<<<< - * raise ValueError(u"Non-native byte order not supported") - * # One could encode it in the format string and have Cython - */ - __pyx_t_5 = PyInt_FromLong(__pyx_v_child->byteorder); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, ((PyObject *)__pyx_kp_s_5), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { - __pyx_t_7 = (!__pyx_v_little_endian); - __pyx_t_9 = __pyx_t_7; - } else { - __pyx_t_9 = __pyx_t_6; - } - __pyx_t_6 = __pyx_t_9; - } else { - __pyx_t_6 = __pyx_t_8; - } - if (__pyx_t_6) { - - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":739 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":710 * if ((child.byteorder == '>' and little_endian) or * (child.byteorder == '<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< + * raise ValueError("Non-native byte order not supported") # <<<<<<<<<<<<<< * # One could encode it in the format string and have Cython * # complain instead, BUT: < and > in format strings also imply */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_6)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_u_6)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_6)); - __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_INCREF(__pyx_kp_28); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_28); + __Pyx_GIVEREF(__pyx_kp_28); + __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_5, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L6; } __pyx_L6:; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":749 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":720 * * # Output padding bytes * while offset[0] < new_offset: # <<<<<<<<<<<<<< @@ -3130,16 +2909,16 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc * f += 1 */ while (1) { - __pyx_t_5 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 720; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_v_new_offset, Py_LT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_v_new_offset, Py_LT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 720; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!__pyx_t_6) break; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 720; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!__pyx_t_8) break; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":750 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":721 * # Output padding bytes * while offset[0] < new_offset: * f[0] = 120 # "x"; pad byte # <<<<<<<<<<<<<< @@ -3148,7 +2927,7 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc */ (__pyx_v_f[0]) = 120; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":751 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":722 * while offset[0] < new_offset: * f[0] = 120 # "x"; pad byte * f += 1 # <<<<<<<<<<<<<< @@ -3157,7 +2936,7 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc */ __pyx_v_f += 1; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":752 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":723 * f[0] = 120 # "x"; pad byte * f += 1 * offset[0] += 1 # <<<<<<<<<<<<<< @@ -3167,7 +2946,7 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc (__pyx_v_offset[0]) += 1; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":754 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":725 * offset[0] += 1 * * offset[0] += child.itemsize # <<<<<<<<<<<<<< @@ -3176,417 +2955,417 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc */ (__pyx_v_offset[0]) += __pyx_v_child->elsize; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":756 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":727 * offset[0] += child.itemsize * * if not PyDataType_HASFIELDS(child): # <<<<<<<<<<<<<< * t = child.type_num * if end - f < 5: */ - __pyx_t_6 = (!PyDataType_HASFIELDS(__pyx_v_child)); - if (__pyx_t_6) { + __pyx_t_8 = (!PyDataType_HASFIELDS(__pyx_v_child)); + if (__pyx_t_8) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":757 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":728 * * if not PyDataType_HASFIELDS(child): * t = child.type_num # <<<<<<<<<<<<<< * if end - f < 5: - * raise RuntimeError(u"Format string allocated too short.") + * raise RuntimeError("Format string allocated too short.") */ - __pyx_t_3 = PyInt_FromLong(__pyx_v_child->type_num); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 757; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyInt_FromLong(__pyx_v_child->type_num); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_v_t); - __pyx_v_t = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_v_t = __pyx_t_4; + __pyx_t_4 = 0; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":758 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":729 * if not PyDataType_HASFIELDS(child): * t = child.type_num * if end - f < 5: # <<<<<<<<<<<<<< - * raise RuntimeError(u"Format string allocated too short.") + * raise RuntimeError("Format string allocated too short.") * */ - __pyx_t_6 = ((__pyx_v_end - __pyx_v_f) < 5); - if (__pyx_t_6) { + __pyx_t_8 = ((__pyx_v_end - __pyx_v_f) < 5); + if (__pyx_t_8) { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":759 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":730 * t = child.type_num * if end - f < 5: - * raise RuntimeError(u"Format string allocated too short.") # <<<<<<<<<<<<<< + * raise RuntimeError("Format string allocated too short.") # <<<<<<<<<<<<<< * * # Until ticket #99 is fixed, use integers to avoid warnings */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 759; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_9)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_u_9)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_9)); - __pyx_t_5 = PyObject_Call(__pyx_builtin_RuntimeError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 759; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 730; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_INCREF(__pyx_kp_29); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_29); + __Pyx_GIVEREF(__pyx_kp_29); + __pyx_t_5 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 730; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_5, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 759; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 730; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L10; } __pyx_L10:; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":762 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":733 * * # Until ticket #99 is fixed, use integers to avoid warnings * if t == NPY_BYTE: f[0] = 98 #"b" # <<<<<<<<<<<<<< * elif t == NPY_UBYTE: f[0] = 66 #"B" * elif t == NPY_SHORT: f[0] = 104 #"h" */ - __pyx_t_5 = PyInt_FromLong(NPY_BYTE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyInt_FromLong(NPY_BYTE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_8) { (__pyx_v_f[0]) = 98; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":763 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":734 * # Until ticket #99 is fixed, use integers to avoid warnings * if t == NPY_BYTE: f[0] = 98 #"b" * elif t == NPY_UBYTE: f[0] = 66 #"B" # <<<<<<<<<<<<<< * elif t == NPY_SHORT: f[0] = 104 #"h" * elif t == NPY_USHORT: f[0] = 72 #"H" */ - __pyx_t_3 = PyInt_FromLong(NPY_UBYTE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_UBYTE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { + if (__pyx_t_8) { (__pyx_v_f[0]) = 66; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":764 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":735 * if t == NPY_BYTE: f[0] = 98 #"b" * elif t == NPY_UBYTE: f[0] = 66 #"B" * elif t == NPY_SHORT: f[0] = 104 #"h" # <<<<<<<<<<<<<< * elif t == NPY_USHORT: f[0] = 72 #"H" * elif t == NPY_INT: f[0] = 105 #"i" */ - __pyx_t_5 = PyInt_FromLong(NPY_SHORT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 764; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyInt_FromLong(NPY_SHORT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 735; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 764; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 735; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 764; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 735; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_8) { (__pyx_v_f[0]) = 104; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":765 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":736 * elif t == NPY_UBYTE: f[0] = 66 #"B" * elif t == NPY_SHORT: f[0] = 104 #"h" * elif t == NPY_USHORT: f[0] = 72 #"H" # <<<<<<<<<<<<<< * elif t == NPY_INT: f[0] = 105 #"i" * elif t == NPY_UINT: f[0] = 73 #"I" */ - __pyx_t_3 = PyInt_FromLong(NPY_USHORT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_USHORT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { + if (__pyx_t_8) { (__pyx_v_f[0]) = 72; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":766 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":737 * elif t == NPY_SHORT: f[0] = 104 #"h" * elif t == NPY_USHORT: f[0] = 72 #"H" * elif t == NPY_INT: f[0] = 105 #"i" # <<<<<<<<<<<<<< * elif t == NPY_UINT: f[0] = 73 #"I" * elif t == NPY_LONG: f[0] = 108 #"l" */ - __pyx_t_5 = PyInt_FromLong(NPY_INT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyInt_FromLong(NPY_INT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 737; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 737; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 737; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_8) { (__pyx_v_f[0]) = 105; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":767 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":738 * elif t == NPY_USHORT: f[0] = 72 #"H" * elif t == NPY_INT: f[0] = 105 #"i" * elif t == NPY_UINT: f[0] = 73 #"I" # <<<<<<<<<<<<<< * elif t == NPY_LONG: f[0] = 108 #"l" * elif t == NPY_ULONG: f[0] = 76 #"L" */ - __pyx_t_3 = PyInt_FromLong(NPY_UINT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_UINT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { + if (__pyx_t_8) { (__pyx_v_f[0]) = 73; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":768 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":739 * elif t == NPY_INT: f[0] = 105 #"i" * elif t == NPY_UINT: f[0] = 73 #"I" * elif t == NPY_LONG: f[0] = 108 #"l" # <<<<<<<<<<<<<< * elif t == NPY_ULONG: f[0] = 76 #"L" * elif t == NPY_LONGLONG: f[0] = 113 #"q" */ - __pyx_t_5 = PyInt_FromLong(NPY_LONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyInt_FromLong(NPY_LONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_8) { (__pyx_v_f[0]) = 108; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":769 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":740 * elif t == NPY_UINT: f[0] = 73 #"I" * elif t == NPY_LONG: f[0] = 108 #"l" * elif t == NPY_ULONG: f[0] = 76 #"L" # <<<<<<<<<<<<<< * elif t == NPY_LONGLONG: f[0] = 113 #"q" * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" */ - __pyx_t_3 = PyInt_FromLong(NPY_ULONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_ULONG); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { + if (__pyx_t_8) { (__pyx_v_f[0]) = 76; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":770 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":741 * elif t == NPY_LONG: f[0] = 108 #"l" * elif t == NPY_ULONG: f[0] = 76 #"L" * elif t == NPY_LONGLONG: f[0] = 113 #"q" # <<<<<<<<<<<<<< * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" * elif t == NPY_FLOAT: f[0] = 102 #"f" */ - __pyx_t_5 = PyInt_FromLong(NPY_LONGLONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 770; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyInt_FromLong(NPY_LONGLONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 741; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 770; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 741; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 770; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 741; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_8) { (__pyx_v_f[0]) = 113; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":771 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":742 * elif t == NPY_ULONG: f[0] = 76 #"L" * elif t == NPY_LONGLONG: f[0] = 113 #"q" * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" # <<<<<<<<<<<<<< * elif t == NPY_FLOAT: f[0] = 102 #"f" * elif t == NPY_DOUBLE: f[0] = 100 #"d" */ - __pyx_t_3 = PyInt_FromLong(NPY_ULONGLONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_ULONGLONG); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 742; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 742; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 742; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { + if (__pyx_t_8) { (__pyx_v_f[0]) = 81; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":772 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":743 * elif t == NPY_LONGLONG: f[0] = 113 #"q" * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" * elif t == NPY_FLOAT: f[0] = 102 #"f" # <<<<<<<<<<<<<< * elif t == NPY_DOUBLE: f[0] = 100 #"d" * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" */ - __pyx_t_5 = PyInt_FromLong(NPY_FLOAT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyInt_FromLong(NPY_FLOAT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_8) { (__pyx_v_f[0]) = 102; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":773 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":744 * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" * elif t == NPY_FLOAT: f[0] = 102 #"f" * elif t == NPY_DOUBLE: f[0] = 100 #"d" # <<<<<<<<<<<<<< * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf */ - __pyx_t_3 = PyInt_FromLong(NPY_DOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_DOUBLE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { + if (__pyx_t_8) { (__pyx_v_f[0]) = 100; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":774 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":745 * elif t == NPY_FLOAT: f[0] = 102 #"f" * elif t == NPY_DOUBLE: f[0] = 100 #"d" * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" # <<<<<<<<<<<<<< * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd */ - __pyx_t_5 = PyInt_FromLong(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyInt_FromLong(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 745; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 745; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 745; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_8) { (__pyx_v_f[0]) = 103; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":775 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":746 * elif t == NPY_DOUBLE: f[0] = 100 #"d" * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf # <<<<<<<<<<<<<< * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg */ - __pyx_t_3 = PyInt_FromLong(NPY_CFLOAT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_CFLOAT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { + if (__pyx_t_8) { (__pyx_v_f[0]) = 90; (__pyx_v_f[1]) = 102; __pyx_v_f += 1; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":776 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":747 * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd # <<<<<<<<<<<<<< * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg * elif t == NPY_OBJECT: f[0] = 79 #"O" */ - __pyx_t_5 = PyInt_FromLong(NPY_CDOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyInt_FromLong(NPY_CDOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_8) { (__pyx_v_f[0]) = 90; (__pyx_v_f[1]) = 100; __pyx_v_f += 1; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":777 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":748 * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg # <<<<<<<<<<<<<< * elif t == NPY_OBJECT: f[0] = 79 #"O" * else: */ - __pyx_t_3 = PyInt_FromLong(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { + if (__pyx_t_8) { (__pyx_v_f[0]) = 90; (__pyx_v_f[1]) = 103; __pyx_v_f += 1; goto __pyx_L11; } - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":778 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":749 * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg * elif t == NPY_OBJECT: f[0] = 79 #"O" # <<<<<<<<<<<<<< * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) + * raise ValueError("unknown dtype code in numpy.pxd (%d)" % t) */ - __pyx_t_5 = PyInt_FromLong(NPY_OBJECT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyInt_FromLong(NPY_OBJECT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_8) { (__pyx_v_f[0]) = 79; goto __pyx_L11; } /*else*/ { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":780 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":751 * elif t == NPY_OBJECT: f[0] = 79 #"O" * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) # <<<<<<<<<<<<<< + * raise ValueError("unknown dtype code in numpy.pxd (%d)" % t) # <<<<<<<<<<<<<< * f += 1 * else: */ - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_7), __pyx_v_t); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyNumber_Remainder(__pyx_kp_30, __pyx_v_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L11:; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":781 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":752 * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) + * raise ValueError("unknown dtype code in numpy.pxd (%d)" % t) * f += 1 # <<<<<<<<<<<<<< * else: * # Cython ignores struct boundary information ("T{...}"), @@ -3596,26 +3375,25 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc } /*else*/ { - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":785 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":756 * # Cython ignores struct boundary information ("T{...}"), * # so don't output it * f = _util_dtypestring(child, f, end, offset) # <<<<<<<<<<<<<< * return f * */ - __pyx_t_10 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_10 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 785; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_f = __pyx_t_10; + __pyx_t_9 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 756; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_f = __pyx_t_9; } __pyx_L9:; } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":786 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/numpy.pxd":757 * # so don't output it * f = _util_dtypestring(child, f, end, offset) * return f # <<<<<<<<<<<<<< * - * */ __pyx_r = __pyx_v_f; goto __pyx_L0; @@ -3623,6 +3401,9 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_1); + __Pyx_XDECREF(__pyx_2); + __Pyx_XDECREF(__pyx_3); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); @@ -3635,7 +3416,6 @@ static INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_desc __Pyx_DECREF(__pyx_v_childname); __Pyx_DECREF(__pyx_v_new_offset); __Pyx_DECREF(__pyx_v_t); - __Pyx_DECREF((PyObject *)__pyx_v_descr); __Pyx_FinishRefcountContext(); return __pyx_r; } @@ -3662,61 +3442,50 @@ static struct PyModuleDef __pyx_moduledef = { #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, - {&__pyx_kp_u_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 1, 0, 0}, - {&__pyx_kp_u_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 1, 0, 0}, - {&__pyx_kp_u_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 1, 0, 0}, - {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0}, - {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0}, - {&__pyx_kp_u_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 1, 0, 0}, - {&__pyx_kp_u_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 1, 0, 0}, - {&__pyx_kp_u_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 1, 0, 0}, - {&__pyx_kp_u_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 1, 0, 0}, - {&__pyx_n_s__RuntimeError, __pyx_k__RuntimeError, sizeof(__pyx_k__RuntimeError), 0, 0, 1, 1}, - {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, - {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, - {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, - {&__pyx_n_s__argmin, __pyx_k__argmin, sizeof(__pyx_k__argmin), 0, 0, 1, 1}, - {&__pyx_n_s__arr, __pyx_k__arr, sizeof(__pyx_k__arr), 0, 0, 1, 1}, - {&__pyx_n_s__ascontiguousarray, __pyx_k__ascontiguousarray, sizeof(__pyx_k__ascontiguousarray), 0, 0, 1, 1}, - {&__pyx_n_s__buf, __pyx_k__buf, sizeof(__pyx_k__buf), 0, 0, 1, 1}, - {&__pyx_n_s__byteorder, __pyx_k__byteorder, sizeof(__pyx_k__byteorder), 0, 0, 1, 1}, - {&__pyx_n_s__descr, __pyx_k__descr, sizeof(__pyx_k__descr), 0, 0, 1, 1}, - {&__pyx_n_s__double, __pyx_k__double, sizeof(__pyx_k__double), 0, 0, 1, 1}, - {&__pyx_n_s__dtype, __pyx_k__dtype, sizeof(__pyx_k__dtype), 0, 0, 1, 1}, - {&__pyx_n_s__empty, __pyx_k__empty, sizeof(__pyx_k__empty), 0, 0, 1, 1}, - {&__pyx_n_s__fields, __pyx_k__fields, sizeof(__pyx_k__fields), 0, 0, 1, 1}, - {&__pyx_n_s__format, __pyx_k__format, sizeof(__pyx_k__format), 0, 0, 1, 1}, - {&__pyx_n_s__itemsize, __pyx_k__itemsize, sizeof(__pyx_k__itemsize), 0, 0, 1, 1}, - {&__pyx_n_s__names, __pyx_k__names, sizeof(__pyx_k__names), 0, 0, 1, 1}, - {&__pyx_n_s__ndim, __pyx_k__ndim, sizeof(__pyx_k__ndim), 0, 0, 1, 1}, - {&__pyx_n_s__np, __pyx_k__np, sizeof(__pyx_k__np), 0, 0, 1, 1}, - {&__pyx_n_s__numpy, __pyx_k__numpy, sizeof(__pyx_k__numpy), 0, 0, 1, 1}, - {&__pyx_n_s__obj, __pyx_k__obj, sizeof(__pyx_k__obj), 0, 0, 1, 1}, - {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, - {&__pyx_n_s__reach, __pyx_k__reach, sizeof(__pyx_k__reach), 0, 0, 1, 1}, - {&__pyx_n_s__readonly, __pyx_k__readonly, sizeof(__pyx_k__readonly), 0, 0, 1, 1}, - {&__pyx_n_s__shape, __pyx_k__shape, sizeof(__pyx_k__shape), 0, 0, 1, 1}, - {&__pyx_n_s__shortest_path, __pyx_k__shortest_path, sizeof(__pyx_k__shortest_path), 0, 0, 1, 1}, - {&__pyx_n_s__strides, __pyx_k__strides, sizeof(__pyx_k__strides), 0, 0, 1, 1}, - {&__pyx_n_s__suboffsets, __pyx_k__suboffsets, sizeof(__pyx_k__suboffsets), 0, 0, 1, 1}, - {&__pyx_n_s__type_num, __pyx_k__type_num, sizeof(__pyx_k__type_num), 0, 0, 1, 1}, - {0, 0, 0, 0, 0, 0, 0} + {&__pyx_kp___main__, __pyx_k___main__, sizeof(__pyx_k___main__), 1, 1, 1}, + {&__pyx_kp_shortest_path, __pyx_k_shortest_path, sizeof(__pyx_k_shortest_path), 1, 1, 1}, + {&__pyx_kp_arr, __pyx_k_arr, sizeof(__pyx_k_arr), 1, 1, 1}, + {&__pyx_kp_reach, __pyx_k_reach, sizeof(__pyx_k_reach), 1, 1, 1}, + {&__pyx_kp_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 1, 1, 1}, + {&__pyx_kp_np, __pyx_k_np, sizeof(__pyx_k_np), 0, 1, 1}, + {&__pyx_kp_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 1, 1, 1}, + {&__pyx_kp_ascontiguousarray, __pyx_k_ascontiguousarray, sizeof(__pyx_k_ascontiguousarray), 1, 1, 1}, + {&__pyx_kp_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 1, 1, 1}, + {&__pyx_kp_double, __pyx_k_double, sizeof(__pyx_k_double), 1, 1, 1}, + {&__pyx_kp_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 1, 1, 1}, + {&__pyx_kp_range, __pyx_k_range, sizeof(__pyx_k_range), 1, 1, 1}, + {&__pyx_kp_argmin, __pyx_k_argmin, sizeof(__pyx_k_argmin), 1, 1, 1}, + {&__pyx_kp_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 0}, + {&__pyx_kp___getbuffer__, __pyx_k___getbuffer__, sizeof(__pyx_k___getbuffer__), 1, 1, 1}, + {&__pyx_kp___releasebuffer__, __pyx_k___releasebuffer__, sizeof(__pyx_k___releasebuffer__), 1, 1, 1}, + {&__pyx_kp_info, __pyx_k_info, sizeof(__pyx_k_info), 1, 1, 1}, + {&__pyx_kp_flags, __pyx_k_flags, sizeof(__pyx_k_flags), 1, 1, 1}, + {&__pyx_kp_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 1, 1, 1}, + {&__pyx_kp_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 0}, + {&__pyx_kp_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 0}, + {&__pyx_kp_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 0}, + {&__pyx_kp_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 0}, + {&__pyx_kp_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 0}, + {&__pyx_kp_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 0}, + {&__pyx_kp_29, __pyx_k_29, sizeof(__pyx_k_29), 0, 0, 0}, + {&__pyx_kp_30, __pyx_k_30, sizeof(__pyx_k_30), 0, 0, 0}, + {0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_RuntimeError = __Pyx_GetName(__pyx_b, __pyx_n_s__RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 735; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_kp_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_kp_range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_RuntimeError = __Pyx_GetName(__pyx_b, __pyx_kp_RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; } static int __Pyx_InitGlobals(void) { - if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_15 = PyInt_FromLong(15); if (unlikely(!__pyx_int_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; return 0; __pyx_L1_error:; return -1; @@ -3730,9 +3499,7 @@ PyMODINIT_FUNC PyInit_spath(void); /*proto*/ PyMODINIT_FUNC PyInit_spath(void) #endif { - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_1 = 0; __pyx_init_filenames(); #ifdef CYTHON_REFNANNY void* __pyx_refchk = NULL; @@ -3771,55 +3538,38 @@ PyMODINIT_FUNC PyInit_spath(void) __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + if (__pyx_module_is_main_scikits__image__analysis__spath) { + if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_kp___main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + } /*--- Initialize various global constants etc. ---*/ if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_module_is_main_scikits__image__analysis__spath) { - if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - } /*--- Builtin init code ---*/ if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_skip_dispatch = 0; /*--- Global init code ---*/ /*--- Function export code ---*/ /*--- Type init code ---*/ /*--- Type import code ---*/ - __pyx_ptype_5numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr)); if (unlikely(!__pyx_ptype_5numpy_dtype)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5numpy_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject)); if (unlikely(!__pyx_ptype_5numpy_flatiter)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5numpy_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject)); if (unlikely(!__pyx_ptype_5numpy_broadcast)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject)); if (unlikely(!__pyx_ptype_5numpy_ndarray)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5numpy_ufunc = __Pyx_ImportType("numpy", "ufunc", sizeof(PyUFuncObject)); if (unlikely(!__pyx_ptype_5numpy_ufunc)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr)); if (unlikely(!__pyx_ptype_5numpy_dtype)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5numpy_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject)); if (unlikely(!__pyx_ptype_5numpy_flatiter)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5numpy_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject)); if (unlikely(!__pyx_ptype_5numpy_broadcast)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject)); if (unlikely(!__pyx_ptype_5numpy_ndarray)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Function import code ---*/ /*--- Execution code ---*/ - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":3 + /* "/home/brucewayne/scikits_image/scikits.image/scikits/image/analysis/spath.pyx":3 * # -*- python -*- * * import numpy as np # <<<<<<<<<<<<<< * cimport numpy as np * */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_1 = __Pyx_Import(__pyx_kp_numpy, 0); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_1); + if (PyObject_SetAttr(__pyx_m, __pyx_kp_np, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_1); __pyx_1 = 0; - /* "/Users/stefan/src/scikits.image/scikits/image/analysis/spath.pyx":1 - * # -*- python -*- # <<<<<<<<<<<<<< - * - * import numpy as np - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__shortest_path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_10), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - - /* "/Users/stefan/lib/python2.6/site-packages/Cython/Includes/stdlib.pxd":2 + /* "/usr/local/lib/python2.6/dist-packages/Cython-0.11.3-py2.6-linux-x86_64.egg/Cython/Includes/stdlib.pxd":2 * * cdef extern from "stdlib.h" nogil: # <<<<<<<<<<<<<< * void free(void *ptr) @@ -3827,9 +3577,7 @@ PyMODINIT_FUNC PyInit_spath(void) */ goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_1); if (__pyx_m) { __Pyx_AddTraceback("init scikits.image.analysis.spath"); Py_DECREF(__pyx_m); __pyx_m = 0; @@ -4483,6 +4231,10 @@ bad: return -1; } +static INLINE void __Pyx_RaiseNoneNotIterableError(void) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); +} + static INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { PyErr_Format(PyExc_ValueError, #if PY_VERSION_HEX < 0x02050000 @@ -4497,33 +4249,6 @@ static INLINE void __Pyx_RaiseTooManyValuesError(void) { PyErr_SetString(PyExc_ValueError, "too many values to unpack"); } -static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) { - PyObject *item; - if (!(item = PyIter_Next(iter))) { - if (!PyErr_Occurred()) { - __Pyx_RaiseNeedMoreValuesError(index); - } - } - return item; -} - -static int __Pyx_EndUnpack(PyObject *iter) { - PyObject *item; - if ((item = PyIter_Next(iter))) { - Py_DECREF(item); - __Pyx_RaiseTooManyValuesError(); - return -1; - } - else if (!PyErr_Occurred()) - return 0; - else - return -1; -} - -static INLINE void __Pyx_RaiseNoneNotIterableError(void) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); -} - static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) { if (t == Py_None) { __Pyx_RaiseNoneNotIterableError(); @@ -4796,230 +4521,28 @@ static int __Pyx_PrintOne(PyObject *o) { #endif -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - static INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { - return ::std::complex< float >(x, y); +static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) { + PyObject *item; + if (!(item = PyIter_Next(iter))) { + if (!PyErr_Occurred()) { + __Pyx_RaiseNeedMoreValuesError(index); + } } - #else - static INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { - return x + y*(__pyx_t_float_complex)_Complex_I; - } - #endif -#else - static INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { - __pyx_t_float_complex z; - z.real = x; - z.imag = y; - return z; - } -#endif + return item; +} -#if CYTHON_CCOMPLEX -#else - static INLINE int __Pyx_c_eqf(__pyx_t_float_complex a, __pyx_t_float_complex b) { - return (a.real == b.real) && (a.imag == b.imag); +static int __Pyx_EndUnpack(PyObject *iter) { + PyObject *item; + if ((item = PyIter_Next(iter))) { + Py_DECREF(item); + __Pyx_RaiseTooManyValuesError(); + return -1; } - static INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex a, __pyx_t_float_complex b) { - __pyx_t_float_complex z; - z.real = a.real + b.real; - z.imag = a.imag + b.imag; - return z; - } - static INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex a, __pyx_t_float_complex b) { - __pyx_t_float_complex z; - z.real = a.real - b.real; - z.imag = a.imag - b.imag; - return z; - } - static INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex a, __pyx_t_float_complex b) { - __pyx_t_float_complex z; - z.real = a.real * b.real - a.imag * b.imag; - z.imag = a.real * b.imag + a.imag * b.real; - return z; - } - static INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex a, __pyx_t_float_complex b) { - __pyx_t_float_complex z; - float denom = b.real * b.real + b.imag * b.imag; - z.real = (a.real * b.real + a.imag * b.imag) / denom; - z.imag = (a.imag * b.real - a.real * b.imag) / denom; - return z; - } - static INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex a) { - __pyx_t_float_complex z; - z.real = -a.real; - z.imag = -a.imag; - return z; - } - static INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex a) { - return (a.real == 0) && (a.imag == 0); - } - static INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex a) { - __pyx_t_float_complex z; - z.real = a.real; - z.imag = -a.imag; - return z; - } -/* - static INLINE float __Pyx_c_absf(__pyx_t_float_complex z) { -#if HAVE_HYPOT - return hypotf(z.real, z.imag); -#else - return sqrtf(z.real*z.real + z.imag*z.imag); -#endif - } -*/ -#endif - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - static INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) { - return ::std::complex< double >(x, y); - } - #else - static INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) { - return x + y*(__pyx_t_double_complex)_Complex_I; - } - #endif -#else - static INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) { - __pyx_t_double_complex z; - z.real = x; - z.imag = y; - return z; - } -#endif - -#if CYTHON_CCOMPLEX -#else - static INLINE int __Pyx_c_eq(__pyx_t_double_complex a, __pyx_t_double_complex b) { - return (a.real == b.real) && (a.imag == b.imag); - } - static INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex a, __pyx_t_double_complex b) { - __pyx_t_double_complex z; - z.real = a.real + b.real; - z.imag = a.imag + b.imag; - return z; - } - static INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex a, __pyx_t_double_complex b) { - __pyx_t_double_complex z; - z.real = a.real - b.real; - z.imag = a.imag - b.imag; - return z; - } - static INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex a, __pyx_t_double_complex b) { - __pyx_t_double_complex z; - z.real = a.real * b.real - a.imag * b.imag; - z.imag = a.real * b.imag + a.imag * b.real; - return z; - } - static INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex a, __pyx_t_double_complex b) { - __pyx_t_double_complex z; - double denom = b.real * b.real + b.imag * b.imag; - z.real = (a.real * b.real + a.imag * b.imag) / denom; - z.imag = (a.imag * b.real - a.real * b.imag) / denom; - return z; - } - static INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex a) { - __pyx_t_double_complex z; - z.real = -a.real; - z.imag = -a.imag; - return z; - } - static INLINE int __Pyx_c_is_zero(__pyx_t_double_complex a) { - return (a.real == 0) && (a.imag == 0); - } - static INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex a) { - __pyx_t_double_complex z; - z.real = a.real; - z.imag = -a.imag; - return z; - } -/* - static INLINE double __Pyx_c_abs(__pyx_t_double_complex z) { -#if HAVE_HYPOT - return hypot(z.real, z.imag); -#else - return sqrt(z.real*z.real + z.imag*z.imag); -#endif - } -*/ -#endif - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - static INLINE __pyx_t_long_double_complex __pyx_t_long_double_complex_from_parts(long double x, long double y) { - return ::std::complex< long double >(x, y); - } - #else - static INLINE __pyx_t_long_double_complex __pyx_t_long_double_complex_from_parts(long double x, long double y) { - return x + y*(__pyx_t_long_double_complex)_Complex_I; - } - #endif -#else - static INLINE __pyx_t_long_double_complex __pyx_t_long_double_complex_from_parts(long double x, long double y) { - __pyx_t_long_double_complex z; - z.real = x; - z.imag = y; - return z; - } -#endif - -#if CYTHON_CCOMPLEX -#else - static INLINE int __Pyx_c_eql(__pyx_t_long_double_complex a, __pyx_t_long_double_complex b) { - return (a.real == b.real) && (a.imag == b.imag); - } - static INLINE __pyx_t_long_double_complex __Pyx_c_suml(__pyx_t_long_double_complex a, __pyx_t_long_double_complex b) { - __pyx_t_long_double_complex z; - z.real = a.real + b.real; - z.imag = a.imag + b.imag; - return z; - } - static INLINE __pyx_t_long_double_complex __Pyx_c_diffl(__pyx_t_long_double_complex a, __pyx_t_long_double_complex b) { - __pyx_t_long_double_complex z; - z.real = a.real - b.real; - z.imag = a.imag - b.imag; - return z; - } - static INLINE __pyx_t_long_double_complex __Pyx_c_prodl(__pyx_t_long_double_complex a, __pyx_t_long_double_complex b) { - __pyx_t_long_double_complex z; - z.real = a.real * b.real - a.imag * b.imag; - z.imag = a.real * b.imag + a.imag * b.real; - return z; - } - static INLINE __pyx_t_long_double_complex __Pyx_c_quotl(__pyx_t_long_double_complex a, __pyx_t_long_double_complex b) { - __pyx_t_long_double_complex z; - long double denom = b.real * b.real + b.imag * b.imag; - z.real = (a.real * b.real + a.imag * b.imag) / denom; - z.imag = (a.imag * b.real - a.real * b.imag) / denom; - return z; - } - static INLINE __pyx_t_long_double_complex __Pyx_c_negl(__pyx_t_long_double_complex a) { - __pyx_t_long_double_complex z; - z.real = -a.real; - z.imag = -a.imag; - return z; - } - static INLINE int __Pyx_c_is_zerol(__pyx_t_long_double_complex a) { - return (a.real == 0) && (a.imag == 0); - } - static INLINE __pyx_t_long_double_complex __Pyx_c_conjl(__pyx_t_long_double_complex a) { - __pyx_t_long_double_complex z; - z.real = a.real; - z.imag = -a.imag; - return z; - } -/* - static INLINE long double __Pyx_c_absl(__pyx_t_long_double_complex z) { -#if HAVE_HYPOT - return hypotl(z.real, z.imag); -#else - return sqrtl(z.real*z.real + z.imag*z.imag); -#endif - } -*/ -#endif + else if (!PyErr_Occurred()) + return 0; + else + return -1; +} static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { if (sizeof(unsigned char) < sizeof(long)) { @@ -5501,7 +5024,7 @@ bad: static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { while (t->p) { #if PY_MAJOR_VERSION < 3 - if (t->is_unicode) { + if (t->is_unicode && (!t->is_identifier)) { *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); } else if (t->intern) { *t->p = PyString_InternFromString(t->s); @@ -5509,14 +5032,10 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { *t->p = PyString_FromStringAndSize(t->s, t->n - 1); } #else /* Python 3+ has unicode identifiers */ - if (t->is_unicode | t->is_str) { - if (t->intern) { - *t->p = PyUnicode_InternFromString(t->s); - } else if (t->encoding) { - *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); - } else { - *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); - } + if (t->is_identifier || (t->is_unicode && t->intern)) { + *t->p = PyUnicode_InternFromString(t->s); + } else if (t->is_unicode) { + *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); } else { *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); } diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index 504d7e8a..839b7d71 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -27,11 +27,27 @@ else: class LabelImage(QLabel): def __init__(self, parent, arr): QLabel.__init__(self) + self.parent = parent + # we need to hold a reference to + # arr because QImage doesn't copy the data + # and the buffer must be alive as long + # as the image is alive. + self.arr = arr + + # we also need to pass in the row-stride to + # the constructor, because we can't guarantee + # that every row of the numpy data is + # 4-byte aligned. Which Qt would require + # if we didnt pass the stride. self.img = QImage(arr.data, arr.shape[1], arr.shape[0], arr.strides[0], QImage.Format_RGB888) + self.pm = QPixmap.fromImage(self.img) self.setPixmap(self.pm) + def mouseMoveEvent(self, evt): + self.parent.label_mouseMoveEvent(evt) + class ImageWindow(QMainWindow): def __init__(self, arr, mgr): @@ -46,20 +62,32 @@ else: # references to it self.mgr.remove_window(self) + def label_mouseMoveEvent(self, evt): + pass + class FancyImageWindow(ImageWindow): def __init__(self, arr, mgr): ImageWindow.__init__(self, arr, mgr) - - # we need to hold a reference to arr, - # if we want to access the data later, - # because QImage does not copy the data. self.arr = arr + # for image manipulation + self.arrfloat = np.asarray(arr, dtype=np.float64) + self.arruint8 = arr.copy() + self.statusBar().showMessage('X: Y: ') self.label.setScaledContents(True) self.label.setMouseTracking(True) - self.label.mouseMoveEvent = self.label_mouseMoveEvent + + + def keyPressEvent(self, evt): + self.arrfloat[:,:,0] *= 1.1 + np.clip(self.arrfloat, 0, 255, self.arrfloat) + self.arr[:] = self.arrfloat[:] + + pm = QPixmap.fromImage(self.label.img) + self.label.setPixmap(pm) + print 'heard' def scale_mouse_pos(self, x, y): width = self.label.width() From 663738ab791d5da43037b58a36c78e6f3ffb317b Mon Sep 17 00:00:00 2001 From: sccolbert Date: Wed, 4 Nov 2009 02:28:57 +0100 Subject: [PATCH 03/43] added the beginnings of the color mixes, and improved fancy imshow for qt --- scikits/image/io/_plugins/_colormixer.pyx | 51 ++++++++++++ scikits/image/io/_plugins/qt_plugin.py | 95 ++++++++++++++++++++--- scikits/image/io/_plugins/util.py | 87 ++++++++++++++++++++- 3 files changed, 220 insertions(+), 13 deletions(-) create mode 100644 scikits/image/io/_plugins/_colormixer.pyx diff --git a/scikits/image/io/_plugins/_colormixer.pyx b/scikits/image/io/_plugins/_colormixer.pyx new file mode 100644 index 00000000..35d7bd6b --- /dev/null +++ b/scikits/image/io/_plugins/_colormixer.pyx @@ -0,0 +1,51 @@ +# ColorMixer function implementations +import numpy as np +cimport numpy as np + +import cython + +@cython.boundscheck(False) +def add(np.ndarray[np.uint8_t, ndim=3] img, + np.ndarray[np.uint8_t, ndim=3] stateimg, + int channel, int ammount): + + cdef int height = img.shape[0] + cdef int width = img.shape[1] + cdef int k = channel + cdef int n = ammount + + cdef np.int16_t op_result + + cdef int i, j + for i in range(height): + for j in range(width): + op_result = (stateimg[i,j,k] + n) + if op_result > 255: + img[i, j, k] = 255 + elif op_result < 0: + img[i, j, k] = 0 + else: + img[i, j, k] = op_result + +@cython.boundscheck(False) +def multiply(np.ndarray[np.uint8_t, ndim=3] img, + np.ndarray[np.uint8_t, ndim=3] stateimg, + int channel, float ammount): + + cdef int height = img.shape[0] + cdef int width = img.shape[1] + cdef int k = channel + cdef float n = ammount + + cdef float op_result + + cdef int i, j + for i in range(height): + for j in range(width): + op_result = (stateimg[i,j,k] * n) + if op_result > 255: + img[i, j, k] = 255 + elif op_result < 0: + img[i, j, k] = 0 + else: + img[i, j, k] = op_result \ No newline at end of file diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index 839b7d71..62b94526 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -1,4 +1,4 @@ -from util import prepare_for_display, window_manager, GuiLockError +from util import prepare_for_display, window_manager, GuiLockError, ColorMixer import numpy as np import sys @@ -14,7 +14,8 @@ except GuiLockError, gle: else: try: from PyQt4.QtGui import (QApplication, QMainWindow, QImage, QPixmap, - QLabel, QWidget, QVBoxLayout) + QLabel, QWidget, QVBoxLayout, QSlider) + from PyQt4 import QtCore, QtGui except ImportError: print 'PyQT4 libraries not installed. Plugin not loaded.' @@ -53,9 +54,14 @@ else: def __init__(self, arr, mgr): QMainWindow.__init__(self) self.mgr = mgr + self.main_widget = QWidget() + self.layout = QtGui.QHBoxLayout(self.main_widget) + self.setCentralWidget(self.main_widget) + self.label = LabelImage(self, arr) - self.setCentralWidget(self.label) + self.layout.addWidget(self.label) self.mgr.add_window(self) + self.main_widget.show() def closeEvent(self, event): # Allow window to be destroyed by removing any @@ -66,28 +72,93 @@ else: pass + class SliderBlock(QWidget): + def __init__(self, srange, callback): + QWidget.__init__(self) + + self.callback = callback + + low = srange[0] + high = srange[1] + init = srange[2] + + self.rslider = QSlider() + self.rslider.setRange(low, high) + self.rslider.setValue(init) + + self.gslider = QSlider() + self.gslider.setRange(low, high) + self.gslider.setValue(init) + + self.bslider = QSlider() + self.bslider.setRange(low, high) + self.bslider.setValue(init) + + self.rslider.valueChanged.connect(self.rslider_changed) + self.gslider.valueChanged.connect(self.gslider_changed) + self.bslider.valueChanged.connect(self.bslider_changed) + + self.layout = QtGui.QHBoxLayout(self) + self.layout.addWidget(self.rslider) + self.layout.addWidget(self.gslider) + self.layout.addWidget(self.bslider) + + def rslider_changed(self, val): + self.callback('RED', val) + + def gslider_changed(self, val): + self.callback('GREEN', val) + + def bslider_changed(self, val): + self.callback('BLUE', val) + + class FancyImageWindow(ImageWindow): def __init__(self, arr, mgr): ImageWindow.__init__(self, arr, mgr) self.arr = arr - # for image manipulation - self.arrfloat = np.asarray(arr, dtype=np.float64) - self.arruint8 = arr.copy() - self.statusBar().showMessage('X: Y: ') self.label.setScaledContents(True) self.label.setMouseTracking(True) + self.mixer = ColorMixer(self.arr) - def keyPressEvent(self, evt): - self.arrfloat[:,:,0] *= 1.1 - np.clip(self.arrfloat, 0, 255, self.arrfloat) - self.arr[:] = self.arrfloat[:] + self.sliders = SliderBlock((-255, 255, 0), self.svalueChanged) + self.msliders = SliderBlock((0, 1000, 500), self.mvalueChanged) + + self.layout.addWidget(self.sliders) + self.layout.addWidget(self.msliders) + + self.sliders.show() + self.msliders.show() + + def svalueChanged(self, who, val): + if who == 'RED': + self.mixer.add(self.mixer.RED, val) + elif who == 'GREEN': + self.mixer.add(self.mixer.GREEN, val) + elif who == 'BLUE': + self.mixer.add(self.mixer.BLUE, val) + else: + return + + pm = QPixmap.fromImage(self.label.img) + self.label.setPixmap(pm) + + def mvalueChanged(self, who, val): + val = val / 500. + if who == 'RED': + self.mixer.multiply(self.mixer.RED, val) + elif who == 'GREEN': + self.mixer.multiply(self.mixer.GREEN, val) + elif who == 'BLUE': + self.mixer.multiply(self.mixer.BLUE, val) + else: + return pm = QPixmap.fromImage(self.label.img) self.label.setPixmap(pm) - print 'heard' def scale_mouse_pos(self, x, y): width = self.label.width() diff --git a/scikits/image/io/_plugins/util.py b/scikits/image/io/_plugins/util.py index 6dd4f8e7..96ae939c 100644 --- a/scikits/image/io/_plugins/util.py +++ b/scikits/image/io/_plugins/util.py @@ -1,5 +1,5 @@ import numpy as np - +import _colormixer # utilities to make life easier for plugin writers. @@ -149,3 +149,88 @@ def prepare_for_display(npy_img): raise ValueError('Image must have 2 or 3 dimensions') return out + + + +class ColorMixer(object): + ''' a class to manage mixing colors in an image. + The input array must be an RGB uint8 image. + + The mixer maintains an original copy of the image, + and uses this copy to query the pixel data for operations. + It also makes a copy for sharing state across operations. + That is, if you add to a channel, and multiply to same channel, + the two operations are carried separately and the results + averaged together. + + it modifies your array in place. This ensures that if you + bust over a threshold, you can always come back down. + + The passed values to a function are always considered + absolute. Thus to threshold a channel completely you + can do mixer.add(RED, 255). Or to double the intensity + of the blue channel: mixer.multiply(BLUE, 2.) + + To reverse these operations, respectively: + mixer.add(RED, 0), mixer.multiply(BLUE, 1.) + + The majority of the backend is implemented in Cython, + so it should be quite quick. + ''' + + RED = 0 + GREEN = 1 + BLUE = 2 + + valid_channels = [RED, GREEN, BLUE] + + def __init__(self, img): + if type(img) != np.ndarray: + raise ValueError('Image must be a numpy array') + if img.dtype != np.uint8: + raise ValueError('Image must have dtype uint8') + if img.ndim != 3 or img.shape[2] != 3: + raise ValueError('Image must be 3 channel MxNx3') + + self.img = img + self.stateimg = img.copy() + + def get_stateimage(self): + return self.stateimg + + def commit_changes(self): + self.stateimg[:] = self.img[:] + + def add(self, channel, ammount): + '''Add the specified ammount to the specified channel. + + Parameters + ---------- + channel : flag + the color channel to operate on + RED, GREED, or BLUE + ammount : integer + the ammount of color to add to the channel, + can be positive or negative. + + ''' + assert channel in self.valid_channels + + _colormixer.add(self.img, self.stateimg, channel, ammount) + + def multiply(self, channel, ammount): + '''Mutliply the indicated channel by the specified value. + + Parameters + ---------- + channel : flag + the color channel to operate on + RED, GREED, or BLUE + ammount : integer + the ammount of color to add to the channel, + can be positive or negative. + + ''' + assert channel in self.valid_channels + + _colormixer.multiply(self.img, self.stateimg, channel, ammount) From 51a1832d971a7ab740f63cf760c852e4b300ce44 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Wed, 4 Nov 2009 07:45:58 +0200 Subject: [PATCH 04/43] io: Add setup files for colour mixer. --- scikits/image/io/setup.py | 34 ++++++++++++++++++++++++++++++++++ scikits/image/setup.py | 1 + 2 files changed, 35 insertions(+) create mode 100644 scikits/image/io/setup.py diff --git a/scikits/image/io/setup.py b/scikits/image/io/setup.py new file mode 100644 index 00000000..2565d724 --- /dev/null +++ b/scikits/image/io/setup.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +from scikits.image._build import cython + +import os.path + +base_path = os.path.abspath(os.path.dirname(__file__)) + +def configuration(parent_package='', top_path=None): + from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs + + config = Configuration('io', parent_package, top_path) + config.add_data_dir('tests') + config.add_data_files('_plugins/*.ini') + + # This function tries to create C files from the given .pyx files. If + # it fails, we build the checked-in .c files. + cython(['_plugins/_colormixer.pyx'], working_path=base_path) + + config.add_extension('_plugins._colormixer', + sources=['_plugins/_colormixer.c'], + include_dirs=[get_numpy_include_dirs()]) + + return config + +if __name__ == '__main__': + from numpy.distutils.core import setup + setup(maintainer = 'scikits.image Developers', + maintainer_email = 'scikits-image@googlegroups.com', + description = 'Image I/O Routines', + url = 'http://stefanv.github.com/scikits.image/', + license = 'Modified BSD', + **(configuration(top_path='').todict()) + ) diff --git a/scikits/image/setup.py b/scikits/image/setup.py index 706604e4..68cdcf0e 100644 --- a/scikits/image/setup.py +++ b/scikits/image/setup.py @@ -7,6 +7,7 @@ def configuration(parent_package='', top_path=None): config.add_subpackage('opencv') config.add_subpackage('analysis') + config.add_subpackage('io') def add_test_directories(arg, dirname, fnames): if dirname.split(os.path.sep)[-1] == 'tests': From d89e577c8708b028c969293e25a1e1588af19a54 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Wed, 4 Nov 2009 07:46:52 +0200 Subject: [PATCH 05/43] io: Document colour mixer. --- scikits/image/io/_plugins/_colormixer.pyx | 50 ++++++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/scikits/image/io/_plugins/_colormixer.pyx b/scikits/image/io/_plugins/_colormixer.pyx index 35d7bd6b..aefe96bc 100644 --- a/scikits/image/io/_plugins/_colormixer.pyx +++ b/scikits/image/io/_plugins/_colormixer.pyx @@ -1,4 +1,14 @@ -# ColorMixer function implementations +# -*- python -*- + +"""Colour Mixer + +NumPy does not do overflow checking when adding or multiplying +integers, so currently the only way to clip results efficiently +(without making copies of the data) is with an extension such as this +one. + +""" + import numpy as np cimport numpy as np @@ -7,12 +17,26 @@ import cython @cython.boundscheck(False) def add(np.ndarray[np.uint8_t, ndim=3] img, np.ndarray[np.uint8_t, ndim=3] stateimg, - int channel, int ammount): + int channel, int amount): + """Add a given amount to a colour channel of `stateimg`, and + store the result in `img`. Overflow is clipped. + Parameters + ---------- + img : (M, N, 3) ndarray of uint8 + Output image. + stateimg : (M, N, 3) ndarray of uint8 + Input image. + channel : int + Channel (0 for "red", 1 for "green", 2 for "blue"). + amount : int + Value to add. + + """ cdef int height = img.shape[0] cdef int width = img.shape[1] cdef int k = channel - cdef int n = ammount + cdef int n = amount cdef np.int16_t op_result @@ -30,12 +54,26 @@ def add(np.ndarray[np.uint8_t, ndim=3] img, @cython.boundscheck(False) def multiply(np.ndarray[np.uint8_t, ndim=3] img, np.ndarray[np.uint8_t, ndim=3] stateimg, - int channel, float ammount): + int channel, float amount): + """Multiply a colour channel of `stateimg` by a certain amount, and + store the result in `img`. Overflow is clipped. + Parameters + ---------- + img : (M, N, 3) ndarray of uint8 + Output image. + stateimg : (M, N, 3) ndarray of uint8 + Input image. + channel : int + Channel (0 for "red", 1 for "green", 2 for "blue"). + amount : float + Multiplication factor. + + """ cdef int height = img.shape[0] cdef int width = img.shape[1] cdef int k = channel - cdef float n = ammount + cdef float n = amount cdef float op_result @@ -48,4 +86,4 @@ def multiply(np.ndarray[np.uint8_t, ndim=3] img, elif op_result < 0: img[i, j, k] = 0 else: - img[i, j, k] = op_result \ No newline at end of file + img[i, j, k] = op_result From 9ab169a25d245c1b64a99d2c9616423e345ff9f8 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Wed, 4 Nov 2009 07:47:07 +0200 Subject: [PATCH 06/43] io: Add tests for colormixer. --- scikits/image/io/tests/test_colormixer.py | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 scikits/image/io/tests/test_colormixer.py diff --git a/scikits/image/io/tests/test_colormixer.py b/scikits/image/io/tests/test_colormixer.py new file mode 100644 index 00000000..6ea620eb --- /dev/null +++ b/scikits/image/io/tests/test_colormixer.py @@ -0,0 +1,49 @@ +from numpy.testing import * +import numpy as np + +import scikits.image.io._plugins._colormixer as cm + +class ColorMixerTest(object): + def setup(self): + self.state = np.ones((18, 33, 3), dtype=np.uint8) * 200 + self.img = np.zeros_like(self.state) + + def test_basic(self): + self.op(self.img, self.state, 0, self.positive) + assert_array_equal(self.img[..., 0], + self.py_op(self.state[..., 0], self.positive)) + + def test_clip(self): + self.op(self.img, self.state, 0, self.positive_clip) + assert_array_equal(self.img[..., 0], + np.ones_like(self.img[..., 0]) * 255) + + def test_negative(self): + self.op(self.img, self.state, 0, self.negative) + assert_array_equal(self.img[..., 0], + self.py_op(self.state[..., 0], self.negative)) + + def test_negative_clip(self): + self.op(self.img, self.state, 0, self.negative_clip) + assert_array_equal(self.img[..., 0], + np.zeros_like(self.img[..., 0])) + +class TestColorMixerAdd(ColorMixerTest): + op = cm.add + py_op = np.add + positive = 50 + positive_clip = 56 + negative = -50 + negative_clip = -220 + +class TestColorMixerMul(ColorMixerTest): + op = cm.multiply + py_op = np.multiply + positive = 1.2 + positive_clip = 2 + negative = 0.5 + negative_clip = -0.5 + + +if __name__ == "__main__": + run_module_suite() From 0216fb6094488d45bc6ede5123b09006128be45a Mon Sep 17 00:00:00 2001 From: sccolbert Date: Wed, 4 Nov 2009 17:27:07 +0100 Subject: [PATCH 07/43] Modified the fancy imshow widget, and added brightness control to the mixer. --- scikits/image/io/_plugins/_colormixer.pyx | 38 +++ scikits/image/io/_plugins/qt_plugin.py | 322 ++++++++++++++++++---- scikits/image/io/_plugins/util.py | 11 + 3 files changed, 310 insertions(+), 61 deletions(-) diff --git a/scikits/image/io/_plugins/_colormixer.pyx b/scikits/image/io/_plugins/_colormixer.pyx index aefe96bc..ee79bb56 100644 --- a/scikits/image/io/_plugins/_colormixer.pyx +++ b/scikits/image/io/_plugins/_colormixer.pyx @@ -87,3 +87,41 @@ def multiply(np.ndarray[np.uint8_t, ndim=3] img, img[i, j, k] = 0 else: img[i, j, k] = op_result + +@cython.boundscheck(False) +def brightness(np.ndarray[np.uint8_t, ndim=3] img, + np.ndarray[np.uint8_t, ndim=3] stateimg, + int offset, float factor): + """Modify the brightness of an image. + 'offset' is added to all channels, which are + then multiplied by 'factor'. Overflow is clipped. + + Parameters + ---------- + img : (M, N, 3) ndarray of uint8 + Output image. + stateimg : (M, N, 3) ndarray of uint8 + Input image. + offset : int + Ammount to add to each channel. + factor : float + Multiplication factor. + + """ + + cdef int height = img.shape[0] + cdef int width = img.shape[1] + + cdef float op_result + + cdef int i, j, k + for i in range(height): + for j in range(width): + for k in range(3): + op_result = ((stateimg[i,j,k] + offset)*factor) + if op_result > 255: + img[i, j, k] = 255 + elif op_result < 0: + img[i, j, k] = 0 + else: + img[i, j, k] = op_result diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index 62b94526..d155ed09 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -72,45 +72,275 @@ else: pass - class SliderBlock(QWidget): - def __init__(self, srange, callback): + class IntelligentSlider(QSlider): + ''' A slider that adds a 'name' attribute and calls a callback + with 'name' as an argument to the registerd callback. + + This allows you to create large groups of sliders in a loop, + but still keep track of the individual events''' + + def __init__(self, name, callback): + QSlider.__init__(self) + self.name = name + self.callback = callback + self.valueChanged.connect(self.i_changed) + + def i_changed(self, val): + self.callback(self.name, val) + + + class NSliderBlock(QWidget): + '''Creates a block of n sliders with ranges + specified as a list of tuples. The fourth entry + in the tuple will be used as a dictionary key + so you can access the slider later. + So the tuple should be (min, max, initial, name) + + The callback is the function to be called + when a slider value changes. The callback will be + called with the following arguments (name, value). + + You can get a hook to a specific slider using + NSliderBlock.sliders[name] + + ''' + + def __init__(self, n, ranges_labels, callback): QWidget.__init__(self) + if len(ranges_labels) != n: + raise ValueError('not enough or too many ranges supplied') + self.callback = callback + self.sliders = {} + self.slider_names = [] + self.layout = QtGui.QGridLayout(self) - low = srange[0] - high = srange[1] - init = srange[2] + for i in range(n): + params = ranges_labels[i] + if len(params) != 4: + raise ValueError('Tuples must be length 4') - self.rslider = QSlider() - self.rslider.setRange(low, high) - self.rslider.setValue(init) + name = params[3] + slider_name = QLabel() + slider_name.setText(name) + slider_name.setAlignment(QtCore.Qt.AlignCenter) + self.slider_names.append(slider_name) - self.gslider = QSlider() - self.gslider.setRange(low, high) - self.gslider.setValue(init) + self.layout.addWidget(slider_name, 0, i) - self.bslider = QSlider() - self.bslider.setRange(low, high) - self.bslider.setValue(init) - self.rslider.valueChanged.connect(self.rslider_changed) - self.gslider.valueChanged.connect(self.gslider_changed) - self.bslider.valueChanged.connect(self.bslider_changed) + slider = IntelligentSlider(name, self.callback) + slider.setMinimum(params[0]) + slider.setMaximum(params[1]) + slider.setValue(params[2]) - self.layout = QtGui.QHBoxLayout(self) - self.layout.addWidget(self.rslider) - self.layout.addWidget(self.gslider) - self.layout.addWidget(self.bslider) + self.sliders[name] = slider - def rslider_changed(self, val): - self.callback('RED', val) + self.layout.addWidget(slider, 1, i) - def gslider_changed(self, val): - self.callback('GREEN', val) + def set_sliders(self, vals): + # vals should a dict to of slider names and set vals + if len(vals) != len(self.sliders): + raise ValueError('Wrong number of values') + + for key, value in vals.iteritems(): + self.sliders[key].setValue(value) + + class MixerPanel(QWidget): + '''A color mixer to hook up to an image. + You pass the image you the panel to operate on + and it operates on that image in place. You also + pass a callback to be called to trigger a refresh. + This callback is called every time the mixer modifies + your image.''' + def __init__(self, img, callback): + QWidget.__init__(self) + + self.img = img + self.update = callback + self.mixer = ColorMixer(self.img) + + #--------------------------------------------------------------- + # ComboBox + #--------------------------------------------------------------- + + self.combo_box_entries = ['RGB Color', 'HSV Color', + 'Brightness', 'Contrast'] + self.combo_box = QtGui.QComboBox() + for entry in self.combo_box_entries: + self.combo_box.addItem(entry) + self.combo_box.currentIndexChanged.connect(self.combo_box_changed) + + #--------------------------------------------------------------- + # RGB color sliders + #--------------------------------------------------------------- + + # radio buttons + self.rgb_add = QtGui.QRadioButton('Additive') + self.rgb_mul = QtGui.QRadioButton('Multiplicative') + self.rgb_mul.toggled.connect(self.rgb_radio_changed) + self.rgb_add.toggled.connect(self.rgb_radio_changed) + + # additive sliders + self.rgb_add_sliders = NSliderBlock(3, [(-255, 255, 0, 'R'), + (-255, 255, 0, 'G'), + (-255, 255, 0, 'B')], + self.rgb_add_changed) + + # multiplicative sliders + self.rgb_mul_sliders = NSliderBlock(3, [(0, 1000, 500, 'R'), + (0, 1000, 500, 'G'), + (0, 1000, 500, 'B')], + self.rgb_mul_changed) + + # layout + self.rgb_widget = QWidget() + self.rgb_widget.layout = QtGui.QGridLayout(self.rgb_widget) + self.rgb_widget.layout.addWidget(self.rgb_add, 0, 0) + self.rgb_widget.layout.addWidget(self.rgb_mul, 1, 0) + self.rgb_widget.layout.addWidget(self.rgb_add_sliders, 2, 0) + self.rgb_widget.layout.addWidget(self.rgb_mul_sliders, 2, 0) + + #--------------------------------------------------------------- + # Brightness sliders + #--------------------------------------------------------------- + + # sliders + self.bright_sliders = NSliderBlock(2, [(-255, 255, 0, 'OFF'), + (0, 1000, 500, 'FAC')], + self.bright_changed) + + # layout + self.bright_widget = QWidget() + self.bright_widget.layout = QtGui.QGridLayout(self.bright_widget) + self.bright_widget.layout.addWidget(self.bright_sliders, 0, 0) + + #--------------------------------------------------------------- + # Buttons + #--------------------------------------------------------------- + self.commit_button = QtGui.QPushButton('Commit') + self.commit_button.clicked.connect(self.commit_changes) + self.revert_button = QtGui.QPushButton('Revert') + self.revert_button.clicked.connect(self.revert_changes) + + #--------------------------------------------------------------- + # Mixer Layout + #--------------------------------------------------------------- + self.layout = QtGui.QGridLayout(self) + self.layout.addWidget(self.combo_box, 0, 0) + self.layout.addWidget(self.rgb_widget, 1, 0) + self.layout.addWidget(self.bright_widget, 1, 0) + self.layout.addWidget(self.commit_button, 2, 0) + self.layout.addWidget(self.revert_button, 3, 0) + + #--------------------------------------------------------------- + # Initialization + #--------------------------------------------------------------- + + self.combo_box.setCurrentIndex(0) + self.hide_sliders() + self.rgb_widget.show() + self.rgb_add.setChecked(True) + + def rgb_add_changed(self, name, val): + if not self.rgb_add.isChecked(): + return + if name == 'R': + self.mixer.add(self.mixer.RED, val) + elif name == 'G': + self.mixer.add(self.mixer.GREEN, val) + elif name == 'B': + self.mixer.add(self.mixer.BLUE, val) + else: + return + self.update() + + def rgb_mul_changed(self, name, val): + if not self.rgb_mul.isChecked(): + return + val = val/500. + if name == 'R': + self.mixer.multiply(self.mixer.RED, val) + elif name == 'G': + self.mixer.multiply(self.mixer.GREEN, val) + elif name == 'B': + self.mixer.multiply(self.mixer.BLUE, val) + else: + return + self.update() + + def bright_changed(self, name, val): + # doesnt matter which slider changed we need both + # values + + # i dont know why this is required, but if you take it out + # an exception is thrown for missing attribute when the + # class is initialized + # though everything will still work. + # python 2.6.4 BUG? + if not hasattr(self, 'bright_sliders'): + return + + factor = self.bright_sliders.sliders['FAC'].value() / 500. + offset = self.bright_sliders.sliders['OFF'].value() + self.mixer.brightness(offset, factor) + self.update() + + + def reset_sliders(self): + self.rgb_add_sliders.set_sliders({'R': 0, 'G': 0, 'B': 0}) + self.rgb_mul_sliders.set_sliders({'R': 500, 'G': 500, 'B': 500}) + self.bright_sliders.set_sliders({'OFF': 0, 'FAC': 500}) + + def combo_box_changed(self, index): + self.reset_sliders() + self.mixer.set_to_stateimg() + self.update() + combo_box_map={0: self.show_rgb, 1: self.show_hsv, + 2: self.show_bright, 3: self.show_contrast} + combo_box_map[index]() + + def hide_sliders(self): + self.rgb_widget.hide() + self.bright_widget.hide() + + def rgb_radio_changed(self): + if self.rgb_add.isChecked(): + self.rgb_add_sliders.show() + self.rgb_mul_sliders.hide() + elif self.rgb_mul.isChecked(): + self.rgb_mul_sliders.show() + self.rgb_add_sliders.hide() + else: + pass + + self.reset_sliders() + self.mixer.set_to_stateimg() + self.update() + + def show_rgb(self): + self.hide_sliders() + self.rgb_widget.show() + + def show_hsv(self): + self.hide_sliders() + + def show_bright(self): + self.hide_sliders() + self.bright_widget.show() + + def show_contrast(self): + self.hide_sliders() + + def commit_changes(self): + self.mixer.commit_changes() + self.update() + + def revert_changes(self): + self.mixer.revert() + self.update() - def bslider_changed(self, val): - self.callback('BLUE', val) class FancyImageWindow(ImageWindow): @@ -122,41 +352,11 @@ else: self.label.setScaledContents(True) self.label.setMouseTracking(True) - self.mixer = ColorMixer(self.arr) - - self.sliders = SliderBlock((-255, 255, 0), self.svalueChanged) - self.msliders = SliderBlock((0, 1000, 500), self.mvalueChanged) - - self.layout.addWidget(self.sliders) - self.layout.addWidget(self.msliders) - - self.sliders.show() - self.msliders.show() - - def svalueChanged(self, who, val): - if who == 'RED': - self.mixer.add(self.mixer.RED, val) - elif who == 'GREEN': - self.mixer.add(self.mixer.GREEN, val) - elif who == 'BLUE': - self.mixer.add(self.mixer.BLUE, val) - else: - return - - pm = QPixmap.fromImage(self.label.img) - self.label.setPixmap(pm) - - def mvalueChanged(self, who, val): - val = val / 500. - if who == 'RED': - self.mixer.multiply(self.mixer.RED, val) - elif who == 'GREEN': - self.mixer.multiply(self.mixer.GREEN, val) - elif who == 'BLUE': - self.mixer.multiply(self.mixer.BLUE, val) - else: - return + self.mixer_panel = MixerPanel(self.arr, self.refresh_image) + self.layout.addWidget(self.mixer_panel) + self.mixer_panel.show() + def refresh_image(self): pm = QPixmap.fromImage(self.label.img) self.label.setPixmap(pm) diff --git a/scikits/image/io/_plugins/util.py b/scikits/image/io/_plugins/util.py index 96ae939c..8f32f4e5 100644 --- a/scikits/image/io/_plugins/util.py +++ b/scikits/image/io/_plugins/util.py @@ -193,6 +193,7 @@ class ColorMixer(object): raise ValueError('Image must be 3 channel MxNx3') self.img = img + self.origimg = img.copy() self.stateimg = img.copy() def get_stateimage(self): @@ -201,6 +202,13 @@ class ColorMixer(object): def commit_changes(self): self.stateimg[:] = self.img[:] + def revert(self): + self.stateimg[:] = self.origimg[:] + self.img[:] = self.stateimg[:] + + def set_to_stateimg(self): + self.img[:] = self.stateimg[:] + def add(self, channel, ammount): '''Add the specified ammount to the specified channel. @@ -234,3 +242,6 @@ class ColorMixer(object): assert channel in self.valid_channels _colormixer.multiply(self.img, self.stateimg, channel, ammount) + + def brightness(self, offset, factor): + _colormixer.brightness(self.img, self.stateimg, offset, factor) From eed8d6f23f28319e7dd30afc31b28c044dfdbb65 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Wed, 4 Nov 2009 19:53:42 +0100 Subject: [PATCH 08/43] fixed a bug in slider signal connection. --- scikits/image/io/_plugins/qt_plugin.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index d155ed09..2da20a53 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -83,8 +83,8 @@ else: QSlider.__init__(self) self.name = name self.callback = callback - self.valueChanged.connect(self.i_changed) + # bind this to the valueChanged signal of the slider def i_changed(self, val): self.callback(self.name, val) @@ -134,6 +134,7 @@ else: slider.setMinimum(params[0]) slider.setMaximum(params[1]) slider.setValue(params[2]) + slider.valueChanged.connect(slider.i_changed) self.sliders[name] = slider @@ -273,15 +274,6 @@ else: def bright_changed(self, name, val): # doesnt matter which slider changed we need both # values - - # i dont know why this is required, but if you take it out - # an exception is thrown for missing attribute when the - # class is initialized - # though everything will still work. - # python 2.6.4 BUG? - if not hasattr(self, 'bright_sliders'): - return - factor = self.bright_sliders.sliders['FAC'].value() / 500. offset = self.bright_sliders.sliders['OFF'].value() self.mixer.brightness(offset, factor) @@ -339,6 +331,7 @@ else: def revert_changes(self): self.mixer.revert() + self.reset_sliders() self.update() From 186eee357ab9a9a1d91f0651f6a9efcffa5aff79 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Wed, 4 Nov 2009 21:03:22 +0100 Subject: [PATCH 09/43] added slider value labels and fixed their layout a little. --- scikits/image/io/_plugins/qt_plugin.py | 61 ++++++++++++++++---------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index 2da20a53..5fa16362 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -79,15 +79,29 @@ else: This allows you to create large groups of sliders in a loop, but still keep track of the individual events''' - def __init__(self, name, callback): + def __init__(self, name, callback, conv_fac): QSlider.__init__(self) self.name = name self.callback = callback + self.conv_fac = conv_fac + + self.name_label = QLabel() + self.name_label.setText(self.name) + self.name_label.setAlignment(QtCore.Qt.AlignCenter) + + self.value_label = QLabel() + self.value_label.setText('') + self.value_label.setAlignment(QtCore.Qt.AlignCenter) # bind this to the valueChanged signal of the slider def i_changed(self, val): + val = self.conv_val() + self.value_label.setText(str(val)[:4]) self.callback(self.name, val) + def conv_val(self): + return self.value() * self.conv_fac + class NSliderBlock(QWidget): '''Creates a block of n sliders with ranges @@ -112,33 +126,33 @@ else: raise ValueError('not enough or too many ranges supplied') self.callback = callback + + # each key will give you self.sliders = {} - self.slider_names = [] self.layout = QtGui.QGridLayout(self) for i in range(n): params = ranges_labels[i] - if len(params) != 4: + if len(params) != 5: raise ValueError('Tuples must be length 4') name = params[3] - slider_name = QLabel() - slider_name.setText(name) - slider_name.setAlignment(QtCore.Qt.AlignCenter) - self.slider_names.append(slider_name) + conv_fac = params[4] - self.layout.addWidget(slider_name, 0, i) - - - slider = IntelligentSlider(name, self.callback) + slider = IntelligentSlider(name, self.callback, conv_fac) slider.setMinimum(params[0]) slider.setMaximum(params[1]) slider.setValue(params[2]) slider.valueChanged.connect(slider.i_changed) + self.sliders[name] = slider - self.layout.addWidget(slider, 1, i) + self.layout.addWidget(slider.name_label, 0, i) + self.layout.addWidget(slider, 1, i, QtCore.Qt.AlignCenter) + self.layout.addWidget(slider.value_label, 2, i) + + self.layout.setColumnMinimumWidth(i, 50) def set_sliders(self, vals): # vals should a dict to of slider names and set vals @@ -184,15 +198,15 @@ else: self.rgb_add.toggled.connect(self.rgb_radio_changed) # additive sliders - self.rgb_add_sliders = NSliderBlock(3, [(-255, 255, 0, 'R'), - (-255, 255, 0, 'G'), - (-255, 255, 0, 'B')], + self.rgb_add_sliders = NSliderBlock(3, [(-255, 255, 0, 'R', 1), + (-255, 255, 0, 'G', 1), + (-255, 255, 0, 'B', 1)], self.rgb_add_changed) # multiplicative sliders - self.rgb_mul_sliders = NSliderBlock(3, [(0, 1000, 500, 'R'), - (0, 1000, 500, 'G'), - (0, 1000, 500, 'B')], + self.rgb_mul_sliders = NSliderBlock(3, [(0, 1000, 500, 'R', .002), + (0, 1000, 500, 'G', .002), + (0, 1000, 500, 'B', .002)], self.rgb_mul_changed) # layout @@ -208,8 +222,8 @@ else: #--------------------------------------------------------------- # sliders - self.bright_sliders = NSliderBlock(2, [(-255, 255, 0, 'OFF'), - (0, 1000, 500, 'FAC')], + self.bright_sliders = NSliderBlock(2, [(-255, 255, 0, '+', 1), + (0, 1000, 500, 'x', 0.002)], self.bright_changed) # layout @@ -260,7 +274,6 @@ else: def rgb_mul_changed(self, name, val): if not self.rgb_mul.isChecked(): return - val = val/500. if name == 'R': self.mixer.multiply(self.mixer.RED, val) elif name == 'G': @@ -274,8 +287,8 @@ else: def bright_changed(self, name, val): # doesnt matter which slider changed we need both # values - factor = self.bright_sliders.sliders['FAC'].value() / 500. - offset = self.bright_sliders.sliders['OFF'].value() + factor = self.bright_sliders.sliders['x'].conv_val() + offset = self.bright_sliders.sliders['+'].conv_val() self.mixer.brightness(offset, factor) self.update() @@ -283,7 +296,7 @@ else: def reset_sliders(self): self.rgb_add_sliders.set_sliders({'R': 0, 'G': 0, 'B': 0}) self.rgb_mul_sliders.set_sliders({'R': 500, 'G': 500, 'B': 500}) - self.bright_sliders.set_sliders({'OFF': 0, 'FAC': 500}) + self.bright_sliders.set_sliders({'+': 0, 'x': 500}) def combo_box_changed(self, index): self.reset_sliders() From 5b3ff5306c0f00f2e339a60d954bba266a928b7e Mon Sep 17 00:00:00 2001 From: sccolbert Date: Wed, 4 Nov 2009 21:10:14 +0100 Subject: [PATCH 10/43] fixed an alignment centering bug. --- scikits/image/io/_plugins/qt_plugin.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index 5fa16362..d2d6c757 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -145,11 +145,10 @@ else: slider.setValue(params[2]) slider.valueChanged.connect(slider.i_changed) - self.sliders[name] = slider self.layout.addWidget(slider.name_label, 0, i) - self.layout.addWidget(slider, 1, i, QtCore.Qt.AlignCenter) + self.layout.addWidget(slider, 1, i, QtCore.Qt.AlignHCenter) self.layout.addWidget(slider.value_label, 2, i) self.layout.setColumnMinimumWidth(i, 50) From f4a042177fc5e25e7dc602b4f74b6a2529b69260 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Wed, 4 Nov 2009 23:10:36 +0100 Subject: [PATCH 11/43] added HSV operations to the ColorMixer and fancy imshow. --- scikits/image/io/_plugins/_colormixer.pyx | 305 ++++++++++++++++++++++ scikits/image/io/_plugins/qt_plugin.py | 67 +++++ scikits/image/io/_plugins/util.py | 49 ++++ 3 files changed, 421 insertions(+) diff --git a/scikits/image/io/_plugins/_colormixer.pyx b/scikits/image/io/_plugins/_colormixer.pyx index ee79bb56..f229f4ea 100644 --- a/scikits/image/io/_plugins/_colormixer.pyx +++ b/scikits/image/io/_plugins/_colormixer.pyx @@ -125,3 +125,308 @@ def brightness(np.ndarray[np.uint8_t, ndim=3] img, img[i, j, k] = 0 else: img[i, j, k] = op_result + +cdef void rgb_2_hsv(float* RGB, float* HSV): + '''Convert an HSV value to RGB. + + Automatic clipping. + + Parameters + ---------- + R : float + From 0. - 255. + G : float + From 0. - 255. + B : float + From 0. - 255. + + Returns + ------- + out : (H, S, V) Floats + Ranges (0...360), (0...1), (0...1) + + conversion convention from here: + http://en.wikipedia.org/wiki/HSL_and_HSV + + ''' + + cdef float R, G, B, H, S, V, MAX, MIN + R = RGB[0] + G = RGB[1] + B = RGB[2] + + if R > 255: + R = 255 + elif R < 0: + R = 0 + else: + pass + + if G > 255: + G = 255 + elif G < 0: + G = 0 + else: + pass + + if B > 255: + B = 255 + elif B < 0: + B = 0 + else: + pass + + if R < G: + MIN = R + MAX = G + else: + MIN = G + MAX = R + + if B < MIN: + MIN = B + elif B > MAX: + MAX = B + else: + pass + + V = MAX / 255. + + if MAX == MIN: + H = 0. + elif MAX == R: + H = (60 * (G - B) / (MAX - MIN)) % 360 + elif MAX == G: + H = 60 * (B - R) / (MAX - MIN) + 120 + else: + H = 60 * (R - G) / (MAX - MIN) + 240 + + if MAX == 0: + S = 0 + else: + S = 1 - MIN / MAX + + HSV[0] = H + HSV[1] = S + HSV[2] = V + +cdef void hsv_2_rgb(float* HSV, float* RGB): + '''Convert an HSV value to RGB. + + Automatic clipping. + + Parameters + ---------- + H : float + From 0. - 360. + S : float + From 0. - 1. + V : float + From 0. - 1. + + Returns + ------- + out : (R, G, B) Floats + Each from 0. - 1. + + conversion convention from here: + http://en.wikipedia.org/wiki/HSL_and_HSV + + ''' + + cdef float H, S, V + cdef float f, p, q, t, r, g, b + cdef int hi + + H = HSV[0] + S = HSV[1] + V = HSV[2] + + if H > 360: + H = 360 + elif H < 0: + H = 0 + else: + pass + + if S > 1: + S = 1 + elif S < 0: + S = 0 + else: + pass + + if V > 1: + V = 1 + elif V < 0: + V = 0 + else: + pass + + hi = ((H / 60.)) % 6 + f = (H / 60.) - ((H / 60.)) + p = V * (1 - S) + q = V * (1 - f * S) + t = V * (1 - (1 -f) * S) + + if hi == 0: + r = V + g = t + b = p + elif hi == 1: + r = q + g = V + b = p + elif hi == 2: + r = p + g = V + b = t + elif hi == 3: + r = p + g = q + b = V + elif hi == 4: + r = t + g = p + b = V + else: + r = V + g = p + b = q + + RGB[0] = r + RGB[1] = g + RGB[2] = b + +@cython.boundscheck(False) +def hsv_add(np.ndarray[np.uint8_t, ndim=3] img, + np.ndarray[np.uint8_t, ndim=3] stateimg, + float h_amt, float s_amt, float v_amt): + """Modify the image color by specifying additive HSV Values. + + Since the underlying images are RGB, all three values HSV + must be specified at the same time. + + The RGB triplet in the image is converted to HSV, the operation + is applied, and then the HSV triplet is converted back to RGB + + HSV values are scaled to H(0. - 360.), S(0. - 1.), V(0. - 1.) + then the operation is performed and any overflow is clipped, then the + reverse transform is performed. Those are the ranges to keep in mind, + when passing in values. + + Parameters + ---------- + img : (M, N, 3) ndarray of uint8 + Output image. + stateimg : (M, N, 3) ndarray of uint8 + Input image. + h_amt : float + Ammount to add to H channel. + s_amt : float + Ammount to add to S channel. + v_amt : float + Ammount to add to V channel. + + + """ + + cdef int height = img.shape[0] + cdef int width = img.shape[1] + + cdef float HSV[3] + cdef float RGB[3] + + cdef int i, j + + for i in range(height): + for j in range(width): + RGB[0] = stateimg[i, j, 0] + RGB[1] = stateimg[i, j, 1] + RGB[2] = stateimg[i, j, 2] + + rgb_2_hsv(RGB, HSV) + + # Add operation + HSV[0] += h_amt + HSV[1] += s_amt + HSV[2] += v_amt + + hsv_2_rgb(HSV, RGB) + + RGB[0] *= 255 + RGB[1] *= 255 + RGB[2] *= 255 + + img[i, j, 0] = RGB[0] + img[i, j, 1] = RGB[1] + img[i, j, 2] = RGB[2] + +@cython.boundscheck(False) +def hsv_multiply(np.ndarray[np.uint8_t, ndim=3] img, + np.ndarray[np.uint8_t, ndim=3] stateimg, + float h_amt, float s_amt, float v_amt): + """Modify the image color by specifying multiplicative HSV Values. + + Since the underlying images are RGB, all three values HSV + must be specified at the same time. + + The RGB triplet in the image is converted to HSV, the operation + is applied, and then the HSV triplet is converted back to RGB + + HSV values are scaled to H(0. - 360.), S(0. - 1.), V(0. - 1.) + then the operation is performed and any overflow is clipped, then the + reverse transform is performed. Those are the ranges to keep in mind, + when passing in values. + + Parameters + ---------- + img : (M, N, 3) ndarray of uint8 + Output image. + stateimg : (M, N, 3) ndarray of uint8 + Input image. + h_amt : float + Ammount to add to H channel. + s_amt : float + Ammount to add to S channel. + v_amt : float + Ammount to add to V channel. + + + """ + + cdef int height = img.shape[0] + cdef int width = img.shape[1] + + cdef float HSV[3] + cdef float RGB[3] + + cdef int i, j + + for i in range(height): + for j in range(width): + RGB[0] = stateimg[i, j, 0] + RGB[1] = stateimg[i, j, 1] + RGB[2] = stateimg[i, j, 2] + + rgb_2_hsv(RGB, HSV) + + # Multiply operation + HSV[0] *= h_amt + HSV[1] *= s_amt + HSV[2] *= v_amt + + hsv_2_rgb(HSV, RGB) + + RGB[0] *= 255 + RGB[1] *= 255 + RGB[2] *= 255 + + img[i, j, 0] = RGB[0] + img[i, j, 1] = RGB[1] + img[i, j, 2] = RGB[2] + + + + + diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index d2d6c757..bd690d89 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -216,6 +216,36 @@ else: self.rgb_widget.layout.addWidget(self.rgb_add_sliders, 2, 0) self.rgb_widget.layout.addWidget(self.rgb_mul_sliders, 2, 0) + #--------------------------------------------------------------- + # HSV sliders + #--------------------------------------------------------------- + + # radio buttons + self.hsv_add = QtGui.QRadioButton('Additive') + self.hsv_mul = QtGui.QRadioButton('Multiplicative') + self.hsv_mul.toggled.connect(self.hsv_radio_changed) + self.hsv_add.toggled.connect(self.hsv_radio_changed) + + # additive sliders + self.hsv_add_sliders = NSliderBlock(3, [(-360, 360, 0, 'H', 1), + (-100, 100, 0, 'S', .01), + (-100, 100, 0, 'V', .01)], + self.hsv_add_changed) + + # multiplicative sliders + self.hsv_mul_sliders = NSliderBlock(3, [(0, 1000, 500, 'H', .002), + (0, 1000, 500, 'S', .002), + (0, 1000, 500, 'V', .002)], + self.hsv_mul_changed) + + # layout + self.hsv_widget = QWidget() + self.hsv_widget.layout = QtGui.QGridLayout(self.hsv_widget) + self.hsv_widget.layout.addWidget(self.hsv_add, 0, 0) + self.hsv_widget.layout.addWidget(self.hsv_mul, 1, 0) + self.hsv_widget.layout.addWidget(self.hsv_add_sliders, 2, 0) + self.hsv_widget.layout.addWidget(self.hsv_mul_sliders, 2, 0) + #--------------------------------------------------------------- # Brightness sliders #--------------------------------------------------------------- @@ -244,6 +274,7 @@ else: self.layout = QtGui.QGridLayout(self) self.layout.addWidget(self.combo_box, 0, 0) self.layout.addWidget(self.rgb_widget, 1, 0) + self.layout.addWidget(self.hsv_widget, 1, 0) self.layout.addWidget(self.bright_widget, 1, 0) self.layout.addWidget(self.commit_button, 2, 0) self.layout.addWidget(self.revert_button, 3, 0) @@ -256,6 +287,7 @@ else: self.hide_sliders() self.rgb_widget.show() self.rgb_add.setChecked(True) + self.hsv_add.setChecked(True) def rgb_add_changed(self, name, val): if not self.rgb_add.isChecked(): @@ -283,6 +315,24 @@ else: return self.update() + def hsv_add_changed(self, name, val): + if not self.hsv_add.isChecked(): + return + h = self.hsv_add_sliders.sliders['H'].conv_val() + s = self.hsv_add_sliders.sliders['S'].conv_val() + v = self.hsv_add_sliders.sliders['V'].conv_val() + self.mixer.hsv_add(h, s, v) + self.update() + + def hsv_mul_changed(self, name, val): + if not self.hsv_mul.isChecked(): + return + h = self.hsv_mul_sliders.sliders['H'].conv_val() + s = self.hsv_mul_sliders.sliders['S'].conv_val() + v = self.hsv_mul_sliders.sliders['V'].conv_val() + self.mixer.hsv_multiply(h, s, v) + self.update() + def bright_changed(self, name, val): # doesnt matter which slider changed we need both # values @@ -295,6 +345,7 @@ else: def reset_sliders(self): self.rgb_add_sliders.set_sliders({'R': 0, 'G': 0, 'B': 0}) self.rgb_mul_sliders.set_sliders({'R': 500, 'G': 500, 'B': 500}) + self.hsv_add_sliders.set_sliders({'H': 0, 'S': 0, 'V': 0}) self.bright_sliders.set_sliders({'+': 0, 'x': 500}) def combo_box_changed(self, index): @@ -307,6 +358,7 @@ else: def hide_sliders(self): self.rgb_widget.hide() + self.hsv_widget.hide() self.bright_widget.hide() def rgb_radio_changed(self): @@ -323,12 +375,27 @@ else: self.mixer.set_to_stateimg() self.update() + def hsv_radio_changed(self): + if self.hsv_add.isChecked(): + self.hsv_add_sliders.show() + self.hsv_mul_sliders.hide() + elif self.hsv_mul.isChecked(): + self.hsv_mul_sliders.show() + self.hsv_add_sliders.hide() + else: + pass + + self.reset_sliders() + self.mixer.set_to_stateimg() + self.update() + def show_rgb(self): self.hide_sliders() self.rgb_widget.show() def show_hsv(self): self.hide_sliders() + self.hsv_widget.show() def show_bright(self): self.hide_sliders() diff --git a/scikits/image/io/_plugins/util.py b/scikits/image/io/_plugins/util.py index 8f32f4e5..2bc21819 100644 --- a/scikits/image/io/_plugins/util.py +++ b/scikits/image/io/_plugins/util.py @@ -244,4 +244,53 @@ class ColorMixer(object): _colormixer.multiply(self.img, self.stateimg, channel, ammount) def brightness(self, offset, factor): + '''Adjust the brightness off an image with an offset and factor. + + Parameters + ---------- + offset : integer + The ammount to add to each channel. + factor : float + The factor to multiply each channel by. + + result = clip((pixel + offset)*factor) + + ''' _colormixer.brightness(self.img, self.stateimg, offset, factor) + + def hsv_add(self, h_amt, s_amt, v_amt): + '''Adjust the H, S, V channels of an image by a constant ammount. + This is similar to the add() mixer function, but operates over the + entire image at once. Thus all three additive values, H, S, V, must + be supplied simultaneously. + + Parameters + ---------- + h_amt : float + The ammount to add to the hue (-360..360) + s_amt : float + The ammount to add to the saturation (-1..1) + v_amt : float + The ammount to add to the value (-1..1) + + ''' + _colormixer.hsv_add(self.img, self.stateimg, h_amt, s_amt, v_amt) + + def hsv_multiply(self, h_amt, s_amt, v_amt): + '''Adjust the H, S, V channels of an image by a constant ammount. + This is similar to the add() mixer function, but operates over the + entire image at once. Thus all three additive values, H, S, V, must + be supplied simultaneously. + + Parameters + ---------- + h_amt : float + The ammount to multiply to the hue (0..1) + s_amt : float + The ammount to multiply to the saturation (0..1) + v_amt : float + The ammount to multiply to the value (0..1) + + ''' + _colormixer.hsv_multiply(self.img, self.stateimg, h_amt, s_amt, v_amt) + From 93fb7de121ca3419aa6ac0e7f983acacfa651084 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Thu, 5 Nov 2009 01:36:08 +0100 Subject: [PATCH 12/43] Finalized HSV support in the color-mixer and fixed a few subtle bugs therein. Updated the fancy imshow widget some more. --- scikits/image/io/_plugins/_colormixer.pyx | 142 ++++++++++++++-------- scikits/image/io/_plugins/qt_plugin.py | 85 ++++++++++--- scikits/image/io/_plugins/util.py | 50 +++++++- 3 files changed, 208 insertions(+), 69 deletions(-) diff --git a/scikits/image/io/_plugins/_colormixer.pyx b/scikits/image/io/_plugins/_colormixer.pyx index f229f4ea..9f1f01a3 100644 --- a/scikits/image/io/_plugins/_colormixer.pyx +++ b/scikits/image/io/_plugins/_colormixer.pyx @@ -126,30 +126,8 @@ def brightness(np.ndarray[np.uint8_t, ndim=3] img, else: img[i, j, k] = op_result + cdef void rgb_2_hsv(float* RGB, float* HSV): - '''Convert an HSV value to RGB. - - Automatic clipping. - - Parameters - ---------- - R : float - From 0. - 255. - G : float - From 0. - 255. - B : float - From 0. - 255. - - Returns - ------- - out : (H, S, V) Floats - Ranges (0...360), (0...1), (0...1) - - conversion convention from here: - http://en.wikipedia.org/wiki/HSL_and_HSV - - ''' - cdef float R, G, B, H, S, V, MAX, MIN R = RGB[0] G = RGB[1] @@ -195,7 +173,7 @@ cdef void rgb_2_hsv(float* RGB, float* HSV): if MAX == MIN: H = 0. elif MAX == R: - H = (60 * (G - B) / (MAX - MIN)) % 360 + H = (60 * (G - B) / (MAX - MIN) + 360) % 360 elif MAX == G: H = 60 * (B - R) / (MAX - MIN) + 120 else: @@ -210,30 +188,8 @@ cdef void rgb_2_hsv(float* RGB, float* HSV): HSV[1] = S HSV[2] = V + cdef void hsv_2_rgb(float* HSV, float* RGB): - '''Convert an HSV value to RGB. - - Automatic clipping. - - Parameters - ---------- - H : float - From 0. - 360. - S : float - From 0. - 1. - V : float - From 0. - 1. - - Returns - ------- - out : (R, G, B) Floats - Each from 0. - 1. - - conversion convention from here: - http://en.wikipedia.org/wiki/HSL_and_HSV - - ''' - cdef float H, S, V cdef float f, p, q, t, r, g, b cdef int hi @@ -243,9 +199,9 @@ cdef void hsv_2_rgb(float* HSV, float* RGB): V = HSV[2] if H > 360: - H = 360 + H = H % 360 elif H < 0: - H = 0 + H = 360 - ((-1 * H) % 360) else: pass @@ -298,6 +254,84 @@ cdef void hsv_2_rgb(float* HSV, float* RGB): RGB[1] = g RGB[2] = b + +def py_hsv_2_rgb(H, S, V): + '''Convert an HSV value to RGB. + + Automatic clipping. + + Parameters + ---------- + H : float + From 0. - 360. + S : float + From 0. - 1. + V : float + From 0. - 1. + + Returns + ------- + out : (R, G, B) ints + Each from 0 - 255 + + conversion convention from here: + http://en.wikipedia.org/wiki/HSL_and_HSV + + ''' + cdef float HSV[3] + cdef float RGB[3] + + HSV[0] = H + HSV[1] = S + HSV[2] = V + + hsv_2_rgb(HSV, RGB) + + R = int(RGB[0] * 255) + G = int(RGB[1] * 255) + B = int(RGB[2] * 255) + + return (R, G, B) + +def py_rgb_2_hsv(R, G, B): + '''Convert an HSV value to RGB. + + Automatic clipping. + + Parameters + ---------- + R : int + From 0. - 255. + G : int + From 0. - 255. + B : int + From 0. - 255. + + Returns + ------- + out : (H, S, V) floats + Ranges (0...360), (0...1), (0...1) + + conversion convention from here: + http://en.wikipedia.org/wiki/HSL_and_HSV + + ''' + cdef float HSV[3] + cdef float RGB[3] + + RGB[0] = R + RGB[1] = G + RGB[2] = B + + rgb_2_hsv(RGB, HSV) + + H = HSV[0] + S = HSV[1] + V = HSV[2] + + return (H, S, V) + + @cython.boundscheck(False) def hsv_add(np.ndarray[np.uint8_t, ndim=3] img, np.ndarray[np.uint8_t, ndim=3] stateimg, @@ -379,6 +413,10 @@ def hsv_multiply(np.ndarray[np.uint8_t, ndim=3] img, reverse transform is performed. Those are the ranges to keep in mind, when passing in values. + Note that since hue is in degrees, it makes no sense to multiply + that channel, thus an add operation is performed on the hue. And the + values given for h_amt, should be the same as for hsv_add + Parameters ---------- img : (M, N, 3) ndarray of uint8 @@ -388,9 +426,9 @@ def hsv_multiply(np.ndarray[np.uint8_t, ndim=3] img, h_amt : float Ammount to add to H channel. s_amt : float - Ammount to add to S channel. + Ammount by which to multiply S channel. v_amt : float - Ammount to add to V channel. + Ammount by which to multiply V channel. """ @@ -412,7 +450,7 @@ def hsv_multiply(np.ndarray[np.uint8_t, ndim=3] img, rgb_2_hsv(RGB, HSV) # Multiply operation - HSV[0] *= h_amt + HSV[0] += h_amt HSV[1] *= s_amt HSV[2] *= v_amt diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index bd690d89..b39476b1 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -55,11 +55,11 @@ else: QMainWindow.__init__(self) self.mgr = mgr self.main_widget = QWidget() - self.layout = QtGui.QHBoxLayout(self.main_widget) + self.layout = QtGui.QGridLayout(self.main_widget) self.setCentralWidget(self.main_widget) self.label = LabelImage(self, arr) - self.layout.addWidget(self.label) + self.layout.addWidget(self.label, 0, 0) self.mgr.add_window(self) self.main_widget.show() @@ -227,13 +227,13 @@ else: self.hsv_add.toggled.connect(self.hsv_radio_changed) # additive sliders - self.hsv_add_sliders = NSliderBlock(3, [(-360, 360, 0, 'H', 1), + self.hsv_add_sliders = NSliderBlock(3, [(-180, 180, 0, 'H', 1), (-100, 100, 0, 'S', .01), (-100, 100, 0, 'V', .01)], self.hsv_add_changed) # multiplicative sliders - self.hsv_mul_sliders = NSliderBlock(3, [(0, 1000, 500, 'H', .002), + self.hsv_mul_sliders = NSliderBlock(3, [(-180, 180, 0, 'H', 1), (0, 1000, 500, 'S', .002), (0, 1000, 500, 'V', .002)], self.hsv_mul_changed) @@ -286,8 +286,8 @@ else: self.combo_box.setCurrentIndex(0) self.hide_sliders() self.rgb_widget.show() - self.rgb_add.setChecked(True) - self.hsv_add.setChecked(True) + self.rgb_mul.setChecked(True) + self.hsv_mul.setChecked(True) def rgb_add_changed(self, name, val): if not self.rgb_add.isChecked(): @@ -346,6 +346,7 @@ else: self.rgb_add_sliders.set_sliders({'R': 0, 'G': 0, 'B': 0}) self.rgb_mul_sliders.set_sliders({'R': 500, 'G': 500, 'B': 500}) self.hsv_add_sliders.set_sliders({'H': 0, 'S': 0, 'V': 0}) + self.hsv_mul_sliders.set_sliders({'H': 0, 'S': 500, 'V': 500}) self.bright_sliders.set_sliders({'+': 0, 'x': 500}) def combo_box_changed(self, index): @@ -414,20 +415,76 @@ else: self.update() + class RGBHSVDisplay(QWidget): + def __init__(self): + QWidget.__init__(self) + self.posx_label = QLabel('X-pos:') + self.posx_value = QLabel() + self.posy_label = QLabel('Y-pos:') + self.posy_value = QLabel() + self.r_label = QLabel('R:') + self.r_value = QLabel() + self.g_label = QLabel('G:') + self.g_value = QLabel() + self.b_label = QLabel('B:') + self.b_value = QLabel() + self.h_label = QLabel('H:') + self.h_value = QLabel() + self.s_label = QLabel('S:') + self.s_value = QLabel() + self.v_label = QLabel('V:') + self.v_value = QLabel() + + self.layout = QtGui.QGridLayout(self) + self.layout.addWidget(self.posx_label, 0, 0) + self.layout.addWidget(self.posx_value, 0, 1) + self.layout.addWidget(self.posy_label, 1, 0) + self.layout.addWidget(self.posy_value, 1, 1) + self.layout.addWidget(self.r_label, 0, 2) + self.layout.addWidget(self.r_value, 0, 3) + self.layout.addWidget(self.g_label, 1, 2) + self.layout.addWidget(self.g_value, 1, 3) + self.layout.addWidget(self.b_label, 2, 2) + self.layout.addWidget(self.b_value, 2, 3) + self.layout.addWidget(self.h_label, 0, 4) + self.layout.addWidget(self.h_value, 0, 5) + self.layout.addWidget(self.s_label, 1, 4) + self.layout.addWidget(self.s_value, 1, 5) + self.layout.addWidget(self.v_label, 2, 4) + self.layout.addWidget(self.v_value, 2, 5) + + def update_vals(self, data): + xpos, ypos, r, g, b, h, s, v = data + self.posx_value.setText(str(xpos)[:5]) + self.posy_value.setText(str(ypos)[:5]) + self.r_value.setText(str(r)[:5]) + self.g_value.setText(str(g)[:5]) + self.b_value.setText(str(b)[:5]) + self.h_value.setText(str(h)[:5]) + self.s_value.setText(str(s)[:5]) + self.v_value.setText(str(v)[:5]) + class FancyImageWindow(ImageWindow): def __init__(self, arr, mgr): ImageWindow.__init__(self, arr, mgr) self.arr = arr - self.statusBar().showMessage('X: Y: ') self.label.setScaledContents(True) self.label.setMouseTracking(True) + self.label.setMinimumSize(QtCore.QSize(100, 100)) self.mixer_panel = MixerPanel(self.arr, self.refresh_image) - self.layout.addWidget(self.mixer_panel) + self.layout.addWidget(self.mixer_panel, 0, 1, 2, 1) self.mixer_panel.show() + self.rgb_hsv_disp = RGBHSVDisplay() + self.layout.addWidget(self.rgb_hsv_disp, 1, 0) + self.rgb_hsv_disp.show() + + self.layout.setColumnStretch(0, 1) + self.layout.setRowStretch(0, 1) + def refresh_image(self): pm = QPixmap.fromImage(self.label.img) self.label.setPixmap(pm) @@ -447,17 +504,15 @@ else: x = evt.x() y = evt.y() x, y = self.scale_mouse_pos(x, y) - msg = 'X: %d, Y: %d ' % (x, y) - R = self.arr[y,x,0] - G = self.arr[y,x,1] - B = self.arr[y,x,2] - msg += 'R: %s, G:, %s, B: %s' % (R, G, B) - self.statusBar().showMessage(msg) + r = self.arr[y,x,0] + g = self.arr[y,x,1] + b = self.arr[y,x,2] + h, s, v = self.mixer_panel.mixer.rgb_2_hsv_pixel(r, g, b) + self.rgb_hsv_disp.update_vals((x, y, r, g, b, h, s, v)) def imshow(arr, fancy=False): global app - if not app: app = QApplication([]) diff --git a/scikits/image/io/_plugins/util.py b/scikits/image/io/_plugins/util.py index 2bc21819..69886fc5 100644 --- a/scikits/image/io/_plugins/util.py +++ b/scikits/image/io/_plugins/util.py @@ -267,7 +267,7 @@ class ColorMixer(object): Parameters ---------- h_amt : float - The ammount to add to the hue (-360..360) + The ammount to add to the hue (-180..180) s_amt : float The ammount to add to the saturation (-1..1) v_amt : float @@ -282,10 +282,14 @@ class ColorMixer(object): entire image at once. Thus all three additive values, H, S, V, must be supplied simultaneously. + Note that since hue is in degrees, it makes no sense to multiply + that channel, thus an add operation is performed on the hue. And the + values given for h_amt, should be the same as for hsv_add + Parameters ---------- h_amt : float - The ammount to multiply to the hue (0..1) + The ammount to to add to the hue (-180..180) s_amt : float The ammount to multiply to the saturation (0..1) v_amt : float @@ -294,3 +298,45 @@ class ColorMixer(object): ''' _colormixer.hsv_multiply(self.img, self.stateimg, h_amt, s_amt, v_amt) + + def rgb_2_hsv_pixel(self, R, G, B): + '''Convert an RGB value to HSV + + Parameters + ---------- + R : int + Red value + G : int + Green value + B : int + Blue value + + Returns + ------- + out : (H, S, V) Floats + The HSV values + + ''' + H, S, V = _colormixer.py_rgb_2_hsv(R, G, B) + return (H, S, V) + + def hsv_2_rgb_pixel(self, H, S, V): + '''Convert an HSV value to RGB + + Parameters + ---------- + H : float + Hue value + S : float + Saturation value + V : float + Intensity value + + Returns + ------- + out : (R, G, B) ints + The RGB values + + ''' + R, G, B = _colormixer.py_hsv_2_rgb(H, S, V) + return (R, G, B) \ No newline at end of file From efbaa849dddf2bbc962a7d4c8feb3437646a98e6 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Fri, 6 Nov 2009 02:24:03 +0100 Subject: [PATCH 13/43] added histograms to fancy imshow and colormixer. Unfortunately im suffering from circular references when the window is initializing. It doesnt crash, but it throws a few exceptions... A refactor is in order. --- scikits/image/io/_plugins/_colormixer.pyx | 62 ++++++++ scikits/image/io/_plugins/qt_plugin.py | 167 +++++++++++++++++++++- scikits/image/io/_plugins/util.py | 21 ++- 3 files changed, 247 insertions(+), 3 deletions(-) diff --git a/scikits/image/io/_plugins/_colormixer.pyx b/scikits/image/io/_plugins/_colormixer.pyx index 9f1f01a3..73127d52 100644 --- a/scikits/image/io/_plugins/_colormixer.pyx +++ b/scikits/image/io/_plugins/_colormixer.pyx @@ -464,6 +464,68 @@ def hsv_multiply(np.ndarray[np.uint8_t, ndim=3] img, img[i, j, 1] = RGB[1] img[i, j, 2] = RGB[2] +@cython.boundscheck(False) +def histograms(np.ndarray[np.uint8_t, ndim=3] img, int nbins): + '''Calculate the channel histograms of the current image. + + Parameters + ---------- + img : ndarray, uint8, ndim=3 + The image to calculate the histogram. + nbins : int + The number of bins. + + Returns + ------- + out : (rcounts, gcounts, bcounts, vcounts) + The binned histograms of the RGB channels and grayscale intensity. + + This is a NAIVE histogram routine, meant primarily for fast display. + + ''' + cdef int width = img.shape[1] + cdef int height = img.shape[0] + cdef np.ndarray[np.int32_t, ndim=1] r + cdef np.ndarray[np.int32_t, ndim=1] g + cdef np.ndarray[np.int32_t, ndim=1] b + cdef np.ndarray[np.int32_t, ndim=1] v + + r = np.zeros((nbins,), dtype=np.int32) + g = np.zeros((nbins,), dtype=np.int32) + b = np.zeros((nbins,), dtype=np.int32) + v = np.zeros((nbins,), dtype=np.int32) + + cdef int i, j, k, rbin, gbin, bbin, vbin + cdef float bin_width = 255./ nbins + cdef np.uint8_t R, G, B, V + + for i in range(height): + for j in range(width): + R = img[i, j, 0] + G = img[i, j, 1] + B = img[i, j, 2] + V = (0.3 * R + 0.59 * G + 0.11 * B) + + rbin = (R / bin_width) + gbin = (G / bin_width) + bbin = (B / bin_width) + vbin = (V / bin_width) + + if rbin == nbins: + rbin -= 1 + if gbin == nbins: + gbin -= 1 + if bbin == nbins: + gbin -= 1 + if vbin == nbins: + vbin -= 1 + + r[rbin] += 1 + g[gbin] += 1 + b[bbin] += 1 + v[vbin] += 1 + + return (r, g, b, v) diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index b39476b1..0531a114 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -14,7 +14,8 @@ except GuiLockError, gle: else: try: from PyQt4.QtGui import (QApplication, QMainWindow, QImage, QPixmap, - QLabel, QWidget, QVBoxLayout, QSlider) + QLabel, QWidget, QVBoxLayout, QSlider, + QPainter, QColor, QFrame) from PyQt4 import QtCore, QtGui except ImportError: @@ -465,6 +466,121 @@ else: self.v_value.setText(str(v)[:5]) + class Histogram(QWidget): + '''A Class which draws a scaling histogram in + a widget. + + The argument to the constructor 'vals' is a list of tuples + of the following form: + + vals = [(counts, colormap)] + + where counts are the bin values in the histogram + and colormap is a tuple of (R, G, B) tuples the same length + as counts. These are the colors to apply to the histogram bars. + Colormap can also contain a single tuple, in which case this is + the color applied to all bars of that histogram. + + Each histogram is drawn in order from left to right in its own + box and the values are scaled so that max(count) = height. + This is a linear scaling. + + The histogram assumes the bins were evenly spaced. + ''' + + def __init__(self, counts, colormap): + QWidget.__init__(self) + self._validate_input(counts, colormap) + self.counts = counts + self.n = np.sum(self.counts) + self.colormap = colormap + self.setMinimumSize(100, 50) + + def _validate_input(self, counts, colormap): + if len(counts) != len(colormap): + if len(colormap) != 1: + msg = 'Colormap must be same length as count or 1' + raise ValueError(msg) + + def paintEvent(self, evt): + # get the widget dimensions + orig_width = self.width() + orig_height = self.height() + + # fill perc % of the widget + perc = 1.0 + width = int(orig_width * perc) + height = int(orig_height * perc) + + # get the starting origin + x_orig = int((orig_width - width) / 2) + # we want to start at the bottom and draw up. + y_orig = orig_height - int((orig_height - height) / 2) + + # a running x-position + running_pos = x_orig + + # calculate to number of bars + nbars = len(self.counts) + + + # calculate the bar widths, this compilcation is + # necessary because integer trunction severly cripples + # the layout. + remainder = width % nbars + bar_width = [int(width / nbars)] * nbars + for i in range(remainder): + bar_width[i]+=1 + + paint = QPainter() + paint.begin(self) + + if len(self.colormap) == 1: + self.colormap = self.colormap * len(self.counts) + + # determine the scaling factor + max_val = np.max(self.counts) + scale = 1. * height / max_val + + # draw the bars for this graph + for i in range(len(self.counts)): + bar_height = self.counts[i] * scale + r, g, b = self.colormap[i] + paint.setPen(QColor(r, g, b)) + paint.setBrush(QColor(r, g, b)) + paint.drawRect(running_pos, y_orig, bar_width[i], -bar_height) + running_pos += bar_width[i] + + paint.end() + + + def update_hist(self, counts, cmap): + self._validate_input(counts, cmap) + self.counts = counts + self.colormap = cmap + self.repaint() + + + + class MultiHist(QFrame): + def __init__(self, vals): + QFrame.__init__(self) + + self.hists = [] + for counts, cmap in vals: + self.hists.append(Histogram(counts, cmap)) + + self.layout = QtGui.QGridLayout(self) + for i in range(len(self.hists))[::-1]: + self.layout.addWidget(self.hists[i], i, 0) + + + def update_hists(self, vals): + for i in range(len(vals)): + counts, cmap = vals[i] + self.hists[i].update_hist(counts, cmap) + + class FancyImageWindow(ImageWindow): def __init__(self, arr, mgr): ImageWindow.__init__(self, arr, mgr) @@ -475,9 +591,13 @@ else: self.label.setMinimumSize(QtCore.QSize(100, 100)) self.mixer_panel = MixerPanel(self.arr, self.refresh_image) - self.layout.addWidget(self.mixer_panel, 0, 1, 2, 1) + self.layout.addWidget(self.mixer_panel, 0, 2) self.mixer_panel.show() + self.rgb_hist = MultiHist(self.calc_hist()) + self.layout.addWidget(self.rgb_hist, 0, 1) + self.rgb_hist.show() + self.rgb_hsv_disp = RGBHSVDisplay() self.layout.addWidget(self.rgb_hsv_disp, 1, 0) self.rgb_hsv_disp.show() @@ -485,9 +605,52 @@ else: self.layout.setColumnStretch(0, 1) self.layout.setRowStretch(0, 1) + # hook up the mixer sliders move events to trigger a + # histogram redraw. + self.mixer_panel.rgb_add_sliders.sliders['R'].\ + sliderMoved.connect(self.update_histogram) + self.mixer_panel.rgb_add_sliders.sliders['G'].\ + sliderMoved.connect(self.update_histogram) + self.mixer_panel.rgb_add_sliders.sliders['B'].\ + sliderMoved.connect(self.update_histogram) + self.mixer_panel.rgb_mul_sliders.sliders['R'].\ + sliderMoved.connect(self.update_histogram) + self.mixer_panel.rgb_mul_sliders.sliders['G'].\ + sliderMoved.connect(self.update_histogram) + self.mixer_panel.rgb_mul_sliders.sliders['B'].\ + sliderMoved.connect(self.update_histogram) + self.mixer_panel.hsv_add_sliders.sliders['H'].\ + sliderMoved.connect(self.update_histogram) + self.mixer_panel.hsv_add_sliders.sliders['S'].\ + sliderMoved.connect(self.update_histogram) + self.mixer_panel.hsv_add_sliders.sliders['V'].\ + sliderMoved.connect(self.update_histogram) + self.mixer_panel.hsv_mul_sliders.sliders['H'].\ + sliderMoved.connect(self.update_histogram) + self.mixer_panel.hsv_mul_sliders.sliders['S'].\ + sliderMoved.connect(self.update_histogram) + self.mixer_panel.hsv_mul_sliders.sliders['V'].\ + sliderMoved.connect(self.update_histogram) + self.mixer_panel.bright_sliders.sliders['+'].\ + sliderMoved.connect(self.update_histogram) + self.mixer_panel.bright_sliders.sliders['x'].\ + sliderMoved.connect(self.update_histogram) + + def update_histogram(self): + self.rgb_hist.update_hists(self.calc_hist()) + + def calc_hist(self): + rvals, gvals, bvals, grays = \ + self.mixer_panel.mixer.histograms(100) + + vals = ((rvals, ((255,0,0),)),(gvals, ((0,255,0),)), + (bvals, ((0,0,255),)), (grays, ((0, 0, 0),))) + return vals + def refresh_image(self): pm = QPixmap.fromImage(self.label.img) self.label.setPixmap(pm) + self.update_histogram() def scale_mouse_pos(self, x, y): width = self.label.width() diff --git a/scikits/image/io/_plugins/util.py b/scikits/image/io/_plugins/util.py index 69886fc5..c6f0dbe7 100644 --- a/scikits/image/io/_plugins/util.py +++ b/scikits/image/io/_plugins/util.py @@ -339,4 +339,23 @@ class ColorMixer(object): ''' R, G, B = _colormixer.py_hsv_2_rgb(H, S, V) - return (R, G, B) \ No newline at end of file + return (R, G, B) + + def histograms(self, nbins): + '''Calculate the channel histograms of the current image. + + Parameters + ---------- + nbins : int + The number of bins. + + Returns + ------- + out : (rcounts, gcounts, bcounts, vcounts) + The binned histograms of the RGB channels and grayscale intensity. + + This is a NAIVE histogram routine, meant primarily for fast display. + + ''' + + return _colormixer.histograms(self.img, nbins) \ No newline at end of file From 00debb650c6f65cc80a9d982d1a3df93aba191ed Mon Sep 17 00:00:00 2001 From: sccolbert Date: Fri, 6 Nov 2009 13:02:39 +0100 Subject: [PATCH 14/43] added sigmoidal gamma --- scikits/image/io/_plugins/_colormixer.pyx | 49 +++++++++++++++++++++-- scikits/image/io/_plugins/qt_plugin.py | 49 ++++++++++++++++++++--- scikits/image/io/_plugins/util.py | 3 ++ 3 files changed, 93 insertions(+), 8 deletions(-) diff --git a/scikits/image/io/_plugins/_colormixer.pyx b/scikits/image/io/_plugins/_colormixer.pyx index 73127d52..c1291e78 100644 --- a/scikits/image/io/_plugins/_colormixer.pyx +++ b/scikits/image/io/_plugins/_colormixer.pyx @@ -14,6 +14,10 @@ cimport numpy as np import cython +cdef extern from "math.h": + float exp(float) + + @cython.boundscheck(False) def add(np.ndarray[np.uint8_t, ndim=3] img, np.ndarray[np.uint8_t, ndim=3] stateimg, @@ -51,6 +55,7 @@ def add(np.ndarray[np.uint8_t, ndim=3] img, else: img[i, j, k] = op_result + @cython.boundscheck(False) def multiply(np.ndarray[np.uint8_t, ndim=3] img, np.ndarray[np.uint8_t, ndim=3] stateimg, @@ -88,13 +93,14 @@ def multiply(np.ndarray[np.uint8_t, ndim=3] img, else: img[i, j, k] = op_result + @cython.boundscheck(False) def brightness(np.ndarray[np.uint8_t, ndim=3] img, np.ndarray[np.uint8_t, ndim=3] stateimg, int offset, float factor): """Modify the brightness of an image. - 'offset' is added to all channels, which are - then multiplied by 'factor'. Overflow is clipped. + 'factor' is multiplied to all channels, which are + then added by 'amount'. Overflow is clipped. Parameters ---------- @@ -118,7 +124,8 @@ def brightness(np.ndarray[np.uint8_t, ndim=3] img, for i in range(height): for j in range(width): for k in range(3): - op_result = ((stateimg[i,j,k] + offset)*factor) + op_result = ((stateimg[i,j,k] * factor + offset)) + if op_result > 255: img[i, j, k] = 255 elif op_result < 0: @@ -127,6 +134,42 @@ def brightness(np.ndarray[np.uint8_t, ndim=3] img, img[i, j, k] = op_result +@cython.boundscheck(False) +def sigmoid_gamma(np.ndarray[np.uint8_t, ndim=3] img, + np.ndarray[np.uint8_t, ndim=3] stateimg, + float alpha, float beta): + + cdef int height = img.shape[0] + cdef int width = img.shape[1] + + cdef float c1, c2, r, g, b + + cdef int i, j, k + for i in range(height): + for j in range(width): + r = stateimg[i,j,0] / 255. + g = stateimg[i,j,1] / 255. + b = stateimg[i,j,2] / 255. + + c1 = 1 / (1 + exp(beta)) + c2 = 1 / (1 + exp(beta - alpha)) - c1 + + r = 1 / (1 + exp(beta - r * alpha)) + r = (r - c1) / c2 + + g = 1 / (1 + exp(beta - g * alpha)) + g = (g - c1) / c2 + + b = 1 / (1 + exp(beta - b * alpha)) + b = (b - c1) / c2 + + img[i,j,0] = (r * 255) + img[i,j,1] = (g * 255) + img[i,j,2] = (b * 255) + + + + cdef void rgb_2_hsv(float* RGB, float* HSV): cdef float R, G, B, H, S, V, MAX, MIN R = RGB[0] diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index 0531a114..a7d95a98 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -181,7 +181,8 @@ else: #--------------------------------------------------------------- self.combo_box_entries = ['RGB Color', 'HSV Color', - 'Brightness', 'Contrast'] + 'Brightness/Contrast', + 'Gamma (Sigmoidal)'] self.combo_box = QtGui.QComboBox() for entry in self.combo_box_entries: self.combo_box.addItem(entry) @@ -252,8 +253,9 @@ else: #--------------------------------------------------------------- # sliders - self.bright_sliders = NSliderBlock(2, [(-255, 255, 0, '+', 1), - (0, 1000, 500, 'x', 0.002)], + self.bright_sliders = NSliderBlock(2, + [(0, 1000, 500, 'x', 0.002), + (-255, 255, 0, '+', 1)], self.bright_changed) # layout @@ -261,6 +263,20 @@ else: self.bright_widget.layout = QtGui.QGridLayout(self.bright_widget) self.bright_widget.layout.addWidget(self.bright_sliders, 0, 0) + #--------------------------------------------------------------- + # Gamma sliders + #--------------------------------------------------------------- + # sliders + self.gamma_sliders = NSliderBlock(2, + [(100, 1200, 100, 'alpha', 0.01), + (0, 1200, 0, 'beta', 0.01)], + self.gamma_changed) + + # layout + self.gamma_widget = QWidget() + self.gamma_widget.layout = QtGui.QGridLayout(self.gamma_widget) + self.gamma_widget.layout.addWidget(self.gamma_sliders, 0, 0) + #--------------------------------------------------------------- # Buttons #--------------------------------------------------------------- @@ -276,7 +292,9 @@ else: self.layout.addWidget(self.combo_box, 0, 0) self.layout.addWidget(self.rgb_widget, 1, 0) self.layout.addWidget(self.hsv_widget, 1, 0) + self.layout.addWidget(self.gamma_widget, 1, 0) self.layout.addWidget(self.bright_widget, 1, 0) + self.layout.addWidget(self.commit_button, 2, 0) self.layout.addWidget(self.revert_button, 3, 0) @@ -342,6 +360,16 @@ else: self.mixer.brightness(offset, factor) self.update() + def gamma_changed(self, name, val): + # doesnt matter which slider changed we need both + # values + alpha = self.gamma_sliders.sliders['alpha'].conv_val() + beta = self.gamma_sliders.sliders['beta'].conv_val() + self.mixer.sigmoid_gamma(alpha, beta) + self.update() + + def iter_all_sliders(self): + pass def reset_sliders(self): self.rgb_add_sliders.set_sliders({'R': 0, 'G': 0, 'B': 0}) @@ -349,19 +377,21 @@ else: self.hsv_add_sliders.set_sliders({'H': 0, 'S': 0, 'V': 0}) self.hsv_mul_sliders.set_sliders({'H': 0, 'S': 500, 'V': 500}) self.bright_sliders.set_sliders({'+': 0, 'x': 500}) + self.gamma_sliders.set_sliders({'alpha': 100, 'beta': 0}) def combo_box_changed(self, index): self.reset_sliders() self.mixer.set_to_stateimg() self.update() combo_box_map={0: self.show_rgb, 1: self.show_hsv, - 2: self.show_bright, 3: self.show_contrast} + 2: self.show_bright, 3: self.show_gamma} combo_box_map[index]() def hide_sliders(self): self.rgb_widget.hide() self.hsv_widget.hide() self.bright_widget.hide() + self.gamma_sliders.hide() def rgb_radio_changed(self): if self.rgb_add.isChecked(): @@ -403,8 +433,9 @@ else: self.hide_sliders() self.bright_widget.show() - def show_contrast(self): + def show_gamma(self): self.hide_sliders() + self.gamma_sliders.show() def commit_changes(self): self.mixer.commit_changes() @@ -605,6 +636,14 @@ else: self.layout.setColumnStretch(0, 1) self.layout.setRowStretch(0, 1) + self.save_file = QtGui.QPushButton('Save to File') + self.save_variable = QtGui.QPushButton('Save to Variable') + self.save_file.show() + self.save_variable.show() + + self.layout.addWidget(self.save_variable, 1, 1) + self.layout.addWidget(self.save_file, 1, 2) + # hook up the mixer sliders move events to trigger a # histogram redraw. self.mixer_panel.rgb_add_sliders.sliders['R'].\ diff --git a/scikits/image/io/_plugins/util.py b/scikits/image/io/_plugins/util.py index c6f0dbe7..7caff221 100644 --- a/scikits/image/io/_plugins/util.py +++ b/scikits/image/io/_plugins/util.py @@ -258,6 +258,9 @@ class ColorMixer(object): ''' _colormixer.brightness(self.img, self.stateimg, offset, factor) + def sigmoid_gamma(self, alpha, beta): + _colormixer.sigmoid_gamma(self.img, self.stateimg, alpha, beta) + def hsv_add(self, h_amt, s_amt, v_amt): '''Adjust the H, S, V channels of an image by a constant ammount. This is similar to the add() mixer function, but operates over the From e21ab2e2ada22ae19290116b5846e7c115b110f3 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Fri, 6 Nov 2009 14:42:46 +0100 Subject: [PATCH 15/43] progress commit --- scikits/image/io/_plugins/q_color_mixer.py | 309 +++++++++++++++++ scikits/image/io/_plugins/qt_plugin.py | 381 +-------------------- 2 files changed, 314 insertions(+), 376 deletions(-) create mode 100644 scikits/image/io/_plugins/q_color_mixer.py diff --git a/scikits/image/io/_plugins/q_color_mixer.py b/scikits/image/io/_plugins/q_color_mixer.py new file mode 100644 index 00000000..e5e4c26d --- /dev/null +++ b/scikits/image/io/_plugins/q_color_mixer.py @@ -0,0 +1,309 @@ +# the module for the qt color_mixer plugin +from PyQt4 import QtGui, QtCore +from PyQt4.QtGui import (QWidget, QStackedWidget, QSlider, QVBoxLayout, + QGridLayout, QLabel) + +from util import ColorMixer + + + + +class IntelligentSlider(QWidget): + ''' A slider that adds a 'name' attribute and calls a callback + with 'name' as an argument to the registerd callback. + + This allows you to create large groups of sliders in a loop, + but still keep track of the individual events + + It also prints a label below the slider. + + The range of the slider is hardcoded from zero - 1000, + but it supports a conversion factor so you can scale the results''' + + def __init__(self, name, a, b, callback): + QWidget.__init__(self) + self.name = name + self.callback = callback + self.a = a + self.b = b + + self.slider = QSlider() + self.slider.setRange(0, 1000) + self.slider.setValue(500) + self.slider.valueChanged.connect(self.slider_changed) + + self.name_label = QLabel() + self.name_label.setText(self.name) + self.name_label.setAlignment(QtCore.Qt.AlignCenter) + + self.value_label = QLabel() + self.value_label.setText(str(self.slider.value() * self.a + self.b)) + self.value_label.setAlignment(QtCore.Qt.AlignCenter) + + self.layout = QVBoxLayout(self) + self.layout.addWidget(self.name_label) + self.layout.addWidget(self.slider) + self.layout.addWidget(self.value_label) + + # bind this to the valueChanged signal of the slider + def slider_changed(self, val): + val = self.val() + self.value_label.setText(str(val)[:4]) + self.callback(self.name, val) + + def set_conv_fac(self, a, b): + self.a = a + self.b = b + + def set_value(self, val): + self.slider.setValue(int((val - self.a) / self.b)) + + def val(self): + return self.value() * self.a + self.b + + +class MixerPanel(QWidget): + '''A color mixer to hook up to an image. + You pass the image you the panel to operate on + and it operates on that image in place. You also + pass a callback to be called to trigger a refresh. + This callback is called every time the mixer modifies + your image.''' + def __init__(self, img): + QWidget.__init__(self) + + self.img = img + self.mixer = ColorMixer(self.img) + + #--------------------------------------------------------------- + # ComboBox + #--------------------------------------------------------------- + + self.combo_box_entries = ['RGB Color', 'HSV Color', + 'Brightness/Contrast', + 'Gamma (Sigmoidal)'] + self.combo_box = QtGui.QComboBox() + for entry in self.combo_box_entries: + self.combo_box.addItem(entry) + self.combo_box.currentIndexChanged.connect(self.combo_box_changed) + + #--------------------------------------------------------------- + # RGB color sliders + #--------------------------------------------------------------- + + # radio buttons + self.rgb_add = QtGui.QRadioButton('Additive') + self.rgb_mul = QtGui.QRadioButton('Multiplicative') + self.rgb_mul.toggled.connect(self.rgb_radio_changed) + self.rgb_add.toggled.connect(self.rgb_radio_changed) + + # sliders + rs = IntelligentSlider('R', 0.51, -255, self.rgb_changed) + gs = IntelligentSlider('G', 0.51, -255, self.rgb_changed) + bs = IntelligentSlider('B', 0.51, -255, self.rgb_changed) + self.rs = rs + self.gs = gs + self.bs = bs + + self.rgb_widget = QWidget() + self.rgb_widget.layout = QGridLayout(self.rgb_widget) + self.rgb_widget.layout.addWidget(self.rgb_add, 0, 0, 1, 3) + self.rgb_widget.layout.addWidget(self.rgb_mul, 1, 0, 1, 3) + self.rgb_widget.layout.addWidget(self.rs, 2, 0) + self.rgb_widget.layout.addWidget(self.gs, 2, 1) + self.rgb_widget.layout.addWidget(self.bs, 2, 2) + + + #--------------------------------------------------------------- + # HSV sliders + #--------------------------------------------------------------- + + # radio buttons + self.hsv_add = QtGui.QRadioButton('Additive') + self.hsv_mul = QtGui.QRadioButton('Multiplicative') + self.hsv_mul.toggled.connect(self.hsv_radio_changed) + self.hsv_mul.toggled.connect(self.hsv_radio_changed) + + # sliders + hs = IntelligentSlider('H', 0.36, -180, self.hsv_changed) + ss = IntelligentSlider('S', 0.002, 0, self.hsv_changed) + vs = IntelligentSlider('V', 0.002, 0, self.hsv_changed) + self.hs = hs + self.ss = ss + self.vs = vs + + self.hsv_widget = QWidget() + self.hsv_widget.layout = QGridLayout(self.hsv_widget) + self.hsv_widget.layout.addWidget(self.hsv_add, 0, 0, 1, 3) + self.hsv_widget.layout.addWidget(self.hsv_mul, 1, 0, 1, 3) + self.hsv_widget.layout.addWidget(self.hs, 2, 0) + self.hsv_widget.layout.addWidget(self.ss, 2, 1) + self.hsv_widget.layout.addWidget(self.vs, 2, 2) + + + #--------------------------------------------------------------- + # Brightness/Contrast sliders + #--------------------------------------------------------------- + + # sliders + cont = IntelligentSlider('x', 0.002, 0, self.bright_changed) + bright = IntelligentSlider('+', 0.51, -155, self.bright_changed) + self.cont = cont + self.bright = bright + + # layout + self.bright_widget = QWidget() + self.bright_widget.layout = QtGui.QGridLayout(self.bright_widget) + self.bright_widget.layout.addWidget(self.cont, 0, 0) + self.bright_widget.layout.addWidget(self.bright, 0, 1) + + + ''' + #--------------------------------------------------------------- + # Gamma sliders + #--------------------------------------------------------------- + # sliders + self.gamma_sliders = NSliderBlock(2, + [(100, 1200, 100, 'alpha', 0.01), + (0, 1200, 0, 'beta', 0.01)], + self.gamma_changed) + + # layout + self.gamma_widget = QWidget() + self.gamma_widget.layout = QtGui.QGridLayout(self.gamma_widget) + self.gamma_widget.layout.addWidget(self.gamma_sliders, 0, 0) + ''' + + #--------------------------------------------------------------- + # Buttons + #--------------------------------------------------------------- + self.commit_button = QtGui.QPushButton('Commit') + self.commit_button.clicked.connect(self.commit_changes) + self.revert_button = QtGui.QPushButton('Revert') + self.revert_button.clicked.connect(self.revert_changes) + + #--------------------------------------------------------------- + # Mixer Layout + #--------------------------------------------------------------- + self.sliders = QStackedWidget() + self.sliders.addWidget(self.rgb_widget) + self.sliders.addWidget(self.hsv_widget) + self.sliders.addWidget(self.bright_widget) + + self.layout = QtGui.QGridLayout(self) + self.layout.addWidget(self.combo_box, 0, 0) + self.layout.addWidget(self.sliders, 1, 0) + self.layout.addWidget(self.commit_button, 2, 0) + self.layout.addWidget(self.revert_button, 3, 0) + + #--------------------------------------------------------------- + # Initialization + #--------------------------------------------------------------- + + self.combo_box.setCurrentIndex(0) + self.sliders.setCurrentIndex(2) + #self.hide_sliders() + #self.rgb_widget.show() + #self.rgb_mul.setChecked(True) + #self.hsv_mul.setChecked(True) + + def rgb_changed(self, name, val): + pass + + + def hsv_changed(self, name, val): + pass + + def bright_changed(self, name, val): + # doesnt matter which slider changed we need both + # values + factor = self.bright_sliders.sliders['x'].conv_val() + offset = self.bright_sliders.sliders['+'].conv_val() + self.mixer.brightness(offset, factor) + self.update() + + def gamma_changed(self, name, val): + # doesnt matter which slider changed we need both + # values + alpha = self.gamma_sliders.sliders['alpha'].conv_val() + beta = self.gamma_sliders.sliders['beta'].conv_val() + self.mixer.sigmoid_gamma(alpha, beta) + self.update() + + def iter_all_sliders(self): + pass + + def reset_sliders(self): + self.rgb_add_sliders.set_sliders({'R': 0, 'G': 0, 'B': 0}) + self.rgb_mul_sliders.set_sliders({'R': 500, 'G': 500, 'B': 500}) + self.hsv_add_sliders.set_sliders({'H': 0, 'S': 0, 'V': 0}) + self.hsv_mul_sliders.set_sliders({'H': 0, 'S': 500, 'V': 500}) + self.bright_sliders.set_sliders({'+': 0, 'x': 500}) + self.gamma_sliders.set_sliders({'alpha': 100, 'beta': 0}) + + def combo_box_changed(self, index): + self.reset_sliders() + self.mixer.set_to_stateimg() + self.update() + combo_box_map={0: self.show_rgb, 1: self.show_hsv, + 2: self.show_bright, 3: self.show_gamma} + combo_box_map[index]() + + def hide_sliders(self): + self.rgb_widget.hide() + self.hsv_widget.hide() + self.bright_widget.hide() + self.gamma_sliders.hide() + + def rgb_radio_changed(self): + if self.rgb_add.isChecked(): + self.rgb_add_sliders.show() + self.rgb_mul_sliders.hide() + elif self.rgb_mul.isChecked(): + self.rgb_mul_sliders.show() + self.rgb_add_sliders.hide() + else: + pass + + self.reset_sliders() + self.mixer.set_to_stateimg() + self.update() + + def hsv_radio_changed(self): + if self.hsv_add.isChecked(): + self.hsv_add_sliders.show() + self.hsv_mul_sliders.hide() + elif self.hsv_mul.isChecked(): + self.hsv_mul_sliders.show() + self.hsv_add_sliders.hide() + else: + pass + + self.reset_sliders() + self.mixer.set_to_stateimg() + self.update() + + def show_rgb(self): + self.hide_sliders() + self.rgb_widget.show() + + def show_hsv(self): + self.hide_sliders() + self.hsv_widget.show() + + def show_bright(self): + self.hide_sliders() + self.bright_widget.show() + + def show_gamma(self): + self.hide_sliders() + self.gamma_sliders.show() + + def commit_changes(self): + self.mixer.commit_changes() + self.update() + + def revert_changes(self): + self.mixer.revert() + self.reset_sliders() + self.update() \ No newline at end of file diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index a7d95a98..88516c2d 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -1,4 +1,4 @@ -from util import prepare_for_display, window_manager, GuiLockError, ColorMixer +from util import prepare_for_display, window_manager, GuiLockError import numpy as np import sys @@ -17,6 +17,7 @@ else: QLabel, QWidget, QVBoxLayout, QSlider, QPainter, QColor, QFrame) from PyQt4 import QtCore, QtGui + from q_color_mixer import MixerPanel except ImportError: print 'PyQT4 libraries not installed. Plugin not loaded.' @@ -73,380 +74,6 @@ else: pass - class IntelligentSlider(QSlider): - ''' A slider that adds a 'name' attribute and calls a callback - with 'name' as an argument to the registerd callback. - - This allows you to create large groups of sliders in a loop, - but still keep track of the individual events''' - - def __init__(self, name, callback, conv_fac): - QSlider.__init__(self) - self.name = name - self.callback = callback - self.conv_fac = conv_fac - - self.name_label = QLabel() - self.name_label.setText(self.name) - self.name_label.setAlignment(QtCore.Qt.AlignCenter) - - self.value_label = QLabel() - self.value_label.setText('') - self.value_label.setAlignment(QtCore.Qt.AlignCenter) - - # bind this to the valueChanged signal of the slider - def i_changed(self, val): - val = self.conv_val() - self.value_label.setText(str(val)[:4]) - self.callback(self.name, val) - - def conv_val(self): - return self.value() * self.conv_fac - - - class NSliderBlock(QWidget): - '''Creates a block of n sliders with ranges - specified as a list of tuples. The fourth entry - in the tuple will be used as a dictionary key - so you can access the slider later. - So the tuple should be (min, max, initial, name) - - The callback is the function to be called - when a slider value changes. The callback will be - called with the following arguments (name, value). - - You can get a hook to a specific slider using - NSliderBlock.sliders[name] - - ''' - - def __init__(self, n, ranges_labels, callback): - QWidget.__init__(self) - - if len(ranges_labels) != n: - raise ValueError('not enough or too many ranges supplied') - - self.callback = callback - - # each key will give you - self.sliders = {} - self.layout = QtGui.QGridLayout(self) - - for i in range(n): - params = ranges_labels[i] - if len(params) != 5: - raise ValueError('Tuples must be length 4') - - name = params[3] - conv_fac = params[4] - - slider = IntelligentSlider(name, self.callback, conv_fac) - slider.setMinimum(params[0]) - slider.setMaximum(params[1]) - slider.setValue(params[2]) - slider.valueChanged.connect(slider.i_changed) - - self.sliders[name] = slider - - self.layout.addWidget(slider.name_label, 0, i) - self.layout.addWidget(slider, 1, i, QtCore.Qt.AlignHCenter) - self.layout.addWidget(slider.value_label, 2, i) - - self.layout.setColumnMinimumWidth(i, 50) - - def set_sliders(self, vals): - # vals should a dict to of slider names and set vals - if len(vals) != len(self.sliders): - raise ValueError('Wrong number of values') - - for key, value in vals.iteritems(): - self.sliders[key].setValue(value) - - class MixerPanel(QWidget): - '''A color mixer to hook up to an image. - You pass the image you the panel to operate on - and it operates on that image in place. You also - pass a callback to be called to trigger a refresh. - This callback is called every time the mixer modifies - your image.''' - def __init__(self, img, callback): - QWidget.__init__(self) - - self.img = img - self.update = callback - self.mixer = ColorMixer(self.img) - - #--------------------------------------------------------------- - # ComboBox - #--------------------------------------------------------------- - - self.combo_box_entries = ['RGB Color', 'HSV Color', - 'Brightness/Contrast', - 'Gamma (Sigmoidal)'] - self.combo_box = QtGui.QComboBox() - for entry in self.combo_box_entries: - self.combo_box.addItem(entry) - self.combo_box.currentIndexChanged.connect(self.combo_box_changed) - - #--------------------------------------------------------------- - # RGB color sliders - #--------------------------------------------------------------- - - # radio buttons - self.rgb_add = QtGui.QRadioButton('Additive') - self.rgb_mul = QtGui.QRadioButton('Multiplicative') - self.rgb_mul.toggled.connect(self.rgb_radio_changed) - self.rgb_add.toggled.connect(self.rgb_radio_changed) - - # additive sliders - self.rgb_add_sliders = NSliderBlock(3, [(-255, 255, 0, 'R', 1), - (-255, 255, 0, 'G', 1), - (-255, 255, 0, 'B', 1)], - self.rgb_add_changed) - - # multiplicative sliders - self.rgb_mul_sliders = NSliderBlock(3, [(0, 1000, 500, 'R', .002), - (0, 1000, 500, 'G', .002), - (0, 1000, 500, 'B', .002)], - self.rgb_mul_changed) - - # layout - self.rgb_widget = QWidget() - self.rgb_widget.layout = QtGui.QGridLayout(self.rgb_widget) - self.rgb_widget.layout.addWidget(self.rgb_add, 0, 0) - self.rgb_widget.layout.addWidget(self.rgb_mul, 1, 0) - self.rgb_widget.layout.addWidget(self.rgb_add_sliders, 2, 0) - self.rgb_widget.layout.addWidget(self.rgb_mul_sliders, 2, 0) - - #--------------------------------------------------------------- - # HSV sliders - #--------------------------------------------------------------- - - # radio buttons - self.hsv_add = QtGui.QRadioButton('Additive') - self.hsv_mul = QtGui.QRadioButton('Multiplicative') - self.hsv_mul.toggled.connect(self.hsv_radio_changed) - self.hsv_add.toggled.connect(self.hsv_radio_changed) - - # additive sliders - self.hsv_add_sliders = NSliderBlock(3, [(-180, 180, 0, 'H', 1), - (-100, 100, 0, 'S', .01), - (-100, 100, 0, 'V', .01)], - self.hsv_add_changed) - - # multiplicative sliders - self.hsv_mul_sliders = NSliderBlock(3, [(-180, 180, 0, 'H', 1), - (0, 1000, 500, 'S', .002), - (0, 1000, 500, 'V', .002)], - self.hsv_mul_changed) - - # layout - self.hsv_widget = QWidget() - self.hsv_widget.layout = QtGui.QGridLayout(self.hsv_widget) - self.hsv_widget.layout.addWidget(self.hsv_add, 0, 0) - self.hsv_widget.layout.addWidget(self.hsv_mul, 1, 0) - self.hsv_widget.layout.addWidget(self.hsv_add_sliders, 2, 0) - self.hsv_widget.layout.addWidget(self.hsv_mul_sliders, 2, 0) - - #--------------------------------------------------------------- - # Brightness sliders - #--------------------------------------------------------------- - - # sliders - self.bright_sliders = NSliderBlock(2, - [(0, 1000, 500, 'x', 0.002), - (-255, 255, 0, '+', 1)], - self.bright_changed) - - # layout - self.bright_widget = QWidget() - self.bright_widget.layout = QtGui.QGridLayout(self.bright_widget) - self.bright_widget.layout.addWidget(self.bright_sliders, 0, 0) - - #--------------------------------------------------------------- - # Gamma sliders - #--------------------------------------------------------------- - # sliders - self.gamma_sliders = NSliderBlock(2, - [(100, 1200, 100, 'alpha', 0.01), - (0, 1200, 0, 'beta', 0.01)], - self.gamma_changed) - - # layout - self.gamma_widget = QWidget() - self.gamma_widget.layout = QtGui.QGridLayout(self.gamma_widget) - self.gamma_widget.layout.addWidget(self.gamma_sliders, 0, 0) - - #--------------------------------------------------------------- - # Buttons - #--------------------------------------------------------------- - self.commit_button = QtGui.QPushButton('Commit') - self.commit_button.clicked.connect(self.commit_changes) - self.revert_button = QtGui.QPushButton('Revert') - self.revert_button.clicked.connect(self.revert_changes) - - #--------------------------------------------------------------- - # Mixer Layout - #--------------------------------------------------------------- - self.layout = QtGui.QGridLayout(self) - self.layout.addWidget(self.combo_box, 0, 0) - self.layout.addWidget(self.rgb_widget, 1, 0) - self.layout.addWidget(self.hsv_widget, 1, 0) - self.layout.addWidget(self.gamma_widget, 1, 0) - self.layout.addWidget(self.bright_widget, 1, 0) - - self.layout.addWidget(self.commit_button, 2, 0) - self.layout.addWidget(self.revert_button, 3, 0) - - #--------------------------------------------------------------- - # Initialization - #--------------------------------------------------------------- - - self.combo_box.setCurrentIndex(0) - self.hide_sliders() - self.rgb_widget.show() - self.rgb_mul.setChecked(True) - self.hsv_mul.setChecked(True) - - def rgb_add_changed(self, name, val): - if not self.rgb_add.isChecked(): - return - if name == 'R': - self.mixer.add(self.mixer.RED, val) - elif name == 'G': - self.mixer.add(self.mixer.GREEN, val) - elif name == 'B': - self.mixer.add(self.mixer.BLUE, val) - else: - return - self.update() - - def rgb_mul_changed(self, name, val): - if not self.rgb_mul.isChecked(): - return - if name == 'R': - self.mixer.multiply(self.mixer.RED, val) - elif name == 'G': - self.mixer.multiply(self.mixer.GREEN, val) - elif name == 'B': - self.mixer.multiply(self.mixer.BLUE, val) - else: - return - self.update() - - def hsv_add_changed(self, name, val): - if not self.hsv_add.isChecked(): - return - h = self.hsv_add_sliders.sliders['H'].conv_val() - s = self.hsv_add_sliders.sliders['S'].conv_val() - v = self.hsv_add_sliders.sliders['V'].conv_val() - self.mixer.hsv_add(h, s, v) - self.update() - - def hsv_mul_changed(self, name, val): - if not self.hsv_mul.isChecked(): - return - h = self.hsv_mul_sliders.sliders['H'].conv_val() - s = self.hsv_mul_sliders.sliders['S'].conv_val() - v = self.hsv_mul_sliders.sliders['V'].conv_val() - self.mixer.hsv_multiply(h, s, v) - self.update() - - def bright_changed(self, name, val): - # doesnt matter which slider changed we need both - # values - factor = self.bright_sliders.sliders['x'].conv_val() - offset = self.bright_sliders.sliders['+'].conv_val() - self.mixer.brightness(offset, factor) - self.update() - - def gamma_changed(self, name, val): - # doesnt matter which slider changed we need both - # values - alpha = self.gamma_sliders.sliders['alpha'].conv_val() - beta = self.gamma_sliders.sliders['beta'].conv_val() - self.mixer.sigmoid_gamma(alpha, beta) - self.update() - - def iter_all_sliders(self): - pass - - def reset_sliders(self): - self.rgb_add_sliders.set_sliders({'R': 0, 'G': 0, 'B': 0}) - self.rgb_mul_sliders.set_sliders({'R': 500, 'G': 500, 'B': 500}) - self.hsv_add_sliders.set_sliders({'H': 0, 'S': 0, 'V': 0}) - self.hsv_mul_sliders.set_sliders({'H': 0, 'S': 500, 'V': 500}) - self.bright_sliders.set_sliders({'+': 0, 'x': 500}) - self.gamma_sliders.set_sliders({'alpha': 100, 'beta': 0}) - - def combo_box_changed(self, index): - self.reset_sliders() - self.mixer.set_to_stateimg() - self.update() - combo_box_map={0: self.show_rgb, 1: self.show_hsv, - 2: self.show_bright, 3: self.show_gamma} - combo_box_map[index]() - - def hide_sliders(self): - self.rgb_widget.hide() - self.hsv_widget.hide() - self.bright_widget.hide() - self.gamma_sliders.hide() - - def rgb_radio_changed(self): - if self.rgb_add.isChecked(): - self.rgb_add_sliders.show() - self.rgb_mul_sliders.hide() - elif self.rgb_mul.isChecked(): - self.rgb_mul_sliders.show() - self.rgb_add_sliders.hide() - else: - pass - - self.reset_sliders() - self.mixer.set_to_stateimg() - self.update() - - def hsv_radio_changed(self): - if self.hsv_add.isChecked(): - self.hsv_add_sliders.show() - self.hsv_mul_sliders.hide() - elif self.hsv_mul.isChecked(): - self.hsv_mul_sliders.show() - self.hsv_add_sliders.hide() - else: - pass - - self.reset_sliders() - self.mixer.set_to_stateimg() - self.update() - - def show_rgb(self): - self.hide_sliders() - self.rgb_widget.show() - - def show_hsv(self): - self.hide_sliders() - self.hsv_widget.show() - - def show_bright(self): - self.hide_sliders() - self.bright_widget.show() - - def show_gamma(self): - self.hide_sliders() - self.gamma_sliders.show() - - def commit_changes(self): - self.mixer.commit_changes() - self.update() - - def revert_changes(self): - self.mixer.revert() - self.reset_sliders() - self.update() - - class RGBHSVDisplay(QWidget): def __init__(self): QWidget.__init__(self) @@ -621,7 +248,7 @@ else: self.label.setMouseTracking(True) self.label.setMinimumSize(QtCore.QSize(100, 100)) - self.mixer_panel = MixerPanel(self.arr, self.refresh_image) + self.mixer_panel = MixerPanel(self.arr) self.layout.addWidget(self.mixer_panel, 0, 2) self.mixer_panel.show() @@ -644,6 +271,7 @@ else: self.layout.addWidget(self.save_variable, 1, 1) self.layout.addWidget(self.save_file, 1, 2) + '''' # hook up the mixer sliders move events to trigger a # histogram redraw. self.mixer_panel.rgb_add_sliders.sliders['R'].\ @@ -674,6 +302,7 @@ else: sliderMoved.connect(self.update_histogram) self.mixer_panel.bright_sliders.sliders['x'].\ sliderMoved.connect(self.update_histogram) + ''' def update_histogram(self): self.rgb_hist.update_hists(self.calc_hist()) From ae9f9cc2caef740f4f93106c95517bdb304b8b39 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Fri, 6 Nov 2009 16:19:41 +0100 Subject: [PATCH 16/43] further progress on the refactoring of the fancy imshow. --- scikits/image/io/_plugins/_colormixer.pyx | 6 +- scikits/image/io/_plugins/q_color_mixer.py | 191 ++++++++++++--------- scikits/image/io/_plugins/qt_plugin.py | 33 +--- scikits/image/io/_plugins/util.py | 4 +- 4 files changed, 119 insertions(+), 115 deletions(-) diff --git a/scikits/image/io/_plugins/_colormixer.pyx b/scikits/image/io/_plugins/_colormixer.pyx index c1291e78..08e3cc8f 100644 --- a/scikits/image/io/_plugins/_colormixer.pyx +++ b/scikits/image/io/_plugins/_colormixer.pyx @@ -97,7 +97,7 @@ def multiply(np.ndarray[np.uint8_t, ndim=3] img, @cython.boundscheck(False) def brightness(np.ndarray[np.uint8_t, ndim=3] img, np.ndarray[np.uint8_t, ndim=3] stateimg, - int offset, float factor): + float factor, int offset): """Modify the brightness of an image. 'factor' is multiplied to all channels, which are then added by 'amount'. Overflow is clipped. @@ -108,10 +108,10 @@ def brightness(np.ndarray[np.uint8_t, ndim=3] img, Output image. stateimg : (M, N, 3) ndarray of uint8 Input image. - offset : int - Ammount to add to each channel. factor : float Multiplication factor. + offset : int + Ammount to add to each channel. """ diff --git a/scikits/image/io/_plugins/q_color_mixer.py b/scikits/image/io/_plugins/q_color_mixer.py index e5e4c26d..12c6e25a 100644 --- a/scikits/image/io/_plugins/q_color_mixer.py +++ b/scikits/image/io/_plugins/q_color_mixer.py @@ -40,10 +40,10 @@ class IntelligentSlider(QWidget): self.value_label.setText(str(self.slider.value() * self.a + self.b)) self.value_label.setAlignment(QtCore.Qt.AlignCenter) - self.layout = QVBoxLayout(self) - self.layout.addWidget(self.name_label) - self.layout.addWidget(self.slider) - self.layout.addWidget(self.value_label) + self.layout = QGridLayout(self) + self.layout.addWidget(self.name_label, 0, 0) + self.layout.addWidget(self.slider, 1, 0, QtCore.Qt.AlignHCenter) + self.layout.addWidget(self.value_label, 2, 0) # bind this to the valueChanged signal of the slider def slider_changed(self, val): @@ -56,10 +56,11 @@ class IntelligentSlider(QWidget): self.b = b def set_value(self, val): - self.slider.setValue(int((val - self.a) / self.b)) + self.slider.setValue(int((val - self.b) / self.a)) + self.value_label.setText(str(val)[:4]) def val(self): - return self.value() * self.a + self.b + return self.slider.value() * self.a + self.b class MixerPanel(QWidget): @@ -74,6 +75,7 @@ class MixerPanel(QWidget): self.img = img self.mixer = ColorMixer(self.img) + self.callback = None #--------------------------------------------------------------- # ComboBox @@ -147,7 +149,7 @@ class MixerPanel(QWidget): # sliders cont = IntelligentSlider('x', 0.002, 0, self.bright_changed) - bright = IntelligentSlider('+', 0.51, -155, self.bright_changed) + bright = IntelligentSlider('+', 0.51, -255, self.bright_changed) self.cont = cont self.bright = bright @@ -158,21 +160,21 @@ class MixerPanel(QWidget): self.bright_widget.layout.addWidget(self.bright, 0, 1) - ''' #--------------------------------------------------------------- # Gamma sliders #--------------------------------------------------------------- + # sliders - self.gamma_sliders = NSliderBlock(2, - [(100, 1200, 100, 'alpha', 0.01), - (0, 1200, 0, 'beta', 0.01)], - self.gamma_changed) + alpha = IntelligentSlider('alpha', 0.011, 1, self.gamma_changed) + beta = IntelligentSlider('beta', 0.012, 0, self.gamma_changed) + self.a_gamma = alpha + self.b_gamma = beta # layout self.gamma_widget = QWidget() self.gamma_widget.layout = QtGui.QGridLayout(self.gamma_widget) - self.gamma_widget.layout.addWidget(self.gamma_sliders, 0, 0) - ''' + self.gamma_widget.layout.addWidget(self.a_gamma, 0, 0) + self.gamma_widget.layout.addWidget(self.b_gamma, 0, 1) #--------------------------------------------------------------- # Buttons @@ -189,6 +191,7 @@ class MixerPanel(QWidget): self.sliders.addWidget(self.rgb_widget) self.sliders.addWidget(self.hsv_widget) self.sliders.addWidget(self.bright_widget) + self.sliders.addWidget(self.gamma_widget) self.layout = QtGui.QGridLayout(self) self.layout.addWidget(self.combo_box, 0, 0) @@ -197,91 +200,123 @@ class MixerPanel(QWidget): self.layout.addWidget(self.revert_button, 3, 0) #--------------------------------------------------------------- - # Initialization + # State Initialization #--------------------------------------------------------------- self.combo_box.setCurrentIndex(0) - self.sliders.setCurrentIndex(2) - #self.hide_sliders() - #self.rgb_widget.show() - #self.rgb_mul.setChecked(True) - #self.hsv_mul.setChecked(True) + self.rgb_mul.setChecked(True) + self.hsv_mul.setChecked(True) + + + def set_callback(self, callback): + self.callback = callback + + def combo_box_changed(self, index): + self.sliders.setCurrentIndex(index) + self.reset_sliders() + + def rgb_radio_changed(self): + self.reset_sliders() + + def hsv_radio_changed(self): + self.reset_sliders() + + def reset_sliders(self): + # handle changing the conversion factors necessary + if self.rgb_add.isChecked(): + self.rs.set_conv_fac(0.51, -255) + self.rs.set_value(0) + self.gs.set_conv_fac(0.51, -255) + self.gs.set_value(0) + self.bs.set_conv_fac(0.51, -255) + self.bs.set_value(0) + else: + self.rs.set_conv_fac(0.002, 0) + self.rs.set_value(1.) + self.gs.set_conv_fac(0.002, 0) + self.gs.set_value(1.) + self.bs.set_conv_fac(0.002, 0) + self.bs.set_value(1.) + + self.hs.set_value(0) + if self.hsv_add.isChecked(): + self.ss.set_conv_fac(0.002, -1) + self.ss.set_value(0) + self.vs.set_conv_fac(0.002, -1) + self.vs.set_value(0) + else: + self.ss.set_conv_fac(0.002, 0) + self.ss.set_value(1.) + self.vs.set_conv_fac(0.002, 0) + self.vs.set_value(1.) + + self.bright.set_value(0) + self.cont.set_value(1.) + + self.a_gamma.set_value(1) + self.b_gamma.set_value(0) + def rgb_changed(self, name, val): - pass + if name == 'R': + channel = self.mixer.RED + elif name == 'G': + channel = self.mixer.GREEN + else: + channel = self.mixer.BLUE + if self.rgb_mul.isChecked(): + self.mixer.multiply(channel, val) + elif self.rgb_add.isChecked(): + self.mixer.add(channel, val) + else: + pass + + if self.callback: + self.callback() def hsv_changed(self, name, val): - pass + h = self.hs.val() + s = self.ss.val() + v = self.vs.val() + + if self.hsv_mul.isChecked(): + self.mixer.hsv_multiply(h, s, v) + elif self.hsv_add.isChecked(): + self.mixer.hsv_add(h, s, v) + else: + pass + + if self.callback: + self.callback() def bright_changed(self, name, val): - # doesnt matter which slider changed we need both - # values - factor = self.bright_sliders.sliders['x'].conv_val() - offset = self.bright_sliders.sliders['+'].conv_val() - self.mixer.brightness(offset, factor) - self.update() + b = self.bright.val() + c = self.cont.val() + self.mixer.brightness(c, b) + + if self.callback: + self.callback() def gamma_changed(self, name, val): - # doesnt matter which slider changed we need both - # values - alpha = self.gamma_sliders.sliders['alpha'].conv_val() - beta = self.gamma_sliders.sliders['beta'].conv_val() - self.mixer.sigmoid_gamma(alpha, beta) - self.update() + ag = self.a_gamma.val() + bg = self.b_gamma.val() + self.mixer.sigmoid_gamma(ag, bg) + + if self.callback: + self.callback() def iter_all_sliders(self): pass - def reset_sliders(self): - self.rgb_add_sliders.set_sliders({'R': 0, 'G': 0, 'B': 0}) - self.rgb_mul_sliders.set_sliders({'R': 500, 'G': 500, 'B': 500}) - self.hsv_add_sliders.set_sliders({'H': 0, 'S': 0, 'V': 0}) - self.hsv_mul_sliders.set_sliders({'H': 0, 'S': 500, 'V': 500}) - self.bright_sliders.set_sliders({'+': 0, 'x': 500}) - self.gamma_sliders.set_sliders({'alpha': 100, 'beta': 0}) - def combo_box_changed(self, index): - self.reset_sliders() - self.mixer.set_to_stateimg() - self.update() - combo_box_map={0: self.show_rgb, 1: self.show_hsv, - 2: self.show_bright, 3: self.show_gamma} - combo_box_map[index]() + + def hide_sliders(self): - self.rgb_widget.hide() - self.hsv_widget.hide() - self.bright_widget.hide() - self.gamma_sliders.hide() + pass - def rgb_radio_changed(self): - if self.rgb_add.isChecked(): - self.rgb_add_sliders.show() - self.rgb_mul_sliders.hide() - elif self.rgb_mul.isChecked(): - self.rgb_mul_sliders.show() - self.rgb_add_sliders.hide() - else: - pass - self.reset_sliders() - self.mixer.set_to_stateimg() - self.update() - - def hsv_radio_changed(self): - if self.hsv_add.isChecked(): - self.hsv_add_sliders.show() - self.hsv_mul_sliders.hide() - elif self.hsv_mul.isChecked(): - self.hsv_mul_sliders.show() - self.hsv_add_sliders.hide() - else: - pass - - self.reset_sliders() - self.mixer.set_to_stateimg() - self.update() def show_rgb(self): self.hide_sliders() diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index 88516c2d..499a4cbd 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -251,6 +251,7 @@ else: self.mixer_panel = MixerPanel(self.arr) self.layout.addWidget(self.mixer_panel, 0, 2) self.mixer_panel.show() + self.mixer_panel.set_callback(self.refresh_image) self.rgb_hist = MultiHist(self.calc_hist()) self.layout.addWidget(self.rgb_hist, 0, 1) @@ -271,38 +272,6 @@ else: self.layout.addWidget(self.save_variable, 1, 1) self.layout.addWidget(self.save_file, 1, 2) - '''' - # hook up the mixer sliders move events to trigger a - # histogram redraw. - self.mixer_panel.rgb_add_sliders.sliders['R'].\ - sliderMoved.connect(self.update_histogram) - self.mixer_panel.rgb_add_sliders.sliders['G'].\ - sliderMoved.connect(self.update_histogram) - self.mixer_panel.rgb_add_sliders.sliders['B'].\ - sliderMoved.connect(self.update_histogram) - self.mixer_panel.rgb_mul_sliders.sliders['R'].\ - sliderMoved.connect(self.update_histogram) - self.mixer_panel.rgb_mul_sliders.sliders['G'].\ - sliderMoved.connect(self.update_histogram) - self.mixer_panel.rgb_mul_sliders.sliders['B'].\ - sliderMoved.connect(self.update_histogram) - self.mixer_panel.hsv_add_sliders.sliders['H'].\ - sliderMoved.connect(self.update_histogram) - self.mixer_panel.hsv_add_sliders.sliders['S'].\ - sliderMoved.connect(self.update_histogram) - self.mixer_panel.hsv_add_sliders.sliders['V'].\ - sliderMoved.connect(self.update_histogram) - self.mixer_panel.hsv_mul_sliders.sliders['H'].\ - sliderMoved.connect(self.update_histogram) - self.mixer_panel.hsv_mul_sliders.sliders['S'].\ - sliderMoved.connect(self.update_histogram) - self.mixer_panel.hsv_mul_sliders.sliders['V'].\ - sliderMoved.connect(self.update_histogram) - self.mixer_panel.bright_sliders.sliders['+'].\ - sliderMoved.connect(self.update_histogram) - self.mixer_panel.bright_sliders.sliders['x'].\ - sliderMoved.connect(self.update_histogram) - ''' def update_histogram(self): self.rgb_hist.update_hists(self.calc_hist()) diff --git a/scikits/image/io/_plugins/util.py b/scikits/image/io/_plugins/util.py index 7caff221..32124038 100644 --- a/scikits/image/io/_plugins/util.py +++ b/scikits/image/io/_plugins/util.py @@ -243,7 +243,7 @@ class ColorMixer(object): _colormixer.multiply(self.img, self.stateimg, channel, ammount) - def brightness(self, offset, factor): + def brightness(self, factor, offset): '''Adjust the brightness off an image with an offset and factor. Parameters @@ -256,7 +256,7 @@ class ColorMixer(object): result = clip((pixel + offset)*factor) ''' - _colormixer.brightness(self.img, self.stateimg, offset, factor) + _colormixer.brightness(self.img, self.stateimg, factor, offset) def sigmoid_gamma(self, alpha, beta): _colormixer.sigmoid_gamma(self.img, self.stateimg, alpha, beta) From cf19f11bbbbec178ca1ec9d9c4efbf1c810e6053 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Fri, 6 Nov 2009 17:31:27 +0100 Subject: [PATCH 17/43] added regular gamma to the mixer, refactored more of fancy imshow. --- scikits/image/io/_plugins/_colormixer.pyx | 22 ++++++ scikits/image/io/_plugins/q_color_mixer.py | 79 ++++++++++------------ scikits/image/io/_plugins/util.py | 3 + 3 files changed, 62 insertions(+), 42 deletions(-) diff --git a/scikits/image/io/_plugins/_colormixer.pyx b/scikits/image/io/_plugins/_colormixer.pyx index 08e3cc8f..ec3d698c 100644 --- a/scikits/image/io/_plugins/_colormixer.pyx +++ b/scikits/image/io/_plugins/_colormixer.pyx @@ -16,6 +16,7 @@ import cython cdef extern from "math.h": float exp(float) + float pow(float, float) @cython.boundscheck(False) @@ -168,6 +169,27 @@ def sigmoid_gamma(np.ndarray[np.uint8_t, ndim=3] img, img[i,j,2] = (b * 255) +@cython.boundscheck(False) +def gamma(np.ndarray[np.uint8_t, ndim=3] img, + np.ndarray[np.uint8_t, ndim=3] stateimg, + float gamma): + + cdef int height = img.shape[0] + cdef int width = img.shape[1] + + cdef float r, g, b + + cdef int i, j + for i in range(height): + for j in range(width): + r = stateimg[i,j,0] / 255. + g = stateimg[i,j,1] / 255. + b = stateimg[i,j,2] / 255. + + img[i,j,0] = (pow(r, gamma) * 255) + img[i,j,1] = (pow(g, gamma) * 255) + img[i,j,2] = (pow(b, gamma) * 255) + cdef void rgb_2_hsv(float* RGB, float* HSV): diff --git a/scikits/image/io/_plugins/q_color_mixer.py b/scikits/image/io/_plugins/q_color_mixer.py index 12c6e25a..d041fb26 100644 --- a/scikits/image/io/_plugins/q_color_mixer.py +++ b/scikits/image/io/_plugins/q_color_mixer.py @@ -83,6 +83,7 @@ class MixerPanel(QWidget): self.combo_box_entries = ['RGB Color', 'HSV Color', 'Brightness/Contrast', + 'Gamma', 'Gamma (Sigmoidal)'] self.combo_box = QtGui.QComboBox() for entry in self.combo_box_entries: @@ -160,21 +161,33 @@ class MixerPanel(QWidget): self.bright_widget.layout.addWidget(self.bright, 0, 1) - #--------------------------------------------------------------- - # Gamma sliders - #--------------------------------------------------------------- - - # sliders - alpha = IntelligentSlider('alpha', 0.011, 1, self.gamma_changed) - beta = IntelligentSlider('beta', 0.012, 0, self.gamma_changed) - self.a_gamma = alpha - self.b_gamma = beta + #----------------------------------------------------------------------- + # Gamma Slider + #----------------------------------------------------------------------- + gamma = IntelligentSlider('gamma', 0.005, 0, self.gamma_changed) + self.gamma = gamma # layout self.gamma_widget = QWidget() self.gamma_widget.layout = QtGui.QGridLayout(self.gamma_widget) - self.gamma_widget.layout.addWidget(self.a_gamma, 0, 0) - self.gamma_widget.layout.addWidget(self.b_gamma, 0, 1) + self.gamma_widget.layout.addWidget(self.gamma, 0, 0) + + + #--------------------------------------------------------------- + # Sigmoid Gamma sliders + #--------------------------------------------------------------- + + # sliders + alpha = IntelligentSlider('alpha', 0.011, 1, self.sig_gamma_changed) + beta = IntelligentSlider('beta', 0.012, 0, self.sig_gamma_changed) + self.a_gamma = alpha + self.b_gamma = beta + + # layout + self.sig_gamma_widget = QWidget() + self.sig_gamma_widget.layout = QtGui.QGridLayout(self.sig_gamma_widget) + self.sig_gamma_widget.layout.addWidget(self.a_gamma, 0, 0) + self.sig_gamma_widget.layout.addWidget(self.b_gamma, 0, 1) #--------------------------------------------------------------- # Buttons @@ -192,6 +205,7 @@ class MixerPanel(QWidget): self.sliders.addWidget(self.hsv_widget) self.sliders.addWidget(self.bright_widget) self.sliders.addWidget(self.gamma_widget) + self.sliders.addWidget(self.sig_gamma_widget) self.layout = QtGui.QGridLayout(self) self.layout.addWidget(self.combo_box, 0, 0) @@ -253,8 +267,9 @@ class MixerPanel(QWidget): self.bright.set_value(0) self.cont.set_value(1.) + self.gamma.set_value(1) self.a_gamma.set_value(1) - self.b_gamma.set_value(0) + self.b_gamma.set_value(0.5) def rgb_changed(self, name, val): @@ -299,6 +314,12 @@ class MixerPanel(QWidget): self.callback() def gamma_changed(self, name, val): + self.mixer.gamma(val) + + if self.callback: + self.callback() + + def sig_gamma_changed(self, name, val): ag = self.a_gamma.val() bg = self.b_gamma.val() self.mixer.sigmoid_gamma(ag, bg) @@ -306,39 +327,13 @@ class MixerPanel(QWidget): if self.callback: self.callback() - def iter_all_sliders(self): - pass - - - - - - def hide_sliders(self): - pass - - - - def show_rgb(self): - self.hide_sliders() - self.rgb_widget.show() - - def show_hsv(self): - self.hide_sliders() - self.hsv_widget.show() - - def show_bright(self): - self.hide_sliders() - self.bright_widget.show() - - def show_gamma(self): - self.hide_sliders() - self.gamma_sliders.show() - def commit_changes(self): self.mixer.commit_changes() - self.update() + self.reset_sliders() def revert_changes(self): self.mixer.revert() self.reset_sliders() - self.update() \ No newline at end of file + + if self.callback: + self.callback() \ No newline at end of file diff --git a/scikits/image/io/_plugins/util.py b/scikits/image/io/_plugins/util.py index 32124038..db8ed0eb 100644 --- a/scikits/image/io/_plugins/util.py +++ b/scikits/image/io/_plugins/util.py @@ -261,6 +261,9 @@ class ColorMixer(object): def sigmoid_gamma(self, alpha, beta): _colormixer.sigmoid_gamma(self.img, self.stateimg, alpha, beta) + def gamma(self, gamma): + _colormixer.gamma(self.img, self.stateimg, gamma) + def hsv_add(self, h_amt, s_amt, v_amt): '''Adjust the H, S, V channels of an image by a constant ammount. This is similar to the add() mixer function, but operates over the From ca051a3e98baf7144fa56393597b9dd7b36540cc Mon Sep 17 00:00:00 2001 From: sccolbert Date: Fri, 6 Nov 2009 20:40:43 +0100 Subject: [PATCH 18/43] Finished the refactor of the mixer and the histogram. Performance is now much better, a bunch of bugs are gone, and it shouldnt throw anymore exceptions. --- scikits/image/io/_plugins/_colormixer.pyx | 63 +--------- scikits/image/io/_plugins/_histograms.pyx | 83 ++++++++++++ scikits/image/io/_plugins/q_color_mixer.py | 19 ++- scikits/image/io/_plugins/q_histogram.py | 140 +++++++++++++++++++++ scikits/image/io/_plugins/qt_plugin.py | 136 ++------------------ scikits/image/io/_plugins/util.py | 39 +++--- scikits/image/io/setup.py | 7 +- 7 files changed, 272 insertions(+), 215 deletions(-) create mode 100644 scikits/image/io/_plugins/_histograms.pyx create mode 100644 scikits/image/io/_plugins/q_histogram.py diff --git a/scikits/image/io/_plugins/_colormixer.pyx b/scikits/image/io/_plugins/_colormixer.pyx index ec3d698c..6e0fa1f4 100644 --- a/scikits/image/io/_plugins/_colormixer.pyx +++ b/scikits/image/io/_plugins/_colormixer.pyx @@ -529,68 +529,7 @@ def hsv_multiply(np.ndarray[np.uint8_t, ndim=3] img, img[i, j, 1] = RGB[1] img[i, j, 2] = RGB[2] -@cython.boundscheck(False) -def histograms(np.ndarray[np.uint8_t, ndim=3] img, int nbins): - '''Calculate the channel histograms of the current image. - - Parameters - ---------- - img : ndarray, uint8, ndim=3 - The image to calculate the histogram. - nbins : int - The number of bins. - - Returns - ------- - out : (rcounts, gcounts, bcounts, vcounts) - The binned histograms of the RGB channels and grayscale intensity. - - This is a NAIVE histogram routine, meant primarily for fast display. - - ''' - cdef int width = img.shape[1] - cdef int height = img.shape[0] - cdef np.ndarray[np.int32_t, ndim=1] r - cdef np.ndarray[np.int32_t, ndim=1] g - cdef np.ndarray[np.int32_t, ndim=1] b - cdef np.ndarray[np.int32_t, ndim=1] v - - r = np.zeros((nbins,), dtype=np.int32) - g = np.zeros((nbins,), dtype=np.int32) - b = np.zeros((nbins,), dtype=np.int32) - v = np.zeros((nbins,), dtype=np.int32) - - cdef int i, j, k, rbin, gbin, bbin, vbin - cdef float bin_width = 255./ nbins - cdef np.uint8_t R, G, B, V - - for i in range(height): - for j in range(width): - R = img[i, j, 0] - G = img[i, j, 1] - B = img[i, j, 2] - V = (0.3 * R + 0.59 * G + 0.11 * B) - - rbin = (R / bin_width) - gbin = (G / bin_width) - bbin = (B / bin_width) - vbin = (V / bin_width) - - if rbin == nbins: - rbin -= 1 - if gbin == nbins: - gbin -= 1 - if bbin == nbins: - gbin -= 1 - if vbin == nbins: - vbin -= 1 - - r[rbin] += 1 - g[gbin] += 1 - b[bbin] += 1 - v[vbin] += 1 - - return (r, g, b, v) + diff --git a/scikits/image/io/_plugins/_histograms.pyx b/scikits/image/io/_plugins/_histograms.pyx new file mode 100644 index 00000000..41ec79a1 --- /dev/null +++ b/scikits/image/io/_plugins/_histograms.pyx @@ -0,0 +1,83 @@ +import numpy as np +cimport numpy as np + +import cython + + +cdef inline float tri_max(float a, float b, float c): + cdef float MAX + + if a > b: + MAX = a + else: + MAX = b + + if MAX > c: + return MAX + else: + return c + + +@cython.boundscheck(False) +def histograms(np.ndarray[np.uint8_t, ndim=3] img, int nbins): + '''Calculate the channel histograms of the current image. + + Parameters + ---------- + img : ndarray, uint8, ndim=3 + The image to calculate the histogram. + nbins : int + The number of bins. + + Returns + ------- + out : (rcounts, gcounts, bcounts, vcounts) + The binned histograms of the RGB channels and grayscale intensity. + + This is a NAIVE histogram routine, meant primarily for fast display. + + ''' + cdef int width = img.shape[1] + cdef int height = img.shape[0] + cdef np.ndarray[np.int32_t, ndim=1] r + cdef np.ndarray[np.int32_t, ndim=1] g + cdef np.ndarray[np.int32_t, ndim=1] b + cdef np.ndarray[np.int32_t, ndim=1] v + + r = np.zeros((nbins,), dtype=np.int32) + g = np.zeros((nbins,), dtype=np.int32) + b = np.zeros((nbins,), dtype=np.int32) + v = np.zeros((nbins,), dtype=np.int32) + + cdef int i, j, k, rbin, gbin, bbin, vbin + cdef float bin_width = 255./ nbins + cdef float R, G, B, V + + for i in range(height): + for j in range(width): + R = img[i, j, 0] + G = img[i, j, 1] + B = img[i, j, 2] + V = tri_max(R, G, B) + + rbin = (R / bin_width) + gbin = (G / bin_width) + bbin = (B / bin_width) + vbin = (V / bin_width) + + # fully open last bin + if R == 255: + rbin -= 1 + if G == 255: + gbin -= 1 + if B == 255: + bbin -= 1 + if V == 255: + vbin -= 1 + + r[rbin] += 1 + g[gbin] += 1 + b[bbin] += 1 + v[vbin] += 1 + + return (r, g, b, v) diff --git a/scikits/image/io/_plugins/q_color_mixer.py b/scikits/image/io/_plugins/q_color_mixer.py index d041fb26..95cb74b7 100644 --- a/scikits/image/io/_plugins/q_color_mixer.py +++ b/scikits/image/io/_plugins/q_color_mixer.py @@ -6,8 +6,6 @@ from PyQt4.QtGui import (QWidget, QStackedWidget, QSlider, QVBoxLayout, from util import ColorMixer - - class IntelligentSlider(QWidget): ''' A slider that adds a 'name' attribute and calls a callback with 'name' as an argument to the registerd callback. @@ -26,6 +24,7 @@ class IntelligentSlider(QWidget): self.callback = callback self.a = a self.b = b + self.manually_triggered = False self.slider = QSlider() self.slider.setRange(0, 1000) @@ -49,15 +48,19 @@ class IntelligentSlider(QWidget): def slider_changed(self, val): val = self.val() self.value_label.setText(str(val)[:4]) - self.callback(self.name, val) + + if not self.manually_triggered: + self.callback(self.name, val) def set_conv_fac(self, a, b): self.a = a self.b = b def set_value(self, val): + self.manually_triggered = True self.slider.setValue(int((val - self.b) / self.a)) self.value_label.setText(str(val)[:4]) + self.manually_triggered = False def val(self): return self.slider.value() * self.a + self.b @@ -227,13 +230,19 @@ class MixerPanel(QWidget): def combo_box_changed(self, index): self.sliders.setCurrentIndex(index) - self.reset_sliders() + self.reset() def rgb_radio_changed(self): - self.reset_sliders() + self.reset() def hsv_radio_changed(self): + self.reset() + + def reset(self): self.reset_sliders() + self.mixer.set_to_stateimg() + if self.callback: + self.callback() def reset_sliders(self): # handle changing the conversion factors necessary diff --git a/scikits/image/io/_plugins/q_histogram.py b/scikits/image/io/_plugins/q_histogram.py new file mode 100644 index 00000000..cfdc889f --- /dev/null +++ b/scikits/image/io/_plugins/q_histogram.py @@ -0,0 +1,140 @@ +import numpy as np + +from PyQt4.QtGui import QWidget, QPainter, QGridLayout, QColor + +from util import histograms + + +class ColorHistogram(QWidget): + '''A Class which draws a scaling histogram in + a widget. + + Where counts are the bin values in the histogram + and colormap is a tuple of (R, G, B) tuples the same length + as counts. These are the colors to apply to the histogram bars. + Colormap can also contain a single tuple (R, G, B), in which case this is + the color applied to all bars of that histogram. + + The histogram assumes the bins were evenly spaced. + ''' + + def __init__(self, counts, colormap): + QWidget.__init__(self) + self._validate_input(counts, colormap) + self.counts = counts + self.n = np.sum(self.counts) + self.colormap = colormap + self.setMinimumSize(100, 50) + + def _validate_input(self, counts, colormap): + if len(counts) != len(colormap): + if len(colormap) != 3: + msg = '''Colormap must be a list of 3-tuples the same + length as counts or a 3-tuple''' + raise ValueError(msg) + + def paintEvent(self, evt): + # get the widget dimensions + orig_width = self.width() + orig_height = self.height() + + # fill perc % of the widget + perc = 1 + width = int(orig_width * perc) + height = int(orig_height * perc) + + # get the starting origin + x_orig = int((orig_width - width) / 2) + # we want to start at the bottom and draw up. + y_orig = orig_height - int((orig_height - height) / 2) + + # a running x-position + running_pos = x_orig + + # calculate to number of bars + nbars = len(self.counts) + + # calculate the bar widths, this compilcation is + # necessary because integer trunction severly cripples + # the layout. + remainder = width % nbars + bar_width = [int(width / nbars)] * nbars + for i in range(remainder): + bar_width[i]+=1 + + paint = QPainter() + paint.begin(self) + + # determine the scaling factor + max_val = np.max(self.counts) + scale = 1. * height / max_val + + # determine if we have a colormap and drop into the appopriate + # loop. + if hasattr(self.colormap[0], '__iter__'): + # assume we have a colormap + for i in range(len(self.counts)): + bar_height = self.counts[i] + r, g, b = self.colormap[i] + paint.setPen(QColor(r, g, b)) + paint.setBrush(QColor(r, g, b)) + paint.drawRect(running_pos, y_orig, bar_width[i], + -bar_height) + running_pos += bar_width[i] + + else: + # we have a tuple + r, g, b = self.colormap + paint.setPen(QColor(r, g, b)) + paint.setBrush(QColor(r, g, b)) + for i in range(len(self.counts)): + bar_height = self.counts[i] * scale + paint.drawRect(running_pos, y_orig, bar_width[i], + -bar_height) + running_pos += bar_width[i] + + paint.end() + + + def update_hist(self, counts, cmap): + self._validate_input(counts, cmap) + self.counts = counts + self.colormap = cmap + self.repaint() + + +class QuadHistogram(QWidget): + '''A class which uses ColorHistogram to draw + the 4 histograms of an image. R, G, B, and Value. + + The 4 histograms are layout out in a grid, + and can be specified horizontal or vertical, + and in which order ie. ['R', 'G', 'B', 'V'] + ''' + + def __init__(self, img, layout='vertical', order=['R', 'G', 'B', 'V']): + QWidget.__init__(self) + r, g, b, v = histograms(img, 100) + self.r_hist = ColorHistogram(r, (255, 0, 0)) + self.g_hist = ColorHistogram(g, (0, 255, 0)) + self.b_hist = ColorHistogram(b, (0, 0, 255)) + self.v_hist = ColorHistogram(v, (0, 0, 0)) + + self.layout = QGridLayout(self) + + order_map = {'R': self.r_hist, 'G': self.g_hist, 'B': self.b_hist, + 'V': self.v_hist} + + if layout=='vertical': + for i in range(len(order)): + self.layout.addWidget(order_map[order[i]], i, 0) + elif layout=='horizontal': + for i in range(len(order)): + self.layout.addWidget(order_map[order[i]], 0, i) + + def update_hists(self, img): + r, g, b, v = histograms(img, 100) + self.r_hist.update_hist(r, (255, 0, 0)) + self.g_hist.update_hist(g, (0, 255, 0)) + self.b_hist.update_hist(b, (0, 0, 255)) + self.v_hist.update_hist(v, (0, 0, 0)) \ No newline at end of file diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index 499a4cbd..f718890c 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -18,6 +18,7 @@ else: QPainter, QColor, QFrame) from PyQt4 import QtCore, QtGui from q_color_mixer import MixerPanel + from q_histogram import QuadHistogram except ImportError: print 'PyQT4 libraries not installed. Plugin not loaded.' @@ -124,121 +125,6 @@ else: self.v_value.setText(str(v)[:5]) - class Histogram(QWidget): - '''A Class which draws a scaling histogram in - a widget. - - The argument to the constructor 'vals' is a list of tuples - of the following form: - - vals = [(counts, colormap)] - - where counts are the bin values in the histogram - and colormap is a tuple of (R, G, B) tuples the same length - as counts. These are the colors to apply to the histogram bars. - Colormap can also contain a single tuple, in which case this is - the color applied to all bars of that histogram. - - Each histogram is drawn in order from left to right in its own - box and the values are scaled so that max(count) = height. - This is a linear scaling. - - The histogram assumes the bins were evenly spaced. - ''' - - def __init__(self, counts, colormap): - QWidget.__init__(self) - self._validate_input(counts, colormap) - self.counts = counts - self.n = np.sum(self.counts) - self.colormap = colormap - self.setMinimumSize(100, 50) - - def _validate_input(self, counts, colormap): - if len(counts) != len(colormap): - if len(colormap) != 1: - msg = 'Colormap must be same length as count or 1' - raise ValueError(msg) - - def paintEvent(self, evt): - # get the widget dimensions - orig_width = self.width() - orig_height = self.height() - - # fill perc % of the widget - perc = 1.0 - width = int(orig_width * perc) - height = int(orig_height * perc) - - # get the starting origin - x_orig = int((orig_width - width) / 2) - # we want to start at the bottom and draw up. - y_orig = orig_height - int((orig_height - height) / 2) - - # a running x-position - running_pos = x_orig - - # calculate to number of bars - nbars = len(self.counts) - - - # calculate the bar widths, this compilcation is - # necessary because integer trunction severly cripples - # the layout. - remainder = width % nbars - bar_width = [int(width / nbars)] * nbars - for i in range(remainder): - bar_width[i]+=1 - - paint = QPainter() - paint.begin(self) - - if len(self.colormap) == 1: - self.colormap = self.colormap * len(self.counts) - - # determine the scaling factor - max_val = np.max(self.counts) - scale = 1. * height / max_val - - # draw the bars for this graph - for i in range(len(self.counts)): - bar_height = self.counts[i] * scale - r, g, b = self.colormap[i] - paint.setPen(QColor(r, g, b)) - paint.setBrush(QColor(r, g, b)) - paint.drawRect(running_pos, y_orig, bar_width[i], -bar_height) - running_pos += bar_width[i] - - paint.end() - - - def update_hist(self, counts, cmap): - self._validate_input(counts, cmap) - self.counts = counts - self.colormap = cmap - self.repaint() - - - - class MultiHist(QFrame): - def __init__(self, vals): - QFrame.__init__(self) - - self.hists = [] - for counts, cmap in vals: - self.hists.append(Histogram(counts, cmap)) - - self.layout = QtGui.QGridLayout(self) - for i in range(len(self.hists))[::-1]: - self.layout.addWidget(self.hists[i], i, 0) - - - def update_hists(self, vals): - for i in range(len(vals)): - counts, cmap = vals[i] - self.hists[i].update_hist(counts, cmap) - - class FancyImageWindow(ImageWindow): def __init__(self, arr, mgr): ImageWindow.__init__(self, arr, mgr) @@ -253,9 +139,9 @@ else: self.mixer_panel.show() self.mixer_panel.set_callback(self.refresh_image) - self.rgb_hist = MultiHist(self.calc_hist()) - self.layout.addWidget(self.rgb_hist, 0, 1) - self.rgb_hist.show() + self.rgbv_hist = QuadHistogram(self.arr) + self.layout.addWidget(self.rgbv_hist, 0, 1) + self.rgbv_hist.show() self.rgb_hsv_disp = RGBHSVDisplay() self.layout.addWidget(self.rgb_hsv_disp, 1, 0) @@ -273,21 +159,13 @@ else: self.layout.addWidget(self.save_file, 1, 2) - def update_histogram(self): - self.rgb_hist.update_hists(self.calc_hist()) - - def calc_hist(self): - rvals, gvals, bvals, grays = \ - self.mixer_panel.mixer.histograms(100) - - vals = ((rvals, ((255,0,0),)),(gvals, ((0,255,0),)), - (bvals, ((0,0,255),)), (grays, ((0, 0, 0),))) - return vals + def update_histograms(self): + self.rgbv_hist.update_hists(self.arr) def refresh_image(self): pm = QPixmap.fromImage(self.label.img) self.label.setPixmap(pm) - self.update_histogram() + self.update_histograms() def scale_mouse_pos(self, x, y): width = self.label.width() diff --git a/scikits/image/io/_plugins/util.py b/scikits/image/io/_plugins/util.py index db8ed0eb..951ec16f 100644 --- a/scikits/image/io/_plugins/util.py +++ b/scikits/image/io/_plugins/util.py @@ -1,5 +1,6 @@ import numpy as np import _colormixer +import _histograms # utilities to make life easier for plugin writers. @@ -151,6 +152,26 @@ def prepare_for_display(npy_img): return out +def histograms(img, nbins): + '''Calculate the channel histograms of the current image. + + Parameters + ---------- + img : ndarray, ndim=3, dtype=np.uint8 + nbins : int + The number of bins. + + Returns + ------- + out : (rcounts, gcounts, bcounts, vcounts) + The binned histograms of the RGB channels and intensity values. + + This is a NAIVE histogram routine, meant primarily for fast display. + + ''' + + return _histograms.histograms(img, nbins) + class ColorMixer(object): ''' a class to manage mixing colors in an image. @@ -347,21 +368,3 @@ class ColorMixer(object): R, G, B = _colormixer.py_hsv_2_rgb(H, S, V) return (R, G, B) - def histograms(self, nbins): - '''Calculate the channel histograms of the current image. - - Parameters - ---------- - nbins : int - The number of bins. - - Returns - ------- - out : (rcounts, gcounts, bcounts, vcounts) - The binned histograms of the RGB channels and grayscale intensity. - - This is a NAIVE histogram routine, meant primarily for fast display. - - ''' - - return _colormixer.histograms(self.img, nbins) \ No newline at end of file diff --git a/scikits/image/io/setup.py b/scikits/image/io/setup.py index 2565d724..9c9cf023 100644 --- a/scikits/image/io/setup.py +++ b/scikits/image/io/setup.py @@ -15,12 +15,17 @@ def configuration(parent_package='', top_path=None): # This function tries to create C files from the given .pyx files. If # it fails, we build the checked-in .c files. - cython(['_plugins/_colormixer.pyx'], working_path=base_path) + cython(['_plugins/_colormixer.pyx', '_plugins/_histograms.pyx'], + working_path=base_path) config.add_extension('_plugins._colormixer', sources=['_plugins/_colormixer.c'], include_dirs=[get_numpy_include_dirs()]) + config.add_extension('_plugins._histograms', + sources=['_plugins/_histograms.c'], + include_dirs=[get_numpy_include_dirs()]) + return config if __name__ == '__main__': From c4f75b7d4776fbef7eb010651f793af13ceae1ef Mon Sep 17 00:00:00 2001 From: sccolbert Date: Fri, 6 Nov 2009 21:06:23 +0100 Subject: [PATCH 19/43] fixed the gamma correction in the color mixer. --- scikits/image/io/_plugins/_colormixer.pyx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scikits/image/io/_plugins/_colormixer.pyx b/scikits/image/io/_plugins/_colormixer.pyx index 6e0fa1f4..19f4fce0 100644 --- a/scikits/image/io/_plugins/_colormixer.pyx +++ b/scikits/image/io/_plugins/_colormixer.pyx @@ -180,6 +180,8 @@ def gamma(np.ndarray[np.uint8_t, ndim=3] img, cdef float r, g, b cdef int i, j + + gamma = 1./gamma for i in range(height): for j in range(width): r = stateimg[i,j,0] / 255. From 983ebd43f9d0b6a6f753c9e7ca291bc9ed2323aa Mon Sep 17 00:00:00 2001 From: sccolbert Date: Fri, 6 Nov 2009 21:12:22 +0100 Subject: [PATCH 20/43] updated string formatting for slider labels. --- scikits/image/io/_plugins/q_color_mixer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scikits/image/io/_plugins/q_color_mixer.py b/scikits/image/io/_plugins/q_color_mixer.py index 95cb74b7..4c37cc4f 100644 --- a/scikits/image/io/_plugins/q_color_mixer.py +++ b/scikits/image/io/_plugins/q_color_mixer.py @@ -36,7 +36,7 @@ class IntelligentSlider(QWidget): self.name_label.setAlignment(QtCore.Qt.AlignCenter) self.value_label = QLabel() - self.value_label.setText(str(self.slider.value() * self.a + self.b)) + self.value_label.setText('%2.2f' % (self.slider.value() * self.a + self.b)) self.value_label.setAlignment(QtCore.Qt.AlignCenter) self.layout = QGridLayout(self) @@ -59,7 +59,7 @@ class IntelligentSlider(QWidget): def set_value(self, val): self.manually_triggered = True self.slider.setValue(int((val - self.b) / self.a)) - self.value_label.setText(str(val)[:4]) + self.value_label.setText('%2.2f' % val) self.manually_triggered = False def val(self): From 384f801055c1ae9d07945cb5607665eb9d927486 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Fri, 6 Nov 2009 23:11:29 +0100 Subject: [PATCH 21/43] Made it so that aspect ratio is maintained on imshow and fancy imshow for the qt plugin. --- scikits/image/io/_plugins/qt_plugin.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index f718890c..628b8beb 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -15,7 +15,7 @@ else: try: from PyQt4.QtGui import (QApplication, QMainWindow, QImage, QPixmap, QLabel, QWidget, QVBoxLayout, QSlider, - QPainter, QColor, QFrame) + QPainter, QColor, QFrame, QLayoutItem) from PyQt4 import QtCore, QtGui from q_color_mixer import MixerPanel from q_histogram import QuadHistogram @@ -28,6 +28,7 @@ else: app = None + class LabelImage(QLabel): def __init__(self, parent, arr): QLabel.__init__(self) @@ -45,13 +46,25 @@ else: # if we didnt pass the stride. self.img = QImage(arr.data, arr.shape[1], arr.shape[0], arr.strides[0], QImage.Format_RGB888) - self.pm = QPixmap.fromImage(self.img) self.setPixmap(self.pm) + self.setMinimumSize(100, 100) def mouseMoveEvent(self, evt): self.parent.label_mouseMoveEvent(evt) + def resizeEvent(self, evt): + width = self.width() + pm = QPixmap.fromImage(self.img) + pm = pm.scaledToWidth(width) + self.setPixmap(pm) + + def update_image(self): + width = self.width() + pm = QPixmap.fromImage(self.img) + pm = pm.scaledToWidth(width) + self.setPixmap(pm) + class ImageWindow(QMainWindow): def __init__(self, arr, mgr): @@ -63,6 +76,7 @@ else: self.label = LabelImage(self, arr) self.layout.addWidget(self.label, 0, 0) + self.layout.addLayout self.mgr.add_window(self) self.main_widget.show() @@ -130,9 +144,7 @@ else: ImageWindow.__init__(self, arr, mgr) self.arr = arr - self.label.setScaledContents(True) self.label.setMouseTracking(True) - self.label.setMinimumSize(QtCore.QSize(100, 100)) self.mixer_panel = MixerPanel(self.arr) self.layout.addWidget(self.mixer_panel, 0, 2) @@ -163,8 +175,7 @@ else: self.rgbv_hist.update_hists(self.arr) def refresh_image(self): - pm = QPixmap.fromImage(self.label.img) - self.label.setPixmap(pm) + self.label.update_image() self.update_histograms() def scale_mouse_pos(self, x, y): From 775ff607cf22f7c6c4a6878caacaa23d9615127f Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sat, 7 Nov 2009 08:44:02 +0200 Subject: [PATCH 22/43] Align image to top so that pixel tracking is accurate. --- scikits/image/io/_plugins/qt_plugin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index 504d7e8a..dd0936b4 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -15,6 +15,7 @@ else: try: from PyQt4.QtGui import (QApplication, QMainWindow, QImage, QPixmap, QLabel, QWidget, QVBoxLayout) + from PyQt4.QtCore import Qt except ImportError: print 'PyQT4 libraries not installed. Plugin not loaded.' @@ -30,6 +31,7 @@ else: self.img = QImage(arr.data, arr.shape[1], arr.shape[0], arr.strides[0], QImage.Format_RGB888) self.pm = QPixmap.fromImage(self.img) + self.setAlignment(Qt.AlignTop) self.setPixmap(self.pm) From cc2b9ae6344125569298062612c815f64111fcb2 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Sat, 7 Nov 2009 14:58:06 +0100 Subject: [PATCH 23/43] fixed mouse tracking to not go out of bounds. Added save-to-file. --- scikits/image/io/_plugins/qt_plugin.py | 40 +++++++++++++++++++------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index 628b8beb..ff25abc8 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -48,6 +48,7 @@ else: arr.strides[0], QImage.Format_RGB888) self.pm = QPixmap.fromImage(self.img) self.setPixmap(self.pm) + self.setAlignment(QtCore.Qt.AlignTop) self.setMinimumSize(100, 100) def mouseMoveEvent(self, evt): @@ -56,8 +57,9 @@ else: def resizeEvent(self, evt): width = self.width() pm = QPixmap.fromImage(self.img) - pm = pm.scaledToWidth(width) - self.setPixmap(pm) + self.pm = pm.scaledToWidth(width) + self.setPixmap(self.pm) + self.setSizePolicy def update_image(self): width = self.width() @@ -163,24 +165,32 @@ else: self.layout.setRowStretch(0, 1) self.save_file = QtGui.QPushButton('Save to File') - self.save_variable = QtGui.QPushButton('Save to Variable') + self.save_file.clicked.connect(self.save_to_file) + #self.save_variable = QtGui.QPushButton('Save to Variable') self.save_file.show() - self.save_variable.show() + #self.save_variable.show() - self.layout.addWidget(self.save_variable, 1, 1) + #self.layout.addWidget(self.save_variable, 1, 1) self.layout.addWidget(self.save_file, 1, 2) def update_histograms(self): self.rgbv_hist.update_hists(self.arr) + def save_to_file(self): + from scikits.image import io + filename = str(QtGui.QFileDialog.getSaveFileName()) + if len(filename) == 0: + return + io.imsave(filename, self.arr) + def refresh_image(self): self.label.update_image() self.update_histograms() def scale_mouse_pos(self, x, y): - width = self.label.width() - height = self.label.height() + width = self.label.pm.width() + height = self.label.pm.height() x_frac = 1. * x / width y_frac = 1. * y / height width = self.arr.shape[1] @@ -193,10 +203,18 @@ else: x = evt.x() y = evt.y() x, y = self.scale_mouse_pos(x, y) - r = self.arr[y,x,0] - g = self.arr[y,x,1] - b = self.arr[y,x,2] - h, s, v = self.mixer_panel.mixer.rgb_2_hsv_pixel(r, g, b) + + # handle tracking out of array bounds + maxw = self.arr.shape[1] + maxh = self.arr.shape[0] + if x >= maxw or y >= maxh or x < 0 or y < 0: + r = g = b = h = s = v = '' + else: + r = self.arr[y,x,0] + g = self.arr[y,x,1] + b = self.arr[y,x,2] + h, s, v = self.mixer_panel.mixer.rgb_2_hsv_pixel(r, g, b) + self.rgb_hsv_disp.update_vals((x, y, r, g, b, h, s, v)) From ac8dadf1ce8856c27833331e300597631958babd Mon Sep 17 00:00:00 2001 From: sccolbert Date: Sat, 7 Nov 2009 16:10:07 +0100 Subject: [PATCH 24/43] added save_to_variable functionality. --- scikits/image/io/_plugins/qt_plugin.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index ff25abc8..9e698d13 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -28,6 +28,7 @@ else: app = None + variable_saved_image = None class LabelImage(QLabel): def __init__(self, parent, arr): @@ -166,17 +167,31 @@ else: self.save_file = QtGui.QPushButton('Save to File') self.save_file.clicked.connect(self.save_to_file) - #self.save_variable = QtGui.QPushButton('Save to Variable') + self.save_variable = QtGui.QPushButton('Save to Variable') + self.save_variable.clicked.connect(self.save_to_variable) self.save_file.show() - #self.save_variable.show() + self.save_variable.show() - #self.layout.addWidget(self.save_variable, 1, 1) + self.layout.addWidget(self.save_variable, 1, 1) self.layout.addWidget(self.save_file, 1, 2) def update_histograms(self): self.rgbv_hist.update_hists(self.arr) + def save_to_variable(self): + global variable_saved_image + variable_saved_image = self.arr.copy() + msg = QLabel('The image has been saved. Call *** to retrieve.') + dialog = QtGui.QDialog() + ok = QtGui.QPushButton('OK', msg) + ok.clicked.connect(dialog.accept) + ok.setDefault(True) + dialog.layout = QtGui.QGridLayout(dialog) + dialog.layout.addWidget(msg, 0, 0, 1, 3) + dialog.layout.addWidget(ok, 1, 1) + dialog.exec_() + def save_to_file(self): from scikits.image import io filename = str(QtGui.QFileDialog.getSaveFileName()) @@ -232,6 +247,10 @@ else: iw.show() + def retrieve_saved_image(): + global variable_saved_image + return variable_saved_image + def _app_show(): global app if app and window_manager.has_windows(): From c10f3a886c87cad699caf2c98ef6afa54f5f5e56 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sat, 7 Nov 2009 17:41:20 +0200 Subject: [PATCH 25/43] Add image stack. --- scikits/image/io/io.py | 31 ++++++++++++++++++++++++++++++- scikits/image/io/tests/test_io.py | 17 +++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 scikits/image/io/tests/test_io.py diff --git a/scikits/image/io/io.py b/scikits/image/io/io.py index 66d3b82b..a2a431ac 100644 --- a/scikits/image/io/io.py +++ b/scikits/image/io/io.py @@ -1,6 +1,35 @@ -__all__ = ['imread', 'imsave', 'imshow', 'show'] +__all__ = ['imread', 'imsave', 'imshow', 'show', 'push', 'pop'] from scikits.image.io._plugins import call as call_plugin +import numpy as np + +# Shared image queue +_image_stack = [] + +def push(img): + """Push an image onto the shared image stack. + + Parameters + ---------- + img : ndarray + Image to push. + + """ + if not isinstance(img, np.ndarray): + raise ValueError("Can only push ndarrays to the image stack.") + + _image_stack.append(img) + +def pop(): + """Pop and image from the shared image stack. + + Returns + ------- + img : ndarray + Image popped from the stack. + + """ + return _image_stack.pop() def imread(fname, as_grey=False, dtype=None, plugin=None, flatten=None, **plugin_args): diff --git a/scikits/image/io/tests/test_io.py b/scikits/image/io/tests/test_io.py new file mode 100644 index 00000000..dbf5a3fc --- /dev/null +++ b/scikits/image/io/tests/test_io.py @@ -0,0 +1,17 @@ +from numpy.testing import * +import numpy as np + +import scikits.image.io as io + +def test_stack_basic(): + x = np.arange(12).reshape(3, 4) + io.push(x) + + assert_array_equal(io.pop(), x) + +@raises(ValueError) +def test_stack_non_array(): + io.push([[1, 2, 3]]) + +if __name__ == "__main__": + run_module_suite() From 03129f7bba03a3b4a541509f98c0fc8f4d014937 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Sat, 7 Nov 2009 16:42:08 +0100 Subject: [PATCH 26/43] Added save to variable function using io.push() functionality. --- scikits/image/io/_plugins/qt_plugin.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index 9e698d13..aa706ae1 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -28,8 +28,6 @@ else: app = None - variable_saved_image = None - class LabelImage(QLabel): def __init__(self, parent, arr): QLabel.__init__(self) @@ -180,18 +178,24 @@ else: self.rgbv_hist.update_hists(self.arr) def save_to_variable(self): - global variable_saved_image - variable_saved_image = self.arr.copy() - msg = QLabel('The image has been saved. Call *** to retrieve.') + from scikits.image import io + from textwrap import dedent + img = self.arr.copy() + io.push(img) + msg = dedent(''' + The image has been pushed to the io stack. + Use io.pop() to retrieve the most recently pushed image.''') + msglabel = QLabel(msg) dialog = QtGui.QDialog() - ok = QtGui.QPushButton('OK', msg) + ok = QtGui.QPushButton('OK', dialog) ok.clicked.connect(dialog.accept) ok.setDefault(True) dialog.layout = QtGui.QGridLayout(dialog) - dialog.layout.addWidget(msg, 0, 0, 1, 3) + dialog.layout.addWidget(msglabel, 0, 0, 1, 3) dialog.layout.addWidget(ok, 1, 1) dialog.exec_() + def save_to_file(self): from scikits.image import io filename = str(QtGui.QFileDialog.getSaveFileName()) @@ -247,9 +251,6 @@ else: iw.show() - def retrieve_saved_image(): - global variable_saved_image - return variable_saved_image def _app_show(): global app From 5bbc0f8de2bbdeed222daca947d9da92206e21c2 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Sat, 7 Nov 2009 16:47:26 +0100 Subject: [PATCH 27/43] removed a dangler. --- scikits/image/io/_plugins/qt_plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index aa706ae1..bc987ba4 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -58,7 +58,7 @@ else: pm = QPixmap.fromImage(self.img) self.pm = pm.scaledToWidth(width) self.setPixmap(self.pm) - self.setSizePolicy + def update_image(self): width = self.width() From a99339f9d6f953b47dff49029d7c59e7723481fb Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sat, 7 Nov 2009 18:13:02 +0200 Subject: [PATCH 28/43] Add basic tests for _histograms. --- .../io/{ => _plugins}/tests/test_colormixer.py | 0 .../image/io/_plugins/tests/test_histograms.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+) rename scikits/image/io/{ => _plugins}/tests/test_colormixer.py (100%) create mode 100644 scikits/image/io/_plugins/tests/test_histograms.py diff --git a/scikits/image/io/tests/test_colormixer.py b/scikits/image/io/_plugins/tests/test_colormixer.py similarity index 100% rename from scikits/image/io/tests/test_colormixer.py rename to scikits/image/io/_plugins/tests/test_colormixer.py diff --git a/scikits/image/io/_plugins/tests/test_histograms.py b/scikits/image/io/_plugins/tests/test_histograms.py new file mode 100644 index 00000000..f1cbe1c5 --- /dev/null +++ b/scikits/image/io/_plugins/tests/test_histograms.py @@ -0,0 +1,16 @@ +from numpy.testing import * +import numpy as np + +import scikits.image.io._plugins._colormixer as cm +from scikits.image.io._plugins._histograms import histograms + +class TestHistogram: + def test_basic(self): + img = np.ones((50, 50, 3), dtype=np.uint8) + r, g, b, v = histograms(img, 255) + + for band in (r, g, b, v): + yield assert_equal, band.sum(), 50*50 + +if __name__ == "__main__": + run_module_suite() From ec5bba7682e4a6fd747ae5d1c6a5b7413e9b168a Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sat, 7 Nov 2009 23:22:06 +0200 Subject: [PATCH 29/43] io: Fix Qt import accidentally removed. --- scikits/image/io/_plugins/qt_plugin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index 55eba465..d66a9f74 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -17,6 +17,7 @@ else: QLabel, QWidget, QVBoxLayout, QSlider, QPainter, QColor, QFrame, QLayoutItem) from PyQt4 import QtCore, QtGui + from PyQt4.QtCore import Qt from q_color_mixer import MixerPanel from q_histogram import QuadHistogram From 3c3fa013361242bb319c7921de3020920d53e8c6 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sat, 7 Nov 2009 23:41:09 +0200 Subject: [PATCH 30/43] io: Combine qt imports. --- scikits/image/io/_plugins/qt_plugin.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index d66a9f74..e7e87390 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -17,7 +17,6 @@ else: QLabel, QWidget, QVBoxLayout, QSlider, QPainter, QColor, QFrame, QLayoutItem) from PyQt4 import QtCore, QtGui - from PyQt4.QtCore import Qt from q_color_mixer import MixerPanel from q_histogram import QuadHistogram @@ -47,7 +46,7 @@ else: self.img = QImage(arr.data, arr.shape[1], arr.shape[0], arr.strides[0], QImage.Format_RGB888) self.pm = QPixmap.fromImage(self.img) - self.setAlignment(Qt.AlignTop) + self.setAlignment(QtCore.Qt.AlignTop) self.setPixmap(self.pm) self.setAlignment(QtCore.Qt.AlignTop) self.setMinimumSize(100, 100) From 992d9df37e578ac880531aefcbec6c6ca718bba7 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sun, 8 Nov 2009 00:08:34 +0200 Subject: [PATCH 31/43] Add image viewer script. --- scikits/image/scripts/__init__.py | 0 scikits/image/scripts/scivi.py | 13 +++++++++++++ setup.py | 5 +++++ 3 files changed, 18 insertions(+) create mode 100644 scikits/image/scripts/__init__.py create mode 100755 scikits/image/scripts/scivi.py diff --git a/scikits/image/scripts/__init__.py b/scikits/image/scripts/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/scikits/image/scripts/scivi.py b/scikits/image/scripts/scivi.py new file mode 100755 index 00000000..553b975f --- /dev/null +++ b/scikits/image/scripts/scivi.py @@ -0,0 +1,13 @@ +"""scikits.image viewer""" +def main(): + import scikits.image.io as io + import sys + + if len(sys.argv) != 2: + print "Usage: scivi " + sys.exit(-1) + + io.use_plugin('qt') + io.imshow(io.imread(sys.argv[1]), fancy=True) + io.show() + diff --git a/setup.py b/setup.py index 160fca2d..bbff4ce5 100644 --- a/setup.py +++ b/setup.py @@ -78,4 +78,9 @@ if __name__ == "__main__": packages=setuptools.find_packages(), include_package_data=True, zip_safe=False, # the package can run out of an .egg file + + entry_points={ + 'console_scripts': [ + 'scivi = scikits.image.scripts.scivi:main'] + }, ) From 57a315240d8b844c54b964b0454f258aa89a8215 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sun, 8 Nov 2009 00:56:09 +0200 Subject: [PATCH 32/43] Remove `imsave` from matplotlib until fixed in their source. --- scikits/image/io/_plugins/matplotlib_plugin.ini | 3 ++- scikits/image/io/_plugins/matplotlib_plugin.py | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/scikits/image/io/_plugins/matplotlib_plugin.ini b/scikits/image/io/_plugins/matplotlib_plugin.ini index 84dc2e53..a0006843 100644 --- a/scikits/image/io/_plugins/matplotlib_plugin.ini +++ b/scikits/image/io/_plugins/matplotlib_plugin.ini @@ -1,4 +1,5 @@ [matplotlib] description = Display or save images using Matplotlib -provides = imshow, imsave +provides = imshow + diff --git a/scikits/image/io/_plugins/matplotlib_plugin.py b/scikits/image/io/_plugins/matplotlib_plugin.py index 349bbe8d..e45c56b6 100644 --- a/scikits/image/io/_plugins/matplotlib_plugin.py +++ b/scikits/image/io/_plugins/matplotlib_plugin.py @@ -1,4 +1 @@ -try: - from matplotlib.pyplot import imshow, imsave -except ImportError: - print "Could not import Matplotlib." +from matplotlib.pyplot import imshow From 1148a47691222d6771ed3e5f89a7cec621ff56c8 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sun, 8 Nov 2009 01:24:20 +0200 Subject: [PATCH 33/43] io: Add _app_show for matplotlib plugin. --- scikits/image/io/_plugins/matplotlib_plugin.ini | 3 +-- scikits/image/io/_plugins/matplotlib_plugin.py | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/scikits/image/io/_plugins/matplotlib_plugin.ini b/scikits/image/io/_plugins/matplotlib_plugin.ini index a0006843..39d78fbb 100644 --- a/scikits/image/io/_plugins/matplotlib_plugin.ini +++ b/scikits/image/io/_plugins/matplotlib_plugin.ini @@ -1,5 +1,4 @@ [matplotlib] description = Display or save images using Matplotlib -provides = imshow - +provides = imshow, _app_show diff --git a/scikits/image/io/_plugins/matplotlib_plugin.py b/scikits/image/io/_plugins/matplotlib_plugin.py index e45c56b6..7fb70da2 100644 --- a/scikits/image/io/_plugins/matplotlib_plugin.py +++ b/scikits/image/io/_plugins/matplotlib_plugin.py @@ -1 +1,5 @@ -from matplotlib.pyplot import imshow +from matplotlib.pyplot import imshow, show + +def _app_show(): + show() + From a51aa32c1cee492a0380b5ca971544acaa43b28b Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sun, 8 Nov 2009 01:43:58 +0200 Subject: [PATCH 34/43] Add scripts for launching without setuptools. --- scikits/image/scripts/scivi | 6 ++++++ scikits/image/scripts/scivi.py | 0 2 files changed, 6 insertions(+) create mode 100755 scikits/image/scripts/scivi mode change 100755 => 100644 scikits/image/scripts/scivi.py diff --git a/scikits/image/scripts/scivi b/scikits/image/scripts/scivi new file mode 100755 index 00000000..0da676ea --- /dev/null +++ b/scikits/image/scripts/scivi @@ -0,0 +1,6 @@ +#!/usr/bin/env python + +if __name__ == "__main__": + from scikits.image.scripts import scivi + scivi.main() + diff --git a/scikits/image/scripts/scivi.py b/scikits/image/scripts/scivi.py old mode 100755 new mode 100644 From a3737fa34c3233402f35ef77c836d7422ea8155f Mon Sep 17 00:00:00 2001 From: sccolbert Date: Sun, 8 Nov 2009 02:40:12 +0100 Subject: [PATCH 35/43] Added tests for colormixer and histograms. Moved tests up a directory level because nosetests doesnt see tests in a directory beginning with an _ (_plugins/). Moved fancy imshow to its own module scivi.py --- CONTRIBUTORS.txt | 4 +- scikits/image/io/_plugins/qt_plugin.ini | 2 +- scikits/image/io/_plugins/qt_plugin.py | 193 ++------------- scikits/image/io/_plugins/scivi.py | 233 ++++++++++++++++++ .../io/_plugins/tests/test_colormixer.py | 49 ---- scikits/image/io/setup.py | 1 + scikits/image/io/tests/test_colormixer.py | 140 +++++++++++ .../{_plugins => }/tests/test_histograms.py | 12 + 8 files changed, 411 insertions(+), 223 deletions(-) create mode 100644 scikits/image/io/_plugins/scivi.py delete mode 100644 scikits/image/io/_plugins/tests/test_colormixer.py create mode 100644 scikits/image/io/tests/test_colormixer.py rename scikits/image/io/{_plugins => }/tests/test_histograms.py (52%) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 6903e72c..ecbbbd90 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -10,8 +10,8 @@ - Mahipal Raythattha Documentation infrastructure -- Chris Colbert - OpenCV wrappers +- S. Chris Colbert + OpenCV wrappers, Scivi, Qt and Gtk gui bits. - Holger Rapp OpenCV functions and better OSX library loader diff --git a/scikits/image/io/_plugins/qt_plugin.ini b/scikits/image/io/_plugins/qt_plugin.ini index ae6cfbd4..9e98ba81 100644 --- a/scikits/image/io/_plugins/qt_plugin.ini +++ b/scikits/image/io/_plugins/qt_plugin.ini @@ -1,4 +1,4 @@ [qt] description = Fast image display using the Qt library -provides = imshow, _app_show +provides = imshow, _app_show, imsave diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index d66a9f74..a667439d 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -1,5 +1,5 @@ from util import prepare_for_display, window_manager, GuiLockError - +from textwrap import dedent import numpy as np import sys @@ -14,12 +14,8 @@ except GuiLockError, gle: else: try: from PyQt4.QtGui import (QApplication, QMainWindow, QImage, QPixmap, - QLabel, QWidget, QVBoxLayout, QSlider, - QPainter, QColor, QFrame, QLayoutItem) + QLabel, QWidget) from PyQt4 import QtCore, QtGui - from PyQt4.QtCore import Qt - from q_color_mixer import MixerPanel - from q_histogram import QuadHistogram except ImportError: print 'PyQT4 libraries not installed. Plugin not loaded.' @@ -29,10 +25,10 @@ else: app = None - class LabelImage(QLabel): + class ImageLabel(QLabel): def __init__(self, parent, arr): QLabel.__init__(self) - self.parent = parent + # we need to hold a reference to # arr because QImage doesn't copy the data # and the buffer must be alive as long @@ -47,14 +43,10 @@ else: self.img = QImage(arr.data, arr.shape[1], arr.shape[0], arr.strides[0], QImage.Format_RGB888) self.pm = QPixmap.fromImage(self.img) - self.setAlignment(Qt.AlignTop) self.setPixmap(self.pm) self.setAlignment(QtCore.Qt.AlignTop) self.setMinimumSize(100, 100) - def mouseMoveEvent(self, evt): - self.parent.label_mouseMoveEvent(evt) - def resizeEvent(self, evt): width = self.width() pm = QPixmap.fromImage(self.img) @@ -62,22 +54,16 @@ else: self.setPixmap(self.pm) - def update_image(self): - width = self.width() - pm = QPixmap.fromImage(self.img) - pm = pm.scaledToWidth(width) - self.setPixmap(pm) - - class ImageWindow(QMainWindow): def __init__(self, arr, mgr): QMainWindow.__init__(self) + self.setWindowTitle('scikits.image') self.mgr = mgr self.main_widget = QWidget() self.layout = QtGui.QGridLayout(self.main_widget) self.setCentralWidget(self.main_widget) - self.label = LabelImage(self, arr) + self.label = ImageLabel(self, arr) self.layout.addWidget(self.label, 0, 0) self.layout.addLayout self.mgr.add_window(self) @@ -88,156 +74,6 @@ else: # references to it self.mgr.remove_window(self) - def label_mouseMoveEvent(self, evt): - pass - - - class RGBHSVDisplay(QWidget): - def __init__(self): - QWidget.__init__(self) - self.posx_label = QLabel('X-pos:') - self.posx_value = QLabel() - self.posy_label = QLabel('Y-pos:') - self.posy_value = QLabel() - self.r_label = QLabel('R:') - self.r_value = QLabel() - self.g_label = QLabel('G:') - self.g_value = QLabel() - self.b_label = QLabel('B:') - self.b_value = QLabel() - self.h_label = QLabel('H:') - self.h_value = QLabel() - self.s_label = QLabel('S:') - self.s_value = QLabel() - self.v_label = QLabel('V:') - self.v_value = QLabel() - - self.layout = QtGui.QGridLayout(self) - self.layout.addWidget(self.posx_label, 0, 0) - self.layout.addWidget(self.posx_value, 0, 1) - self.layout.addWidget(self.posy_label, 1, 0) - self.layout.addWidget(self.posy_value, 1, 1) - self.layout.addWidget(self.r_label, 0, 2) - self.layout.addWidget(self.r_value, 0, 3) - self.layout.addWidget(self.g_label, 1, 2) - self.layout.addWidget(self.g_value, 1, 3) - self.layout.addWidget(self.b_label, 2, 2) - self.layout.addWidget(self.b_value, 2, 3) - self.layout.addWidget(self.h_label, 0, 4) - self.layout.addWidget(self.h_value, 0, 5) - self.layout.addWidget(self.s_label, 1, 4) - self.layout.addWidget(self.s_value, 1, 5) - self.layout.addWidget(self.v_label, 2, 4) - self.layout.addWidget(self.v_value, 2, 5) - - def update_vals(self, data): - xpos, ypos, r, g, b, h, s, v = data - self.posx_value.setText(str(xpos)[:5]) - self.posy_value.setText(str(ypos)[:5]) - self.r_value.setText(str(r)[:5]) - self.g_value.setText(str(g)[:5]) - self.b_value.setText(str(b)[:5]) - self.h_value.setText(str(h)[:5]) - self.s_value.setText(str(s)[:5]) - self.v_value.setText(str(v)[:5]) - - - class FancyImageWindow(ImageWindow): - def __init__(self, arr, mgr): - ImageWindow.__init__(self, arr, mgr) - self.arr = arr - - self.label.setMouseTracking(True) - - self.mixer_panel = MixerPanel(self.arr) - self.layout.addWidget(self.mixer_panel, 0, 2) - self.mixer_panel.show() - self.mixer_panel.set_callback(self.refresh_image) - - self.rgbv_hist = QuadHistogram(self.arr) - self.layout.addWidget(self.rgbv_hist, 0, 1) - self.rgbv_hist.show() - - self.rgb_hsv_disp = RGBHSVDisplay() - self.layout.addWidget(self.rgb_hsv_disp, 1, 0) - self.rgb_hsv_disp.show() - - self.layout.setColumnStretch(0, 1) - self.layout.setRowStretch(0, 1) - - self.save_file = QtGui.QPushButton('Save to File') - self.save_file.clicked.connect(self.save_to_file) - self.save_variable = QtGui.QPushButton('Save to Variable') - self.save_variable.clicked.connect(self.save_to_variable) - self.save_file.show() - self.save_variable.show() - - self.layout.addWidget(self.save_variable, 1, 1) - self.layout.addWidget(self.save_file, 1, 2) - - - def update_histograms(self): - self.rgbv_hist.update_hists(self.arr) - - def save_to_variable(self): - from scikits.image import io - from textwrap import dedent - img = self.arr.copy() - io.push(img) - msg = dedent(''' - The image has been pushed to the io stack. - Use io.pop() to retrieve the most recently pushed image.''') - msglabel = QLabel(msg) - dialog = QtGui.QDialog() - ok = QtGui.QPushButton('OK', dialog) - ok.clicked.connect(dialog.accept) - ok.setDefault(True) - dialog.layout = QtGui.QGridLayout(dialog) - dialog.layout.addWidget(msglabel, 0, 0, 1, 3) - dialog.layout.addWidget(ok, 1, 1) - dialog.exec_() - - - def save_to_file(self): - from scikits.image import io - filename = str(QtGui.QFileDialog.getSaveFileName()) - if len(filename) == 0: - return - io.imsave(filename, self.arr) - - def refresh_image(self): - self.label.update_image() - self.update_histograms() - - def scale_mouse_pos(self, x, y): - width = self.label.pm.width() - height = self.label.pm.height() - x_frac = 1. * x / width - y_frac = 1. * y / height - width = self.arr.shape[1] - height = self.arr.shape[0] - new_x = int(width * x_frac) - new_y = int(height * y_frac) - return(new_x, new_y) - - def label_mouseMoveEvent(self, evt): - x = evt.x() - y = evt.y() - x, y = self.scale_mouse_pos(x, y) - - # handle tracking out of array bounds - maxw = self.arr.shape[1] - maxh = self.arr.shape[0] - if x >= maxw or y >= maxh or x < 0 or y < 0: - r = g = b = h = s = v = '' - else: - r = self.arr[y,x,0] - g = self.arr[y,x,1] - b = self.arr[y,x,2] - h, s, v = self.mixer_panel.mixer.rgb_2_hsv_pixel(r, g, b) - - self.rgb_hsv_disp.update_vals((x, y, r, g, b, h, s, v)) - def imshow(arr, fancy=False): global app @@ -249,7 +85,8 @@ else: if not fancy: iw = ImageWindow(arr, window_manager) else: - iw = FancyImageWindow(arr, window_manager) + from scivi import SciviImageWindow + iw = SciviImageWindow(arr, window_manager) iw.show() @@ -260,3 +97,17 @@ else: app.exec_() else: print 'No images to show. See `imshow`.' + + + def imsave(filename, img): + # we can support for other than 3D uint8 here... + img = prepare_for_display(img) + qimg = QImage(img.data, img.shape[1], img.shape[0], + img.strides[0], QImage.Format_RGB888) + saved = qimg.save(filename) + if not saved: + msg = dedent( + '''The image was not saved. Allowable file formats + for the QT imsave plugin are: + BMP, JPG, JPEG, PNG, PPM, TIFF, XBM, XPM''') + raise RuntimeError(msg) diff --git a/scikits/image/io/_plugins/scivi.py b/scikits/image/io/_plugins/scivi.py new file mode 100644 index 00000000..c6197717 --- /dev/null +++ b/scikits/image/io/_plugins/scivi.py @@ -0,0 +1,233 @@ +''' +Scivi is written/maintained/developed by: + +S. Chris Colbert - sccolbert@gmail.com + +Scivi is free software and is part of the scikits.image project. + +Scivi is governed by the licenses of the scikits.image project. + +Please report any bugs to the author. + +The scivi module is not meant to be used directly. + +Use scikits.image.io.imshow(img, fancy=True)''' + +from textwrap import dedent +import numpy as np +import sys + +from PyQt4 import QtCore, QtGui +from PyQt4.QtGui import (QApplication, QMainWindow, QImage, QPixmap, + QLabel, QWidget, QVBoxLayout, QSlider, + QPainter, QColor, QFrame, QLayoutItem) + +from q_color_mixer import MixerPanel +from q_histogram import QuadHistogram + + +class ImageLabel(QLabel): + def __init__(self, parent, arr): + QLabel.__init__(self) + self.parent = parent + + # we need to hold a reference to + # arr because QImage doesn't copy the data + # and the buffer must be alive as long + # as the image is alive. + self.arr = arr + + # we also need to pass in the row-stride to + # the constructor, because we can't guarantee + # that every row of the numpy data is + # 4-byte aligned. Which Qt would require + # if we didnt pass the stride. + self.img = QImage(arr.data, arr.shape[1], arr.shape[0], + arr.strides[0], QImage.Format_RGB888) + self.pm = QPixmap.fromImage(self.img) + self.setPixmap(self.pm) + self.setAlignment(QtCore.Qt.AlignTop) + self.setMinimumSize(100, 100) + self.setMouseTracking(True) + + def mouseMoveEvent(self, evt): + self.parent.label_mouseMoveEvent(evt) + + def resizeEvent(self, evt): + width = self.width() + pm = QPixmap.fromImage(self.img) + self.pm = pm.scaledToWidth(width) + self.setPixmap(self.pm) + + def update_image(self): + width = self.width() + pm = QPixmap.fromImage(self.img) + pm = pm.scaledToWidth(width) + self.setPixmap(pm) + + +class RGBHSVDisplay(QWidget): + def __init__(self): + QWidget.__init__(self) + self.posx_label = QLabel('X-pos:') + self.posx_value = QLabel() + self.posy_label = QLabel('Y-pos:') + self.posy_value = QLabel() + self.r_label = QLabel('R:') + self.r_value = QLabel() + self.g_label = QLabel('G:') + self.g_value = QLabel() + self.b_label = QLabel('B:') + self.b_value = QLabel() + self.h_label = QLabel('H:') + self.h_value = QLabel() + self.s_label = QLabel('S:') + self.s_value = QLabel() + self.v_label = QLabel('V:') + self.v_value = QLabel() + + self.layout = QtGui.QGridLayout(self) + self.layout.addWidget(self.posx_label, 0, 0) + self.layout.addWidget(self.posx_value, 0, 1) + self.layout.addWidget(self.posy_label, 1, 0) + self.layout.addWidget(self.posy_value, 1, 1) + self.layout.addWidget(self.r_label, 0, 2) + self.layout.addWidget(self.r_value, 0, 3) + self.layout.addWidget(self.g_label, 1, 2) + self.layout.addWidget(self.g_value, 1, 3) + self.layout.addWidget(self.b_label, 2, 2) + self.layout.addWidget(self.b_value, 2, 3) + self.layout.addWidget(self.h_label, 0, 4) + self.layout.addWidget(self.h_value, 0, 5) + self.layout.addWidget(self.s_label, 1, 4) + self.layout.addWidget(self.s_value, 1, 5) + self.layout.addWidget(self.v_label, 2, 4) + self.layout.addWidget(self.v_value, 2, 5) + + def update_vals(self, data): + xpos, ypos, r, g, b, h, s, v = data + self.posx_value.setText(str(xpos)[:5]) + self.posy_value.setText(str(ypos)[:5]) + self.r_value.setText(str(r)[:5]) + self.g_value.setText(str(g)[:5]) + self.b_value.setText(str(b)[:5]) + self.h_value.setText(str(h)[:5]) + self.s_value.setText(str(s)[:5]) + self.v_value.setText(str(v)[:5]) + + + +class SciviImageWindow(QMainWindow): + def __init__(self, arr, mgr): + QMainWindow.__init__(self) + + self.arr = arr + + self.mgr = mgr + self.main_widget = QWidget() + self.layout = QtGui.QGridLayout(self.main_widget) + self.setCentralWidget(self.main_widget) + + self.label = ImageLabel(self, arr) + self.layout.addWidget(self.label, 0, 0) + self.layout.addLayout + self.mgr.add_window(self) + self.main_widget.show() + + self.setWindowTitle('Scivi - The scikits.image viewer.') + + self.mixer_panel = MixerPanel(self.arr) + self.layout.addWidget(self.mixer_panel, 0, 2) + self.mixer_panel.show() + self.mixer_panel.set_callback(self.refresh_image) + + self.rgbv_hist = QuadHistogram(self.arr) + self.layout.addWidget(self.rgbv_hist, 0, 1) + self.rgbv_hist.show() + + self.rgb_hsv_disp = RGBHSVDisplay() + self.layout.addWidget(self.rgb_hsv_disp, 1, 0) + self.rgb_hsv_disp.show() + + self.layout.setColumnStretch(0, 1) + self.layout.setRowStretch(0, 1) + + self.save_file = QtGui.QPushButton('Save to File') + self.save_file.clicked.connect(self.save_to_file) + self.save_stack = QtGui.QPushButton('Save to Stack') + self.save_stack.clicked.connect(self.save_to_stack) + self.save_file.show() + self.save_stack.show() + + self.layout.addWidget(self.save_stack, 1, 1) + self.layout.addWidget(self.save_file, 1, 2) + + + def closeEvent(self, event): + # Allow window to be destroyed by removing any + # references to it + self.mgr.remove_window(self) + + def update_histograms(self): + self.rgbv_hist.update_hists(self.arr) + + def refresh_image(self): + self.label.update_image() + self.update_histograms() + + def scale_mouse_pos(self, x, y): + width = self.label.pm.width() + height = self.label.pm.height() + x_frac = 1. * x / width + y_frac = 1. * y / height + width = self.arr.shape[1] + height = self.arr.shape[0] + new_x = int(width * x_frac) + new_y = int(height * y_frac) + return(new_x, new_y) + + def label_mouseMoveEvent(self, evt): + x = evt.x() + y = evt.y() + x, y = self.scale_mouse_pos(x, y) + + # handle tracking out of array bounds + maxw = self.arr.shape[1] + maxh = self.arr.shape[0] + if x >= maxw or y >= maxh or x < 0 or y < 0: + r = g = b = h = s = v = '' + else: + r = self.arr[y,x,0] + g = self.arr[y,x,1] + b = self.arr[y,x,2] + h, s, v = self.mixer_panel.mixer.rgb_2_hsv_pixel(r, g, b) + + self.rgb_hsv_disp.update_vals((x, y, r, g, b, h, s, v)) + + + def save_to_stack(self): + from scikits.image import io + img = self.arr.copy() + io.push(img) + msg = dedent(''' + The image has been pushed to the io stack. + Use io.pop() to retrieve the most recently + pushed image.''') + msglabel = QLabel(msg) + dialog = QtGui.QDialog() + ok = QtGui.QPushButton('OK', dialog) + ok.clicked.connect(dialog.accept) + ok.setDefault(True) + dialog.layout = QtGui.QGridLayout(dialog) + dialog.layout.addWidget(msglabel, 0, 0, 1, 3) + dialog.layout.addWidget(ok, 1, 1) + dialog.exec_() + + def save_to_file(self): + from scikits.image import io + filename = str(QtGui.QFileDialog.getSaveFileName()) + if len(filename) == 0: + return + io.imsave(filename, self.arr) + + diff --git a/scikits/image/io/_plugins/tests/test_colormixer.py b/scikits/image/io/_plugins/tests/test_colormixer.py deleted file mode 100644 index 6ea620eb..00000000 --- a/scikits/image/io/_plugins/tests/test_colormixer.py +++ /dev/null @@ -1,49 +0,0 @@ -from numpy.testing import * -import numpy as np - -import scikits.image.io._plugins._colormixer as cm - -class ColorMixerTest(object): - def setup(self): - self.state = np.ones((18, 33, 3), dtype=np.uint8) * 200 - self.img = np.zeros_like(self.state) - - def test_basic(self): - self.op(self.img, self.state, 0, self.positive) - assert_array_equal(self.img[..., 0], - self.py_op(self.state[..., 0], self.positive)) - - def test_clip(self): - self.op(self.img, self.state, 0, self.positive_clip) - assert_array_equal(self.img[..., 0], - np.ones_like(self.img[..., 0]) * 255) - - def test_negative(self): - self.op(self.img, self.state, 0, self.negative) - assert_array_equal(self.img[..., 0], - self.py_op(self.state[..., 0], self.negative)) - - def test_negative_clip(self): - self.op(self.img, self.state, 0, self.negative_clip) - assert_array_equal(self.img[..., 0], - np.zeros_like(self.img[..., 0])) - -class TestColorMixerAdd(ColorMixerTest): - op = cm.add - py_op = np.add - positive = 50 - positive_clip = 56 - negative = -50 - negative_clip = -220 - -class TestColorMixerMul(ColorMixerTest): - op = cm.multiply - py_op = np.multiply - positive = 1.2 - positive_clip = 2 - negative = 0.5 - negative_clip = -0.5 - - -if __name__ == "__main__": - run_module_suite() diff --git a/scikits/image/io/setup.py b/scikits/image/io/setup.py index 9c9cf023..769ead42 100644 --- a/scikits/image/io/setup.py +++ b/scikits/image/io/setup.py @@ -11,6 +11,7 @@ def configuration(parent_package='', top_path=None): config = Configuration('io', parent_package, top_path) config.add_data_dir('tests') + config.add_data_dir('_plugins/tests') config.add_data_files('_plugins/*.ini') # This function tries to create C files from the given .pyx files. If diff --git a/scikits/image/io/tests/test_colormixer.py b/scikits/image/io/tests/test_colormixer.py new file mode 100644 index 00000000..72e4aed0 --- /dev/null +++ b/scikits/image/io/tests/test_colormixer.py @@ -0,0 +1,140 @@ +from numpy.testing import * +import numpy as np + +import scikits.image.io._plugins._colormixer as cm + +class ColorMixerTest(object): + def setup(self): + self.state = np.ones((18, 33, 3), dtype=np.uint8) * 200 + self.img = np.zeros_like(self.state) + + def test_basic(self): + self.op(self.img, self.state, 0, self.positive) + assert_array_equal(self.img[..., 0], + self.py_op(self.state[..., 0], self.positive)) + + def test_clip(self): + self.op(self.img, self.state, 0, self.positive_clip) + assert_array_equal(self.img[..., 0], + np.ones_like(self.img[..., 0]) * 255) + + def test_negative(self): + self.op(self.img, self.state, 0, self.negative) + assert_array_equal(self.img[..., 0], + self.py_op(self.state[..., 0], self.negative)) + + def test_negative_clip(self): + self.op(self.img, self.state, 0, self.negative_clip) + assert_array_equal(self.img[..., 0], + np.zeros_like(self.img[..., 0])) + + +class TestColorMixerAdd(ColorMixerTest): + op = cm.add + py_op = np.add + positive = 50 + positive_clip = 56 + negative = -50 + negative_clip = -220 + + +class TestColorMixerMul(ColorMixerTest): + op = cm.multiply + py_op = np.multiply + positive = 1.2 + positive_clip = 2 + negative = 0.5 + negative_clip = -0.5 + + +class TestColorMixerBright(object): + + def setup(self): + self.state = np.ones((18, 33, 3), dtype=np.uint8) * 200 + self.img = np.zeros_like(self.state) + + def test_brightness_pos(self): + cm.brightness(self.img, self.state, 1.25, 1) + assert_array_equal(self.img, np.ones_like(self.img) * 251) + + def test_brightness_neg(self): + cm.brightness(self.img, self.state, 0.5, -50) + assert_array_equal(self.img, np.ones_like(self.img) * 50) + + def test_brightness_pos_clip(self): + cm.brightness(self.img, self.state, 2, 0) + assert_array_equal(self.img, np.ones_like(self.img) * 255) + + def test_brightness_neg_clip(self): + cm.brightness(self.img, self.state, 0, 0) + assert_array_equal(self.img, np.zeros_like(self.img)) + + +class TestColorMixer(object): + + def setup(self): + self.state = np.ones((18, 33, 3), dtype=np.uint8) * 50 + self.img = np.zeros_like(self.state) + + def test_sigmoid(self): + import math + alpha = 1.5 + beta = 1.5 + c1 = 1 / (1 + math.exp(beta)) + c2 = 1 / (1 + math.exp(beta - alpha)) - c1 + state = self.state / 255. + cm.sigmoid_gamma(self.img, self.state, alpha, beta) + img = 1 / (1 + np.exp(beta - state * alpha)) + img = np.asarray((img - c1) / c2 * 255, dtype='uint8') + assert_almost_equal(img, self.img) + + def test_gamma(self): + gamma = 1.5 + cm.gamma(self.img, self.state, gamma) + img = np.asarray(((self.state/255.)**(1/gamma))*255, dtype='uint8') + assert_array_almost_equal(img, self.img) + + def test_rgb_2_hsv(self): + r = 255 + g = 0 + b = 0 + h, s, v = cm.py_rgb_2_hsv(r, g, b) + assert_almost_equal(np.array([h]), np.array([0])) + assert_almost_equal(np.array([s]), np.array([1])) + assert_almost_equal(np.array([v]), np.array([1])) + + def test_hsv_2_rgb(self): + h = 0 + s = 1 + v = 1 + r, g, b = cm.py_hsv_2_rgb(h, s, v) + assert_almost_equal(np.array([r]), np.array([255])) + assert_almost_equal(np.array([g]), np.array([0])) + assert_almost_equal(np.array([b]), np.array([0])) + + + def test_hsv_add(self): + cm.hsv_add(self.img, self.state, 360, 0, 0) + assert_almost_equal(self.img, self.state) + + def test_hsv_add_clip_neg(self): + cm.hsv_add(self.img, self.state, 0, 0, -1) + assert_equal(self.img, np.zeros_like(self.state)) + + def test_hsv_add_clip_pos(self): + cm.hsv_add(self.img, self.state, 0, 0, 1) + assert_equal(self.img, np.ones_like(self.state)*255) + + def test_hsv_mul(self): + cm.hsv_multiply(self.img, self.state, 360, 1, 1) + assert_almost_equal(self.img, self.state) + + def test_hsv_mul_clip_neg(self): + cm.hsv_multiply(self.img, self.state, 0, 0, 0) + assert_equal(self.img, np.zeros_like(self.state)) + + + + +if __name__ == "__main__": + run_module_suite() diff --git a/scikits/image/io/_plugins/tests/test_histograms.py b/scikits/image/io/tests/test_histograms.py similarity index 52% rename from scikits/image/io/_plugins/tests/test_histograms.py rename to scikits/image/io/tests/test_histograms.py index f1cbe1c5..76589e3b 100644 --- a/scikits/image/io/_plugins/tests/test_histograms.py +++ b/scikits/image/io/tests/test_histograms.py @@ -12,5 +12,17 @@ class TestHistogram: for band in (r, g, b, v): yield assert_equal, band.sum(), 50*50 + def test_counts(self): + channel = np.arange(255).reshape(51, 5) + img = np.empty((51, 5, 3), dtype='uint8') + img[:,:,0] = channel + img[:,:,1] = channel + img[:,:,2] = channel + r, g, b, v = histograms(img, 255) + assert_array_equal(r, g) + assert_array_equal(r, b) + assert_array_equal(r, v) + assert_array_equal(r, np.ones(255)) + if __name__ == "__main__": run_module_suite() From 196ab7530aa23e6dfc8fb1823b8557961e1cb7d3 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Sun, 8 Nov 2009 05:28:24 +0100 Subject: [PATCH 36/43] first go at multithreading the mixer. --- scikits/image/io/_plugins/_colormixer.pyx | 191 +++++++++++----------- scikits/image/io/_plugins/util.py | 81 ++++++++- 2 files changed, 173 insertions(+), 99 deletions(-) diff --git a/scikits/image/io/_plugins/_colormixer.pyx b/scikits/image/io/_plugins/_colormixer.pyx index 19f4fce0..48450473 100644 --- a/scikits/image/io/_plugins/_colormixer.pyx +++ b/scikits/image/io/_plugins/_colormixer.pyx @@ -15,8 +15,8 @@ cimport numpy as np import cython cdef extern from "math.h": - float exp(float) - float pow(float, float) + float exp(float) nogil + float pow(float, float) nogil @cython.boundscheck(False) @@ -46,15 +46,16 @@ def add(np.ndarray[np.uint8_t, ndim=3] img, cdef np.int16_t op_result cdef int i, j - for i in range(height): - for j in range(width): - op_result = (stateimg[i,j,k] + n) - if op_result > 255: - img[i, j, k] = 255 - elif op_result < 0: - img[i, j, k] = 0 - else: - img[i, j, k] = op_result + with nogil: + for i from 0 <= i < height: + for j from 0 <= j < width: + op_result = (stateimg[i,j,k] + n) + if op_result > 255: + img[i, j, k] = 255 + elif op_result < 0: + img[i, j, k] = 0 + else: + img[i, j, k] = op_result @cython.boundscheck(False) @@ -84,15 +85,16 @@ def multiply(np.ndarray[np.uint8_t, ndim=3] img, cdef float op_result cdef int i, j - for i in range(height): - for j in range(width): - op_result = (stateimg[i,j,k] * n) - if op_result > 255: - img[i, j, k] = 255 - elif op_result < 0: - img[i, j, k] = 0 - else: - img[i, j, k] = op_result + with nogil: + for i from 0 <= i < height: + for j from 0 <= j < width: + op_result = (stateimg[i,j,k] * n) + if op_result > 255: + img[i, j, k] = 255 + elif op_result < 0: + img[i, j, k] = 0 + else: + img[i, j, k] = op_result @cython.boundscheck(False) @@ -122,17 +124,18 @@ def brightness(np.ndarray[np.uint8_t, ndim=3] img, cdef float op_result cdef int i, j, k - for i in range(height): - for j in range(width): - for k in range(3): - op_result = ((stateimg[i,j,k] * factor + offset)) + with nogil: + for i from 0 <= i < height: + for j from 0 <= j < width: + for k from 0 <= k < 3: + op_result = ((stateimg[i,j,k] * factor + offset)) - if op_result > 255: - img[i, j, k] = 255 - elif op_result < 0: - img[i, j, k] = 0 - else: - img[i, j, k] = op_result + if op_result > 255: + img[i, j, k] = 255 + elif op_result < 0: + img[i, j, k] = 0 + else: + img[i, j, k] = op_result @cython.boundscheck(False) @@ -144,29 +147,30 @@ def sigmoid_gamma(np.ndarray[np.uint8_t, ndim=3] img, cdef int width = img.shape[1] cdef float c1, c2, r, g, b - cdef int i, j, k - for i in range(height): - for j in range(width): - r = stateimg[i,j,0] / 255. - g = stateimg[i,j,1] / 255. - b = stateimg[i,j,2] / 255. - c1 = 1 / (1 + exp(beta)) - c2 = 1 / (1 + exp(beta - alpha)) - c1 + with nogil: + for i from 0 <= i < height: + for j from 0 <= j < width: + r = stateimg[i,j,0] / 255. + g = stateimg[i,j,1] / 255. + b = stateimg[i,j,2] / 255. - r = 1 / (1 + exp(beta - r * alpha)) - r = (r - c1) / c2 + c1 = 1 / (1 + exp(beta)) + c2 = 1 / (1 + exp(beta - alpha)) - c1 - g = 1 / (1 + exp(beta - g * alpha)) - g = (g - c1) / c2 + r = 1 / (1 + exp(beta - r * alpha)) + r = (r - c1) / c2 - b = 1 / (1 + exp(beta - b * alpha)) - b = (b - c1) / c2 + g = 1 / (1 + exp(beta - g * alpha)) + g = (g - c1) / c2 - img[i,j,0] = (r * 255) - img[i,j,1] = (g * 255) - img[i,j,2] = (b * 255) + b = 1 / (1 + exp(beta - b * alpha)) + b = (b - c1) / c2 + + img[i,j,0] = (r * 255) + img[i,j,1] = (g * 255) + img[i,j,2] = (b * 255) @cython.boundscheck(False) @@ -182,19 +186,21 @@ def gamma(np.ndarray[np.uint8_t, ndim=3] img, cdef int i, j gamma = 1./gamma - for i in range(height): - for j in range(width): - r = stateimg[i,j,0] / 255. - g = stateimg[i,j,1] / 255. - b = stateimg[i,j,2] / 255. - img[i,j,0] = (pow(r, gamma) * 255) - img[i,j,1] = (pow(g, gamma) * 255) - img[i,j,2] = (pow(b, gamma) * 255) + with nogil: + for i from 0 <= i < height: + for j from 0 <= j < width: + r = stateimg[i,j,0] / 255. + g = stateimg[i,j,1] / 255. + b = stateimg[i,j,2] / 255. + + img[i,j,0] = (pow(r, gamma) * 255) + img[i,j,1] = (pow(g, gamma) * 255) + img[i,j,2] = (pow(b, gamma) * 255) -cdef void rgb_2_hsv(float* RGB, float* HSV): +cdef void rgb_2_hsv(float* RGB, float* HSV) nogil: cdef float R, G, B, H, S, V, MAX, MIN R = RGB[0] G = RGB[1] @@ -256,7 +262,7 @@ cdef void rgb_2_hsv(float* RGB, float* HSV): HSV[2] = V -cdef void hsv_2_rgb(float* HSV, float* RGB): +cdef void hsv_2_rgb(float* HSV, float* RGB) nogil: cdef float H, S, V cdef float f, p, q, t, r, g, b cdef int hi @@ -440,28 +446,30 @@ def hsv_add(np.ndarray[np.uint8_t, ndim=3] img, cdef int i, j - for i in range(height): - for j in range(width): - RGB[0] = stateimg[i, j, 0] - RGB[1] = stateimg[i, j, 1] - RGB[2] = stateimg[i, j, 2] + with nogil: + for i from 0 <= i < height: + for j from 0 <= j < width: + RGB[0] = stateimg[i, j, 0] + RGB[1] = stateimg[i, j, 1] + RGB[2] = stateimg[i, j, 2] - rgb_2_hsv(RGB, HSV) + rgb_2_hsv(RGB, HSV) - # Add operation - HSV[0] += h_amt - HSV[1] += s_amt - HSV[2] += v_amt + # Add operation + HSV[0] += h_amt + HSV[1] += s_amt + HSV[2] += v_amt - hsv_2_rgb(HSV, RGB) + hsv_2_rgb(HSV, RGB) - RGB[0] *= 255 - RGB[1] *= 255 - RGB[2] *= 255 + RGB[0] *= 255 + RGB[1] *= 255 + RGB[2] *= 255 + + img[i, j, 0] = RGB[0] + img[i, j, 1] = RGB[1] + img[i, j, 2] = RGB[2] - img[i, j, 0] = RGB[0] - img[i, j, 1] = RGB[1] - img[i, j, 2] = RGB[2] @cython.boundscheck(False) def hsv_multiply(np.ndarray[np.uint8_t, ndim=3] img, @@ -508,28 +516,29 @@ def hsv_multiply(np.ndarray[np.uint8_t, ndim=3] img, cdef int i, j - for i in range(height): - for j in range(width): - RGB[0] = stateimg[i, j, 0] - RGB[1] = stateimg[i, j, 1] - RGB[2] = stateimg[i, j, 2] + with nogil: + for i from 0 <= i < height: + for j from 0 <= j < width: + RGB[0] = stateimg[i, j, 0] + RGB[1] = stateimg[i, j, 1] + RGB[2] = stateimg[i, j, 2] - rgb_2_hsv(RGB, HSV) + rgb_2_hsv(RGB, HSV) - # Multiply operation - HSV[0] += h_amt - HSV[1] *= s_amt - HSV[2] *= v_amt + # Multiply operation + HSV[0] += h_amt + HSV[1] *= s_amt + HSV[2] *= v_amt - hsv_2_rgb(HSV, RGB) + hsv_2_rgb(HSV, RGB) - RGB[0] *= 255 - RGB[1] *= 255 - RGB[2] *= 255 + RGB[0] *= 255 + RGB[1] *= 255 + RGB[2] *= 255 - img[i, j, 0] = RGB[0] - img[i, j, 1] = RGB[1] - img[i, j, 2] = RGB[2] + img[i, j, 0] = RGB[0] + img[i, j, 1] = RGB[1] + img[i, j, 2] = RGB[2] diff --git a/scikits/image/io/_plugins/util.py b/scikits/image/io/_plugins/util.py index 951ec16f..6d976deb 100644 --- a/scikits/image/io/_plugins/util.py +++ b/scikits/image/io/_plugins/util.py @@ -1,8 +1,11 @@ import numpy as np import _colormixer import _histograms +import threading +import multiprocessing # utilities to make life easier for plugin writers. +CPU_COUNT = multiprocessing.cpu_count() class GuiLockError(Exception): def __init__(self, msg): @@ -173,6 +176,52 @@ def histograms(img, nbins): return _histograms.histograms(img, nbins) +class ImgThread(threading.Thread): + def __init__(self, func, *args): + super(ImgThread, self).__init__() + self.func = func + self.args = args + + def run(self): + self.func(*self.args) + +class ThreadDispatch(object): + def __init__(self, img, stateimg, func, *args): + + width = img.shape[1] + height = img.shape[0] + self.cores = CPU_COUNT + self.threads = [] + self.chunks = [] + if self.cores == 2: + self.chunks.append((img[:, :(width/2), :], + stateimg[:, :(width/2), :])) + self.chunks.append((img[:, (width/2):, :], + stateimg[:, (width/2):, :])) + elif self.cores == 4: + self.chunks.append((img[:(height/2), :(width/2), :], + stateimg[:(height/2), :(width/2), :])) + self.chunks.append((img[:(height/2), (width/2):, :], + stateimg[:(height/2), (width/2):, :])) + self.chunks.append((img[(height/2):, :(width/2), :], + stateimg[(height/2):, :(width/2), :])) + self.chunks.append((img[(height/2):, (width/2):, :], + stateimg[(height/2):, (width/2):, :])) + else: + raise ValueError('Cant handle your weird machine') + + for i in range(self.cores): + self.threads.append(ImgThread(func, self.chunks[i][0], + self.chunks[i][1], *args)) + + def run(self): + for t in self.threads: + t.start() + for t in self.threads: + t.join() + + + class ColorMixer(object): ''' a class to manage mixing colors in an image. The input array must be an RGB uint8 image. @@ -244,8 +293,11 @@ class ColorMixer(object): ''' assert channel in self.valid_channels + pool = ThreadDispatch(self.img, self.stateimg, + _colormixer.add, channel, ammount) + pool.run() + - _colormixer.add(self.img, self.stateimg, channel, ammount) def multiply(self, channel, ammount): '''Mutliply the indicated channel by the specified value. @@ -261,8 +313,10 @@ class ColorMixer(object): ''' assert channel in self.valid_channels + pool = ThreadDispatch(self.img, self.stateimg, + _colormixer.multiply, channel, ammount) + pool.run() - _colormixer.multiply(self.img, self.stateimg, channel, ammount) def brightness(self, factor, offset): '''Adjust the brightness off an image with an offset and factor. @@ -277,13 +331,21 @@ class ColorMixer(object): result = clip((pixel + offset)*factor) ''' - _colormixer.brightness(self.img, self.stateimg, factor, offset) + pool = ThreadDispatch(self.img, self.stateimg, + _colormixer.brightness, factor, offset) + pool.run() + def sigmoid_gamma(self, alpha, beta): - _colormixer.sigmoid_gamma(self.img, self.stateimg, alpha, beta) + pool = ThreadDispatch(self.img, self.stateimg, + _colormixer.sigmoid_gamma, alpha, beta) + pool.run() + def gamma(self, gamma): - _colormixer.gamma(self.img, self.stateimg, gamma) + pool = ThreadDispatch(self.img, self.stateimg, + _colormixer.gamma, gamma) + pool.run() def hsv_add(self, h_amt, s_amt, v_amt): '''Adjust the H, S, V channels of an image by a constant ammount. @@ -301,7 +363,9 @@ class ColorMixer(object): The ammount to add to the value (-1..1) ''' - _colormixer.hsv_add(self.img, self.stateimg, h_amt, s_amt, v_amt) + pool = ThreadDispatch(self.img, self.stateimg, + _colormixer.hsv_add, h_amt, s_amt, v_amt) + pool.run() def hsv_multiply(self, h_amt, s_amt, v_amt): '''Adjust the H, S, V channels of an image by a constant ammount. @@ -323,8 +387,9 @@ class ColorMixer(object): The ammount to multiply to the value (0..1) ''' - _colormixer.hsv_multiply(self.img, self.stateimg, h_amt, s_amt, v_amt) - + pool = ThreadDispatch(self.img, self.stateimg, + _colormixer.hsv_multiply, h_amt, s_amt, v_amt) + pool.run() def rgb_2_hsv_pixel(self, R, G, B): '''Convert an RGB value to HSV From 4beb9eb16b7da82bd32bf1086d8c336036bb19de Mon Sep 17 00:00:00 2001 From: sccolbert Date: Sun, 8 Nov 2009 05:39:02 +0100 Subject: [PATCH 37/43] added better logic to the thread dispatcher. --- scikits/image/io/_plugins/util.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/scikits/image/io/_plugins/util.py b/scikits/image/io/_plugins/util.py index 6d976deb..6ef1af48 100644 --- a/scikits/image/io/_plugins/util.py +++ b/scikits/image/io/_plugins/util.py @@ -193,12 +193,11 @@ class ThreadDispatch(object): self.cores = CPU_COUNT self.threads = [] self.chunks = [] - if self.cores == 2: - self.chunks.append((img[:, :(width/2), :], - stateimg[:, :(width/2), :])) - self.chunks.append((img[:, (width/2):, :], - stateimg[:, (width/2):, :])) - elif self.cores == 4: + + if self.cores == 1: + self.chunks.append((img, stateimg)) + + elif self.cores >= 4: self.chunks.append((img[:(height/2), :(width/2), :], stateimg[:(height/2), :(width/2), :])) self.chunks.append((img[:(height/2), (width/2):, :], @@ -207,8 +206,13 @@ class ThreadDispatch(object): stateimg[(height/2):, :(width/2), :])) self.chunks.append((img[(height/2):, (width/2):, :], stateimg[(height/2):, (width/2):, :])) + + # if they dont have 1, or 4 or more, 2 is good. else: - raise ValueError('Cant handle your weird machine') + self.chunks.append((img[:, :(width/2), :], + stateimg[:, :(width/2), :])) + self.chunks.append((img[:, (width/2):, :], + stateimg[:, (width/2):, :])) for i in range(self.cores): self.threads.append(ImgThread(func, self.chunks[i][0], From db7583b62aad9eaf10c67e89cd46087b36c77d81 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sun, 8 Nov 2009 09:44:52 +0200 Subject: [PATCH 38/43] io: Move plugin tests to io/tests. --- scikits/image/io/setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scikits/image/io/setup.py b/scikits/image/io/setup.py index 769ead42..9c9cf023 100644 --- a/scikits/image/io/setup.py +++ b/scikits/image/io/setup.py @@ -11,7 +11,6 @@ def configuration(parent_package='', top_path=None): config = Configuration('io', parent_package, top_path) config.add_data_dir('tests') - config.add_data_dir('_plugins/tests') config.add_data_files('_plugins/*.ini') # This function tries to create C files from the given .pyx files. If From a6de1409e0cce5d4422e9552f459cd16cbce4dc5 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Sun, 8 Nov 2009 09:13:40 +0100 Subject: [PATCH 39/43] added try except to deal with missing multiprocessing. --- scikits/image/io/_plugins/util.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scikits/image/io/_plugins/util.py b/scikits/image/io/_plugins/util.py index 6ef1af48..40f6e92b 100644 --- a/scikits/image/io/_plugins/util.py +++ b/scikits/image/io/_plugins/util.py @@ -2,10 +2,14 @@ import numpy as np import _colormixer import _histograms import threading -import multiprocessing + # utilities to make life easier for plugin writers. -CPU_COUNT = multiprocessing.cpu_count() +try: + import multiprocessing + CPU_COUNT = multiprocessing.cpu_count() +except ImportError: + CPU_COUNT = 2 class GuiLockError(Exception): def __init__(self, msg): From 625291f361aeafab7b1b9c0f7c31f5f4e11f8377 Mon Sep 17 00:00:00 2001 From: sccolbert Date: Sun, 8 Nov 2009 18:35:07 +0100 Subject: [PATCH 40/43] added division decorators to cython. Improved how data gets chunked up. --- scikits/image/io/_plugins/_colormixer.pyx | 6 ++++-- scikits/image/io/_plugins/util.py | 24 +++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/scikits/image/io/_plugins/_colormixer.pyx b/scikits/image/io/_plugins/_colormixer.pyx index 48450473..25767f66 100644 --- a/scikits/image/io/_plugins/_colormixer.pyx +++ b/scikits/image/io/_plugins/_colormixer.pyx @@ -185,6 +185,8 @@ def gamma(np.ndarray[np.uint8_t, ndim=3] img, cdef int i, j + if gamma == 0: + gamma = 0.00000000000000000001 gamma = 1./gamma with nogil: @@ -199,7 +201,7 @@ def gamma(np.ndarray[np.uint8_t, ndim=3] img, img[i,j,2] = (pow(b, gamma) * 255) - +@cython.cdivision(True) cdef void rgb_2_hsv(float* RGB, float* HSV) nogil: cdef float R, G, B, H, S, V, MAX, MIN R = RGB[0] @@ -261,7 +263,7 @@ cdef void rgb_2_hsv(float* RGB, float* HSV) nogil: HSV[1] = S HSV[2] = V - +@cython.cdivision(True) cdef void hsv_2_rgb(float* HSV, float* RGB) nogil: cdef float H, S, V cdef float f, p, q, t, r, g, b diff --git a/scikits/image/io/_plugins/util.py b/scikits/image/io/_plugins/util.py index 40f6e92b..a9936bdc 100644 --- a/scikits/image/io/_plugins/util.py +++ b/scikits/image/io/_plugins/util.py @@ -202,21 +202,21 @@ class ThreadDispatch(object): self.chunks.append((img, stateimg)) elif self.cores >= 4: - self.chunks.append((img[:(height/2), :(width/2), :], - stateimg[:(height/2), :(width/2), :])) - self.chunks.append((img[:(height/2), (width/2):, :], - stateimg[:(height/2), (width/2):, :])) - self.chunks.append((img[(height/2):, :(width/2), :], - stateimg[(height/2):, :(width/2), :])) - self.chunks.append((img[(height/2):, (width/2):, :], - stateimg[(height/2):, (width/2):, :])) + self.chunks.append((img[:(height/4), :, :], + stateimg[:(height/4), :, :])) + self.chunks.append((img[(height/4):(height/2), :, :], + stateimg[(height/4):(height/2), :, :])) + self.chunks.append((img[(height/2):(3*height/4), :, :], + stateimg[(height/2):(3*height/4), :, :])) + self.chunks.append((img[(3*height/4):, :, :], + stateimg[(3*height/4):, :, :])) # if they dont have 1, or 4 or more, 2 is good. else: - self.chunks.append((img[:, :(width/2), :], - stateimg[:, :(width/2), :])) - self.chunks.append((img[:, (width/2):, :], - stateimg[:, (width/2):, :])) + self.chunks.append((img[:(height/2), :, :], + stateimg[:(height/2), :, :])) + self.chunks.append((img[(height/2):, :, :], + stateimg[(height/2):, :, :])) for i in range(self.cores): self.threads.append(ImgThread(func, self.chunks[i][0], From c539a02b2000c0b1fef24833eba8ebb1c40067f3 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sun, 8 Nov 2009 22:02:15 +0200 Subject: [PATCH 41/43] io: Fix one more instance of cdivision. --- scikits/image/io/_plugins/_colormixer.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/scikits/image/io/_plugins/_colormixer.pyx b/scikits/image/io/_plugins/_colormixer.pyx index 25767f66..2aa2161b 100644 --- a/scikits/image/io/_plugins/_colormixer.pyx +++ b/scikits/image/io/_plugins/_colormixer.pyx @@ -139,6 +139,7 @@ def brightness(np.ndarray[np.uint8_t, ndim=3] img, @cython.boundscheck(False) +@cython.cdivision(True) def sigmoid_gamma(np.ndarray[np.uint8_t, ndim=3] img, np.ndarray[np.uint8_t, ndim=3] stateimg, float alpha, float beta): From d9f624959f0c8c2e9e877296f7e94db1f11fc3a3 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sun, 8 Nov 2009 22:08:42 +0200 Subject: [PATCH 42/43] io: Throw exception when qt plugin can't be loaded. --- scikits/image/io/_plugins/qt_plugin.py | 199 +++++++++++++------------ 1 file changed, 101 insertions(+), 98 deletions(-) diff --git a/scikits/image/io/_plugins/qt_plugin.py b/scikits/image/io/_plugins/qt_plugin.py index a667439d..b58e2c38 100644 --- a/scikits/image/io/_plugins/qt_plugin.py +++ b/scikits/image/io/_plugins/qt_plugin.py @@ -1,113 +1,116 @@ from util import prepare_for_display, window_manager, GuiLockError -from textwrap import dedent import numpy as np import sys +# We try to aquire the gui lock first or else the gui import might +# trample another GUI's PyOS_InputHook. +window_manager.acquire('qt') + try: - # We try to aquire the gui lock first or else the gui import might - # trample another GUI's PyOS_InputHook. - window_manager.acquire('qt') + from PyQt4.QtGui import (QApplication, QMainWindow, QImage, QPixmap, + QLabel, QWidget) + from PyQt4 import QtCore, QtGui -except GuiLockError, gle: - print gle +except ImportError: + window_manager._release('qt') -else: - try: - from PyQt4.QtGui import (QApplication, QMainWindow, QImage, QPixmap, - QLabel, QWidget) - from PyQt4 import QtCore, QtGui + raise ImportError("""\ + PyQt4 libraries not installed. Please refer to - except ImportError: - print 'PyQT4 libraries not installed. Plugin not loaded.' - window_manager._release('qt') + http://www.riverbankcomputing.co.uk/software/pyqt/intro + for more information. PyQt4 is GPL licensed. For an + LGPL equivalent, see + + http://www.pyside.org + """) + +app = None + +class ImageLabel(QLabel): + def __init__(self, parent, arr): + QLabel.__init__(self) + + # we need to hold a reference to + # arr because QImage doesn't copy the data + # and the buffer must be alive as long + # as the image is alive. + self.arr = arr + + # we also need to pass in the row-stride to + # the constructor, because we can't guarantee + # that every row of the numpy data is + # 4-byte aligned. Which Qt would require + # if we didnt pass the stride. + self.img = QImage(arr.data, arr.shape[1], arr.shape[0], + arr.strides[0], QImage.Format_RGB888) + self.pm = QPixmap.fromImage(self.img) + self.setPixmap(self.pm) + self.setAlignment(QtCore.Qt.AlignTop) + self.setMinimumSize(100, 100) + + def resizeEvent(self, evt): + width = self.width() + pm = QPixmap.fromImage(self.img) + self.pm = pm.scaledToWidth(width) + self.setPixmap(self.pm) + + +class ImageWindow(QMainWindow): + def __init__(self, arr, mgr): + QMainWindow.__init__(self) + self.setWindowTitle('scikits.image') + self.mgr = mgr + self.main_widget = QWidget() + self.layout = QtGui.QGridLayout(self.main_widget) + self.setCentralWidget(self.main_widget) + + self.label = ImageLabel(self, arr) + self.layout.addWidget(self.label, 0, 0) + self.layout.addLayout + self.mgr.add_window(self) + self.main_widget.show() + + def closeEvent(self, event): + # Allow window to be destroyed by removing any + # references to it + self.mgr.remove_window(self) + + +def imshow(arr, fancy=False): + global app + if not app: + app = QApplication([]) + + arr = prepare_for_display(arr) + + if not fancy: + iw = ImageWindow(arr, window_manager) else: + from scivi import SciviImageWindow + iw = SciviImageWindow(arr, window_manager) - app = None - - class ImageLabel(QLabel): - def __init__(self, parent, arr): - QLabel.__init__(self) - - # we need to hold a reference to - # arr because QImage doesn't copy the data - # and the buffer must be alive as long - # as the image is alive. - self.arr = arr - - # we also need to pass in the row-stride to - # the constructor, because we can't guarantee - # that every row of the numpy data is - # 4-byte aligned. Which Qt would require - # if we didnt pass the stride. - self.img = QImage(arr.data, arr.shape[1], arr.shape[0], - arr.strides[0], QImage.Format_RGB888) - self.pm = QPixmap.fromImage(self.img) - self.setPixmap(self.pm) - self.setAlignment(QtCore.Qt.AlignTop) - self.setMinimumSize(100, 100) - - def resizeEvent(self, evt): - width = self.width() - pm = QPixmap.fromImage(self.img) - self.pm = pm.scaledToWidth(width) - self.setPixmap(self.pm) + iw.show() - class ImageWindow(QMainWindow): - def __init__(self, arr, mgr): - QMainWindow.__init__(self) - self.setWindowTitle('scikits.image') - self.mgr = mgr - self.main_widget = QWidget() - self.layout = QtGui.QGridLayout(self.main_widget) - self.setCentralWidget(self.main_widget) - - self.label = ImageLabel(self, arr) - self.layout.addWidget(self.label, 0, 0) - self.layout.addLayout - self.mgr.add_window(self) - self.main_widget.show() - - def closeEvent(self, event): - # Allow window to be destroyed by removing any - # references to it - self.mgr.remove_window(self) +def _app_show(): + global app + if app and window_manager.has_windows(): + app.exec_() + else: + print 'No images to show. See `imshow`.' - def imshow(arr, fancy=False): - global app - if not app: - app = QApplication([]) - - arr = prepare_for_display(arr) - - if not fancy: - iw = ImageWindow(arr, window_manager) - else: - from scivi import SciviImageWindow - iw = SciviImageWindow(arr, window_manager) - - iw.show() - - - def _app_show(): - global app - if app and window_manager.has_windows(): - app.exec_() - else: - print 'No images to show. See `imshow`.' - - - def imsave(filename, img): - # we can support for other than 3D uint8 here... - img = prepare_for_display(img) - qimg = QImage(img.data, img.shape[1], img.shape[0], - img.strides[0], QImage.Format_RGB888) - saved = qimg.save(filename) - if not saved: - msg = dedent( - '''The image was not saved. Allowable file formats - for the QT imsave plugin are: - BMP, JPG, JPEG, PNG, PPM, TIFF, XBM, XPM''') - raise RuntimeError(msg) +def imsave(filename, img): + # we can add support for other than 3D uint8 here... + img = prepare_for_display(img) + qimg = QImage(img.data, img.shape[1], img.shape[0], + img.strides[0], QImage.Format_RGB888) + saved = qimg.save(filename) + if not saved: + from textwrap import dedent + msg = dedent( + '''The image was not saved. Allowable file formats + for the QT imsave plugin are: + BMP, JPG, JPEG, PNG, PPM, TIFF, XBM, XPM''') + raise RuntimeError(msg) From d8709bd0c0a0f332dbee9284d4a4ae0183c9bc62 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sun, 8 Nov 2009 23:49:51 +0200 Subject: [PATCH 43/43] io: Add imsave using PIL. --- scikits/image/io/_plugins/pil_plugin.ini | 2 +- scikits/image/io/_plugins/pil_plugin.py | 116 ++++++++++++------ .../io/tests/{test_imread.py => test_pil.py} | 31 ++++- 3 files changed, 109 insertions(+), 40 deletions(-) rename scikits/image/io/tests/{test_imread.py => test_pil.py} (50%) diff --git a/scikits/image/io/_plugins/pil_plugin.ini b/scikits/image/io/_plugins/pil_plugin.ini index be54e541..7afa244f 100644 --- a/scikits/image/io/_plugins/pil_plugin.ini +++ b/scikits/image/io/_plugins/pil_plugin.ini @@ -1,4 +1,4 @@ [pil] description = Image reading via the Python Imaging Library -provides = imread +provides = imread, imsave diff --git a/scikits/image/io/_plugins/pil_plugin.py b/scikits/image/io/_plugins/pil_plugin.py index e50cbe6c..2aa3e9d4 100644 --- a/scikits/image/io/_plugins/pil_plugin.py +++ b/scikits/image/io/_plugins/pil_plugin.py @@ -6,44 +6,90 @@ import numpy as np try: from PIL import Image except ImportError: - print 'Could not load Python Imaging Library' -else: - def imread(fname, as_grey=False, dtype=None): - """Load an image from file. + raise ImportError("The Python Image Library could not be found. " + "Please refer to http://pypi.python.org/pypi/PIL/ " + "for further instructions.") - """ - im = Image.open(fname) - if im.mode == 'P': - if palette_is_grayscale(im): - im = im.convert('L') - else: - im = im.convert('RGB') +def imread(fname, as_grey=False, dtype=None): + """Load an image from file. - if as_grey and not \ - im.mode in ('1', 'L', 'I', 'F', 'I;16', 'I;16L', 'I;16B'): - im = im.convert('F') + """ + im = Image.open(fname) + if im.mode == 'P': + if _palette_is_grayscale(im): + im = im.convert('L') + else: + im = im.convert('RGB') - return np.array(im, dtype=dtype) + if as_grey and not \ + im.mode in ('1', 'L', 'I', 'F', 'I;16', 'I;16L', 'I;16B'): + im = im.convert('F') - def palette_is_grayscale(pil_image): - """Return True if PIL image in palette mode is grayscale. + return np.array(im, dtype=dtype) - Parameters - ---------- - pil_image : PIL image - PIL Image that is in Palette mode. +def _palette_is_grayscale(pil_image): + """Return True if PIL image in palette mode is grayscale. - Returns - ------- - is_grayscale : bool - True if all colors in image palette are gray. - """ - assert pil_image.mode == 'P' - # get palette as an array with R, G, B columns - palette = np.asarray(pil_image.getpalette()).reshape((256, 3)) - # Not all palette colors are used; unused colors have junk values. - start, stop = pil_image.getextrema() - valid_palette = palette[start:stop] - # Image is grayscale if channel differences (R - G and G - B) - # are all zero. - return np.allclose(np.diff(valid_palette), 0) + Parameters + ---------- + pil_image : PIL image + PIL Image that is in Palette mode. + + Returns + ------- + is_grayscale : bool + True if all colors in image palette are gray. + """ + assert pil_image.mode == 'P' + # get palette as an array with R, G, B columns + palette = np.asarray(pil_image.getpalette()).reshape((256, 3)) + # Not all palette colors are used; unused colors have junk values. + start, stop = pil_image.getextrema() + valid_palette = palette[start:stop] + # Image is grayscale if channel differences (R - G and G - B) + # are all zero. + return np.allclose(np.diff(valid_palette), 0) + +def imsave(fname, arr): + """Save an image to disk. + + Parameters + ---------- + fname : str + Name of destination file. + arr : ndarray of uint8 or float + Array (image) to save. Arrays of data-type uint8 should have + values in [0, 255], whereas floating-point arrays must be + in [0, 1]. + + Notes + ----- + Currently, only 8-bit precision is supported. + + """ + arr = np.asarray(arr).squeeze() + + if arr.ndim not in (2, 3): + raise ValueError("Invalid shape for image array: %s" % arr.shape) + + if arr.ndim == 3: + if arr.shape[2] not in (3, 4): + raise ValueError("Invalid number of channels in image array.") + + # Image is floating point, assume in [0, 1] + if np.issubdtype(arr.dtype, float): + arr = arr * 255 + + arr = arr.astype(np.uint8) + + if arr.ndim == 2: + mode = 'L' + + elif arr.shape[2] in (3, 4): + mode = {3: 'RGB', 4: 'RGBA'}[arr.shape[2]] + + # Force all integers to bytes + arr = arr.astype(np.uint8) + + img = Image.fromstring(mode, (arr.shape[1], arr.shape[0]), arr.tostring()) + img.save(fname) diff --git a/scikits/image/io/tests/test_imread.py b/scikits/image/io/tests/test_pil.py similarity index 50% rename from scikits/image/io/tests/test_imread.py rename to scikits/image/io/tests/test_pil.py index fc77e0c7..0dbb877f 100644 --- a/scikits/image/io/tests/test_imread.py +++ b/scikits/image/io/tests/test_pil.py @@ -1,9 +1,12 @@ import os.path import numpy as np +from numpy.testing import * + +from tempfile import NamedTemporaryFile from scikits.image import data_dir -from scikits.image.io import imread -from scikits.image.io._plugins.pil_plugin import palette_is_grayscale +from scikits.image.io import imread, imsave +from scikits.image.io._plugins.pil_plugin import _palette_is_grayscale def test_imread_flatten(): # a color image is flattened and returned as float32 @@ -26,6 +29,26 @@ def test_imread_palette(): def test_palette_is_gray(): from PIL import Image gray = Image.open(os.path.join(data_dir, 'palette_gray.png')) - assert palette_is_grayscale(gray) + assert _palette_is_grayscale(gray) color = Image.open(os.path.join(data_dir, 'palette_color.png')) - assert not palette_is_grayscale(color) + assert not _palette_is_grayscale(color) + +class TestSave: + def roundtrip(self, dtype, x, scaling=1): + f = NamedTemporaryFile(suffix='.png') + imsave(f.name, x) + f.seek(0) + y = imread(f.name) + + assert_array_almost_equal((x * scaling).astype(np.int32), y) + + def test_imsave_roundtrip(self): + for shape in [(10, 10), (10, 10, 3), (10, 10, 4)]: + for dtype in (np.uint8, np.uint16, np.float32, np.float64): + x = np.ones(shape, dtype=dtype) * np.random.random(shape) + + if np.issubdtype(dtype, float): + yield self.roundtrip, dtype, x, 255 + else: + x = (x * 255).astype(dtype) + yield self.roundtrip, dtype, x