Repository: scikit-image/scikit-image

Issue:
seam carving vertically then horizontally
## Description

I am attempting to scale an image using seam carving, but I receive the following error:

> *** Error in `python': free(): invalid next size (normal): 0x00000000040b7f80 ***
> ======= Backtrace: =========
> /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fed969147e5]
> /lib/x86_64-linux-gnu/libc.so.6(+0x7fe0a)[0x7fed9691ce0a]
> /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fed9692098c]
> /home/jesse/programs/anaconda/lib/python2.7/site-packages/numpy/core/multiarray.so(+0x1cfe7)[0x7fed9269bfe7]
> /home/jesse/programs/anaconda/lib/python2.7/site-packages/numpy/core/multiarray.so(+0x1fa5e)[0x7fed9269ea5e]
> /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/transform/_seam_carving.so(+0x5cff)[0x7fed650f3cff]
> /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/transform/_seam_carving.so(+0x1c78f)[0x7fed6510a78f]
> /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/transform/_seam_carving.so(+0x1f47c)[0x7fed6510d47c]
> /home/jesse/programs/anaconda/bin/../lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x7b35)[0x7fed976901e5]
> /home/jesse/programs/anaconda/bin/../lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x89e)[0x7fed97691c3e]
> /home/jesse/programs/anaconda/bin/../lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x8b47)[0x7fed976911f7]
> /home/jesse/programs/anaconda/bin/../lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x8c95)[0x7fed97691345]
> /home/jesse/programs/anaconda/bin/../lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x89e)[0x7fed97691c3e]
> /home/jesse/programs/anaconda/bin/../lib/libpython2.7.so.1.0(PyEval_EvalCode+0x32)[0x7fed97691d52]
> /home/jesse/programs/anaconda/bin/../lib/libpython2.7.so.1.0(PyRun_FileExFlags+0xb0)[0x7fed976b2450]
> /home/jesse/programs/anaconda/bin/../lib/libpython2.7.so.1.0(PyRun_SimpleFileExFlags+0xef)[0x7fed976b262f]
> /home/jesse/programs/anaconda/bin/../lib/libpython2.7.so.1.0(Py_Main+0xca4)[0x7fed976c7fd4]
> /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fed968bd830]
> python[0x400729]
> ======= Memory map: ========
> 00400000-00401000 r-xp 00000000 08:02 18481226                           /home/jesse/programs/anaconda/bin/python2.7
> 00600000-00601000 rw-p 00000000 08:02 18481226                           /home/jesse/programs/anaconda/bin/python2.7
> 014cc000-059ea000 rw-p 00000000 00:00 0                                  [heap]
> 7fed50000000-7fed50021000 rw-p 00000000 00:00 0 
> 7fed50021000-7fed54000000 ---p 00000000 00:00 0 
> 7fed54000000-7fed54021000 rw-p 00000000 00:00 0 
> 7fed54021000-7fed58000000 ---p 00000000 00:00 0 
> 7fed58000000-7fed58021000 rw-p 00000000 00:00 0 
> 7fed58021000-7fed5c000000 ---p 00000000 00:00 0 
> 7fed5cf57000-7fed5d0af000 rw-s 00000000 00:05 29130804                   /SYSV00000000 (deleted)
> 7fed5d0af000-7fed5d16f000 rw-p 00000000 00:00 0 
> 7fed5d16f000-7fed5d2c7000 rw-s 00000000 00:05 29098035                   /SYSV00000000 (deleted)
> 7fed5d2c7000-7fed5d3c7000 rw-p 00000000 00:00 0 
> 7fed5d3c7000-7fed5d3c8000 ---p 00000000 00:00 0 
> 7fed5d3c8000-7fed5dbc8000 rw-p 00000000 00:00 0 
> 7fed5dbc8000-7fed5dc81000 r--p 00000000 08:01 262386                     /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf
> 7fed5dc81000-7fed5dcc1000 r--s 00000000 08:02 19661412                   /home/jesse/programs/anaconda/var/cache/fontconfig/0bd3dc0958fa2205aaaa8ebb13e2872b-le64.cache-7
> 7fed5dcc1000-7fed5dd01000 rw-p 00000000 00:00 0 
> 7fed5dd01000-7fed5dd63000 r-xp 00000000 08:02 30415945                   /home/jesse/programs/anaconda/plugins/imageformats/libqwebp.so
> 7fed5dd63000-7fed5df62000 ---p 00062000 08:02 30415945                   /home/jesse/programs/anaconda/plugins/imageformats/libqwebp.so
> 7fed5df62000-7fed5df64000 rw-p 00061000 08:02 30415945                   /home/jesse/programs/anaconda/plugins/imageformats/libqwebp.so
> 7fed5df64000-7fed5df66000 rw-p 00000000 00:00 0 
> 7fed5df66000-7fed5df6b000 r-xp 00000000 08:02 30415543                   /home/jesse/programs/anaconda/plugins/imageformats/libqwbmp.so
> 7fed5df6b000-7fed5e16a000 ---p 00005000 08:02 30415543                   /home/jesse/programs/anaconda/plugins/imageformats/libqwbmp.so
> 7fed5e16a000-7fed5e16b000 rw-p 00004000 08:02 30415543                   /home/jesse/programs/anaconda/plugins/imageformats/libqwbmp.so
> 7fed5e16b000-7fed5e1d4000 r-xp 00000000 08:02 30415950                   /home/jesse/programs/anaconda/plugins/imageformats/libqtiff.so
> 7fed5e1d4000-7fed5e3d4000 ---p 00069000 08:02 30415950                   /home/jesse/programs/anaconda/plugins/imageformats/libqtiff.so
> 7fed5e3d4000-7fed5e3d8000 rw-p 00069000 08:02 30415950                   /home/jesse/programs/anaconda/plugins/imageformats/libqtiff.so
> 7fed5e3d8000-7fed5e3dd000 r-xp 00000000 08:02 30415559                   /home/jesse/programs/anaconda/plugins/imageformats/libqtga.so
> 7fed5e3dd000-7fed5e5dc000 ---p 00005000 08:02 30415559                   /home/jesse/programs/anaconda/plugins/imageformats/libqtga.so
> 7fed5e5dc000-7fed5e5dd000 rw-p 00004000 08:02 30415559                   /home/jesse/programs/anaconda/plugins/imageformats/libqtga.so
> 7fed5e5dd000-7fed5e632000 r-xp 00000000 08:02 30415944                   /home/jesse/programs/anaconda/lib/libQt5Svg.so.5.6.2
> 7fed5e632000-7fed5e831000 ---p 00055000 08:02 30415944                   /home/jesse/programs/anaconda/lib/libQt5Svg.so.5.6.2
> 7fed5e831000-7fed5e835000 rw-p 00054000 08:02 30415944                   /home/jesse/programs/anaconda/lib/libQt5Svg.so.5.6.2
> 7fed5e835000-7fed5e83f000 rw-p 00059000 08:02 30415944                   /home/jesse/programs/anaconda/lib/libQt5Svg.so.5.6.2
> 7fed5e83f000-7fed5e844000 r-xp 00000000 08:02 30415590                   /home/jesse/programs/anaconda/plugins/imageformats/libqsvg.so
> 7fed5e844000-7fed5ea44000 ---p 00005000 08:02 30415590                   /home/jesse/programs/anaconda/plugins/imageformats/libqsvg.so
> 7fed5ea44000-7fed5ea45000 rw-p 00005000 08:02 30415590                   /home/jesse/programs/anaconda/plugins/imageformats/libqsvg.so
> 7fed5ea45000-7fed5ea51000 r-xp 00000000 08:02 30415719                   /home/jesse/programs/anaconda/plugins/imageformats/libqjpeg.so
> 7fed5ea51000-7fed5ec50000 ---p 0000c000 08:02 30415719                   /home/jesse/programs/anaconda/plugins/imageformats/libqjpeg.so
> 7fed5ec50000-7fed5ec51000 rw-p 0000b000 08:02 30415719                   /home/jesse/programs/anaconda/plugins/imageformats/libqjpeg.so
> 7fed5ec51000-7fed5ec58000 r-xp 00000000 08:02 30415629                   /home/jesse/programs/anaconda/plugins/imageformats/libqico.so
> 7fed5ec58000-7fed5ee57000 ---p 00007000 08:02 30415629                   /home/jesse/programs/anaconda/plugins/imageformats/libqico.so
> 7fed5ee57000-7fed5ee58000 rw-p 00006000 08:02 30415629                   /home/jesse/programs/anaconda/plugins/imageformats/libqico.so
> 7fed5ee58000-7fed5ee61000 r-xp 00000000 08:02 30415692                   /home/jesse/programs/anaconda/plugins/imageformats/libqicns.so
> 7fed5ee61000-7fed5f061000 ---p 00009000 08:02 30415692                   /home/jesse/programs/anaconda/plugins/imageformats/libqicns.so
> 7fed5f061000-7fed5f062000 rw-p 00009000 08:02 30415692                   /home/jesse/programs/anaconda/plugins/imageformats/libqicns.so
> 7fed5f062000-7fed5f068000 r-xp 00000000 08:02 30415618                   /home/jesse/programs/anaconda/plugins/imageformats/libqgif.so
> 7fed5f068000-7fed5f268000 ---p 00006000 08:02 30415618                   /home/jesse/programs/anaconda/plugins/imageformats/libqgif.so
> 7fed5f268000-7fed5f269000 rw-p 00006000 08:02 30415618                   /home/jesse/programs/anaconda/plugins/imageformats/libqgif.so
> 7fed5f269000-7fed5f274000 r-xp 00000000 08:02 30415721                   /home/jesse/programs/anaconda/plugins/imageformats/libqdds.so
> 7fed5f274000-7fed5f474000 ---p 0000b000 08:02 30415721                   /home/jesse/programs/anaconda/plugins/imageformats/libqdds.so
> 7fed5f474000-7fed5f475000 rw-p 0000b000 08:02 30415721                   /home/jesse/programs/anaconda/plugins/imageformats/libqdds.so
> 7fed5f475000-7fed5f4ba000 r-xp 00000000 08:02 20054640                   /home/jesse/programs/anaconda/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so
> 7fed5f4ba000-7fed5f6b9000 ---p 00045000 08:02 20054640                   /home/jesse/programs/anaconda/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so
> 7fed5f6b9000-7fed5f6bb000 rw-p 00044000 08:02 20054640                   /home/jesse/programs/anaconda/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so
> 7fed5f6bb000-7fed5f6bc000 ---p 00000000 00:00 0 
> 7fed5f6bc000-7fed5febc000 rw-p 00000000 00:00 0 
> 7fed5febc000-7fed5ffaa000 r-xp 00000000 08:02 18489381                   /home/jesse/programs/anaconda/lib/libiconv.so.2.5.1
> 7fed5ffaa000-7fed601a9000 ---p 000ee000 08:02 18489381                   /home/jesse/programs/anaconda/lib/libiconv.so.2.5.1
> 7fed601a9000-7fed601ab000 rw-p 000ed000 08:02 18489381                   /home/jesse/programs/anaconda/lib/libiconv.so.2.5.1
> 7fed601ab000-7fed602fc000 r-xp 00000000 08:02 18489505                   /home/jesse/programs/anaconda/lib/libxml2.so.2.9.4
> 7fed602fc000-7fed604fb000 ---p 00151000 08:02 18489505                   /home/jesse/programs/anaconda/lib/libxml2.so.2.9.4
> 7fed604fb000-7fed60505000 rw-p 00150000 08:02 18489505                   /home/jesse/programs/anaconda/lib/libxml2.so.2.9.4
> 7fed60505000-7fed60506000 rw-p 00000000 00:00 0 
> 7fed60506000-7fed6058a000 r-xp 00000000 08:02 30415960                   /home/jesse/programs/anaconda/lib/libQt5DBus.so.5.6.2
> 7fed6058a000-7fed6078a000 ---p 00084000 08:02 30415960                   /home/jesse/programs/anaconda/lib/libQt5DBus.so.5.6.2
> 7fed6078a000-7fed6078d000 rw-p 00084000 08:02 30415960                   /home/jesse/programs/anaconda/lib/libQt5DBus.so.5.6.2
> 7fed6078d000-7fed60795000 rw-p 00088000 08:02 30415960                   /home/jesse/programs/anaconda/lib/libQt5DBus.so.5.6.2
> 7fed60795000-7fed607d2000 r-xp 00000000 08:02 18481338                   /home/jesse/programs/anaconda/lib/libfontconfig.so.1.9.2
> 7fed607d2000-7fed609d2000 ---p 0003d000 08:02 18481338                   /home/jesse/programs/anaconda/lib/libfontconfig.so.1.9.2
> 7fed609d2000-7fed609d8000 rw-p 0003d000 08:02 18481338                   /home/jesse/programs/anaconda/lib/libfontconfig.so.1.9.2
> 7fed609d8000-7fed60a20000 r-xp 00000000 08:02 18481312                   /home/jesse/programs/anaconda/lib/libdbus-1.so.3.14.7
> 7fed60a20000-7fed60c20000 ---p 00048000 08:02 18481312                   /home/jesse/programs/anaconda/lib/libdbus-1.so.3.14.7
> 7fed60c20000-7fed60c22000 rw-p 00048000 08:02 18481312                   /home/jesse/programs/anaconda/lib/libdbus-1.so.3.14.7
> 7fed60fbf000-7fed61117000 rw-s 00000000 00:05 29196342                   /SYSV00000000 (deleted)
> 7fed61117000-7fed611d7000 rw-p 00000000 00:00 0 
> 7fed611d7000-7fed6132f000 rw-s 00000000 00:05 29163573                   /SYSV00000000 (deleted)
> 7fed6132f000-7fed613ef000 rw-p 00000000 00:00 0 
> 7fed613ef000-7fed613f8000 r-xp 00000000 08:01 2888388                    /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.0
> 7fed613f8000-7fed615f7000 ---p 00009000 08:01 2888388                    /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.0
> 7fed615f7000-7fed615f8000 r--p 00008000 08:01 2888388                    /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.0
> 7fed615f8000-7fed615f9000 rw-p 00009000 08:01 2888388                    /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.0
> 7fed615f9000-7fed61736000 r-xp 00000000 08:02 18490128                   /home/jesse/programs/anaconda/lib/libQt5XcbQpa.so.5.6.2
> 7fed61736000-7fed61936000 ---p 0013d000 08:02 18490128                   /home/jesse/programs/anaconda/lib/libQt5XcbQpa.so.5.6.2
> 7fed61936000-7fed61941000 rw-p 0013d000 08:02 18490128                   /home/jesse/programs/anaconda/lib/libQt5XcbQpa.so.5.6.2
> 7fed61941000-7fed61951000 rw-p 00149000 08:02 18490128                   /home/jesse/programs/anaconda/lib/libQt5XcbQpa.so.5.6.2
> 7fed61951000-7fed61953000 r-xp 00000000 08:02 30415290                   /home/jesse/programs/anaconda/plugins/platforms/libqxcb.so
> 7fed61953000-7fed61b53000 ---p 00002000 08:02 30415290                   /home/jesse/programs/anaconda/plugins/platforms/libqxcb.so
> 7fed61b53000-7fed61b54000 rw-p 00002000 08:02 30415290                   /home/jesse/programs/anaconda/plugins/platforms/libqxcb.so
> 7fed61b54000-7fed61b98000 r-xp 00000000 08:02 19273732                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/filters/rank/bilateral_cy.so
> 7fed61b98000-7fed61d98000 ---p 00044000 08:02 19273732                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/filters/rank/bilateral_cy.so
> 7fed61d98000-7fed61d9d000 rw-p 00044000 08:02 19273732                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/filters/rank/bilateral_cy.so
> 7fed61d9d000-7fed61e2b000 r-xp 00000000 08:02 19273737                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/filters/rank/percentile_cy.so
> 7fed61e2b000-7fed6202b000 ---p 0008e000 08:02 19273737                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/filters/rank/percentile_cy.so
> 7fed6202b000-7fed62031000 rw-p 0008e000 08:02 19273737                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/filters/rank/percentile_cy.so
> 7fed62031000-7fed62085000 r-xp 00000000 08:02 19273733                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/filters/rank/core_cy.so
> 7fed62085000-7fed62285000 ---p 00054000 08:02 19273733                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/filters/rank/core_cy.so
> 7fed62285000-7fed62288000 rw-p 00054000 08:02 19273733                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/filters/rank/core_cy.so
> 7fed62288000-7fed6238e000 r-xp 00000000 08:02 19273736                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/filters/rank/generic_cy.so
> 7fed6238e000-7fed6258e000 ---p 00106000 08:02 19273736                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/filters/rank/generic_cy.so
> 7fed6258e000-7fed62595000 rw-p 00106000 08:02 19273736                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/filters/rank/generic_cy.so
> 7fed62595000-7fed625d6000 rw-p 00000000 00:00 0 
> 7fed625d6000-7fed6260b000 r-xp 00000000 08:02 19274038                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/restoration/_nl_means_denoising.so
> 7fed6260b000-7fed6280b000 ---p 00035000 08:02 19274038                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/restoration/_nl_means_denoising.so
> 7fed6280b000-7fed62810000 rw-p 00035000 08:02 19274038                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/restoration/_nl_means_denoising.so
> 7fed62810000-7fed62840000 r-xp 00000000 08:02 19274037                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/restoration/_denoise_cy.so
> 7fed62840000-7fed62a3f000 ---p 00030000 08:02 19274037                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/restoration/_denoise_cy.so
> 7fed62a3f000-7fed62a44000 rw-p 0002f000 08:02 19274037                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/restoration/_denoise_cy.so
> 7fed62a44000-7fed62a68000 r-xp 00000000 08:02 19274041                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/restoration/_unwrap_3d.so
> 7fed62a68000-7fed62c68000 ---p 00024000 08:02 19274041                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/restoration/_unwrap_3d.so
> 7fed62c68000-7fed62c6b000 rw-p 00024000 08:02 19274041                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/restoration/_unwrap_3d.so
> 7fed62c6b000-7fed62c8b000 r-xp 00000000 08:02 19274040                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/restoration/_unwrap_2d.so
> 7fed62c8b000-7fed62e8b000 ---p 00020000 08:02 19274040                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/restoration/_unwrap_2d.so
> 7fed62e8b000-7fed62e8e000 rw-p 00020000 08:02 19274040                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/restoration/_unwrap_2d.so
> 7fed62e8e000-7fed62eab000 r-xp 00000000 08:02 19274039                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/restoration/_unwrap_1d.so
> 7fed62eab000-7fed630ab000 ---p 0001d000 08:02 19274039                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/restoration/_unwrap_1d.so
> 7fed630ab000-7fed630ae000 rw-p 0001d000 08:02 19274039                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/restoration/_unwrap_1d.so
> 7fed630ae000-7fed650ae000 rw-p 00000000 00:00 0 
> 7fed650ae000-7fed650ee000 rw-p 00000000 00:00 0 
> 7fed650ee000-7fed65114000 r-xp 00000000 08:02 19274124                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/transform/_seam_carving.so
> 7fed65114000-7fed65314000 ---p 00026000 08:02 19274124                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/transform/_seam_carving.so
> 7fed65314000-7fed65318000 rw-p 00026000 08:02 19274124                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/transform/_seam_carving.so
> 7fed65318000-7fed6533c000 r-xp 00000000 08:02 19274123                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/transform/_radon_transform.so
> 7fed6533c000-7fed6553b000 ---p 00024000 08:02 19274123                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/transform/_radon_transform.so
> 7fed6553b000-7fed6553f000 rw-p 00023000 08:02 19274123                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/transform/_radon_transform.so
> 7fed6553f000-7fed65564000 r-xp 00000000 08:02 19274127                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/transform/_warps_cy.so
> 7fed65564000-7fed65763000 ---p 00025000 08:02 19274127                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/transform/_warps_cy.so
> 7fed65763000-7fed65767000 rw-p 00024000 08:02 19274127                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/transform/_warps_cy.so
> 7fed65767000-7fed657a9000 r-xp 00000000 08:02 19273593                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/draw/_draw.so
> 7fed657a9000-7fed659a8000 ---p 00042000 08:02 19273593                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/draw/_draw.so
> 7fed659a8000-7fed659b3000 rw-p 00041000 08:02 19273593                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/draw/_draw.so
> 7fed659b3000-7fed659e8000 r-xp 00000000 08:02 19274122                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/transform/_hough_transform.so
> 7fed659e8000-7fed65be8000 ---p 00035000 08:02 19274122                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/transform/_hough_transform.so
> 7fed65be8000-7fed65bee000 rw-p 00035000 08:02 19274122                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/transform/_hough_transform.so
> 7fed65bee000-7fed65bef000 rw-p 00000000 00:00 0 
> 7fed65bef000-7fed65c15000 r-xp 00000000 08:02 19273929                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/measure/_pnpoly.so
> 7fed65c15000-7fed65e15000 ---p 00026000 08:02 19273929                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/measure/_pnpoly.so
> 7fed65e15000-7fed65e18000 rw-p 00026000 08:02 19273929                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/skimage/measure/_pnpoly.so
> 7fed65e18000-7fed65e59000 rw-p 00000000 00:00 0 
> 7fed65e59000-7fed65e6a000 r-xp 00000000 08:02 30543926                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/stats/mvn.so
> 7fed65e6a000-7fed66069000 ---p 00011000 08:02 30543926                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/stats/mvn.so
> 7fed66069000-7fed6606b000 rw-p 00010000 08:02 30543926                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/stats/mvn.so
> 7fed6606b000-7fed66162000 rw-p 00000000 00:00 0 
> 7fed66162000-7fed6616d000 r-xp 00000000 08:02 30543929                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/stats/statlib.so
> 7fed6616d000-7fed6636c000 ---p 0000b000 08:02 30543929                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/stats/statlib.so
> 7fed6636c000-7fed6636e000 rw-p 0000a000 08:02 30543929                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/stats/statlib.so
> 7fed6636e000-7fed664ae000 rw-p 00000000 00:00 0 
> 7fed664ae000-7fed664d6000 r-xp 00000000 08:02 30543907                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/stats/_stats.so
> 7fed664d6000-7fed666d5000 ---p 00028000 08:02 30543907                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/stats/_stats.so
> 7fed666d5000-7fed666d9000 rw-p 00027000 08:02 30543907                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/stats/_stats.so
> 7fed666d9000-7fed66799000 rw-p 00000000 00:00 0 
> 7fed66799000-7fed667a5000 r-xp 00000000 08:02 30543508                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/signal/_spectral.so
> 7fed667a5000-7fed669a4000 ---p 0000c000 08:02 30543508                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/signal/_spectral.so
> 7fed669a4000-7fed669a7000 rw-p 0000b000 08:02 30543508                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/signal/_spectral.so
> 7fed669a7000-7fed669e7000 rw-p 00000000 00:00 0 
> 7fed669e7000-7fed669fe000 r-xp 00000000 08:02 30542761                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/fftpack/convolve.so
> 7fed669fe000-7fed66bfd000 ---p 00017000 08:02 30542761                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/fftpack/convolve.so
> 7fed66bfd000-7fed66bff000 rw-p 00016000 08:02 30542761                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/fftpack/convolve.so
> 7fed66bff000-7fed66c53000 r-xp 00000000 08:02 30542758                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/fftpack/_fftpack.so
> 7fed66c53000-7fed66e52000 ---p 00054000 08:02 30542758                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/fftpack/_fftpack.so
> 7fed66e52000-7fed66e59000 rw-p 00053000 08:02 30542758                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/fftpack/_fftpack.so
> 7fed66e59000-7fed66e5a000 rw-p 00000000 00:00 0 
> 7fed66e5a000-7fed66e6e000 r-xp 00000000 08:02 30543755                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/spatial/_distance_wrap.so
> 7fed66e6e000-7fed6706e000 ---p 00014000 08:02 30543755                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/spatial/_distance_wrap.so
> 7fed6706e000-7fed6706f000 rw-p 00014000 08:02 30543755                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/spatial/_distance_wrap.so
> 7fed6706f000-7fed670af000 rw-p 00000000 00:00 0 
> 7fed670af000-7fed67172000 r-xp 00000000 08:02 30543767                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/spatial/qhull.so
> 7fed67172000-7fed67371000 ---p 000c3000 08:02 30543767                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/spatial/qhull.so
> 7fed67371000-7fed6737e000 rw-p 000c2000 08:02 30543767                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/spatial/qhull.so
> 7fed6737e000-7fed6737f000 rw-p 00000000 00:00 0 
> 7fed6737f000-7fed673fa000 r-xp 00000000 08:02 30543762                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/spatial/ckdtree.so
> 7fed673fa000-7fed675fa000 ---p 0007b000 08:02 30543762                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/spatial/ckdtree.so
> 7fed675fa000-7fed67602000 rw-p 0007b000 08:02 30543762                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/spatial/ckdtree.so
> 7fed67602000-7fed67647000 r-xp 00000000 08:02 30542843                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/interpolate/interpnd.so
> 7fed67647000-7fed67846000 ---p 00045000 08:02 30542843                   /home/jesse/programs/anaconda/lib/python2.7/site-packages/scipy/interpolate/interpnd.soAborted (core dumped)
> 

I checked the image size before hand:

Energy map = (576, 299)
Image = (576, 299, 3)

## Way to reproduce

I can not share the image, but the code is as follows, where the error occurs on the second seam_carve call:

```
from skimage import filters, util, transform

img = util.img_as_float(img)
energy_map = filters.sobel(color.rgb2gray(img))
num = img.shape[0] - size
img = transform.seam_carve(img, energy_map, 'vertical', num)

img = util.img_as_float(img)
energy_map = filters.sobel(color.rgb2gray(img))
print(energy_map.shape, img.shape)
img = transform.seam_carve(img, energy_map, 'horizontal', num)
```
I am using Kubuntu 64-bit, Python 2 with Anaconda.

```
>>> skimage.__version__
'0.12.3
```




Discussion:
Could you specify the `dtype` and `shape` of your image, and what is `size` in your snippet?
Hi, as I mentioned above the shape before failure is:

Energy map = (576, 299)
Image = (576, 299, 3)

The original shape is:

Image = (576, 576, 3)

So, I'm trying to cut 277 pixels from axis 0 and axis 1.

The dtype for the image and energy map are float64 prior to the second call.  Visually, the energy map and the image look OK.



Hello,

I think I might have found the issue.  Here's the original code:

```
utils.assert_nD(img, (2, 3))
    image = util.img_as_float(img, force_copy)
    energy_map = util.img_as_float(energy_map, force_copy)

    if image.ndim == 2:
        image = image[..., np.newaxis]

    if mode == "horizontal":
        image = np.transpose(image, (1, 0, 2))

    image = np.ascontiguousarray(image)
    out = _seam_carve_v(image, energy_map, num, border)

    if mode == "horizontal":
out = np.transpose(out, (1, 0, 2))
```

But, looks like we need to transport the energy_map as well, so I propose adding:


```
    if mode == "horizontal":
        image = np.transpose(image, (1, 0, 2))
        energy_map = np.transpose(energy_map, (1, 0, 2))
```

I haven't made this change, because I just wrote my own in the meantime.  But, it was bugging me last night, while I was out for a walk why when I did the 'horizontal' on it's own, I got garbage.  I think this is the problem.

Cheers.

@jessejohns well spotted! If you have time to do a PR, (including a test to prevent regression), it would be much appreciated! Otherwise this is already very valuable and we'll aim to get it fixed soon!
We will take this one with Ines.
Hi, I would like to address this issue. I just have to transpose the energy_map before seam carve and add  a test to prevent regression, correct? Also, could you provide a hint on how to write a test to prevent regression?
@meriki I am already working on this one!

Resolving patch:
diff --git a/skimage/transform/seam_carving.py b/skimage/transform/seam_carving.py
--- a/skimage/transform/seam_carving.py
+++ b/skimage/transform/seam_carving.py
@@ -55,12 +55,13 @@ def seam_carve(image, energy_map, mode, num, border=1, force_copy=True):
         image = image[..., np.newaxis]
 
     if mode == 'horizontal':
-        image = np.transpose(image, (1, 0, 2))
+        image = np.swapaxes(image, 0, 1)
+        energy_map = np.swapaxes(energy_map, 0, 1)
 
     image = np.ascontiguousarray(image)
     out = _seam_carve_v(image, energy_map, num, border)
 
     if mode == 'horizontal':
-        out = np.transpose(out, (1, 0, 2))
+        out = np.swapaxes(out, 0, 1)
 
     return np.squeeze(out)


Test patch:
diff --git a/skimage/transform/tests/test_seam_carving.py b/skimage/transform/tests/test_seam_carving.py
--- a/skimage/transform/tests/test_seam_carving.py
+++ b/skimage/transform/tests/test_seam_carving.py
@@ -7,16 +7,25 @@ def test_seam_carving():
     img = np.array([[0, 0, 1, 0, 0],
                     [0, 0, 1, 0, 0],
                     [0, 0, 1, 0, 0],
-                    [0, 1, 0, 0, 0],
-                    [1, 0, 0, 0, 0]], dtype=np.float)
+                    [0, 1, 0, 0, 1],
+                    [1, 0, 0, 1, 0]], dtype=np.float)
+
+    expected = np.array([[0, 0, 0, 0],
+                        [0, 0, 0, 0],
+                        [0, 0, 0, 0],
+                        [0, 0, 0, 1],
+                        [0, 0, 1, 0]], dtype=np.float)
+
     energy = 1 - img
 
     out = transform.seam_carve(img, energy, 'vertical', 1, border=0)
-    testing.assert_allclose(out, 0)
+    testing.assert_equal(out, expected)
 
     img = img.T
+    energy = energy.T
+
     out = transform.seam_carve(img, energy, 'horizontal', 1, border=0)
-    testing.assert_allclose(out, 0)
+    testing.assert_equal(out, expected.T)
 
 
 if __name__ == '__main__':