{"id":4991,"date":"2017-01-23T10:00:37","date_gmt":"2017-01-23T15:00:37","guid":{"rendered":"https:\/\/pyimagesearch.com\/?p=4991"},"modified":"2021-04-17T14:47:18","modified_gmt":"2021-04-17T18:47:18","slug":"seam-carving-with-opencv-python-and-scikit-image","status":"publish","type":"post","link":"https:\/\/pyimagesearch.com\/2017\/01\/23\/seam-carving-with-opencv-python-and-scikit-image\/","title":{"rendered":"Seam carving with OpenCV, Python, and scikit-image"},"content":{"rendered":"<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-5020\" src=\"https:\/\/pyimagesearch.com\/wp-content\/uploads\/2017\/01\/seam_carving_animation.gif\" alt=\"seam_carving_animation\" width=\"291\" height=\"234\"><\/p>\n<p>Easily one of my all-time favorite papers in computer vision literature is <em><a href=\"http:\/\/perso.crans.org\/frenoy\/matlab2012\/seamcarving.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">Seam Carving for Content-Aware Image Resizing<\/a><\/em> by Avidan and Shamir from Mitsubishi Electric Research Labs (MERL).<\/p>\n<p>Originally published in the SIGGRAPH 2007 proceedings, I read this paper for the first time during my computational photography class as an undergraduate student.<\/p>\n<p>This paper, along with <a href=\"https:\/\/www.youtube.com\/watch?v=qadw0BRKeMk\" target=\"_blank\" rel=\"noopener noreferrer\">the demo video from the authors<\/a>, <strong><em>made the algorithm feel like magic<\/em><\/strong>, especially to a student who was just getting his feet wet in the world of computer vision and image processing.<\/p>\n<p>The seam carving algorithm works by finding connected pixels called <em>seams<\/em> with <em>low energy <\/em>(i.e., least important) that traverse the entire image from left-to-right or top-to-bottom.<\/p>\n<p>These seams are then removed from the original image, allowing us to resize the image while preserving the most salient regions (the original algorithm also supports <em>adding seams<\/em>, allowing us to <em>increase<\/em> the image size as well).<\/p>\n<p>In the remainder of today&#8217;s blog post I&#8217;ll discuss the seam carving algorithm, how it works, and how to apply seam carving using Python, OpenCV, and sickit-image.<\/p>\n<p><em><strong>To learn more about this classic computer vision algorithm, just keep reading!<\/strong><\/em><\/p>\n<div id=\"pyi-source-code-block\" class=\"source-code-wrap\"><div class=\"gpd-source-code\">\n    <div class=\"gpd-source-code-content\">\n        <img decoding=\"async\" src=\"\/\/pyimagesearch.com\/wp-content\/uploads\/2020\/01\/source-code-icon.png\" alt=\"\">\n        <h4>Looking for the source code to this post?<\/h4>\n                    <a href=\"#download-the-code\" class=\"pyis-cta-modal-open-modal\">Jump Right To The Downloads Section <svg class=\"svg-icon arrow-right\" width=\"12\" height=\"12\" aria-hidden=\"true\" role=\"img\" focusable=\"false\" viewBox=\"0 0 14 14\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><path d=\"M6.8125 0.1875C6.875 0.125 6.96875 0.09375 7.09375 0.09375C7.1875 0.09375 7.28125 0.125 7.34375 0.1875L13.875 6.75C13.9375 6.8125 14 6.90625 14 7C14 7.125 13.9375 7.1875 13.875 7.25L7.34375 13.8125C7.28125 13.875 7.1875 13.9062 7.09375 13.9062C6.96875 13.9062 6.875 13.875 6.8125 13.8125L6.1875 13.1875C6.125 13.125 6.09375 13.0625 6.09375 12.9375C6.09375 12.8438 6.125 12.75 6.1875 12.6562L11.0312 7.8125H0.375C0.25 7.8125 0.15625 7.78125 0.09375 7.71875C0.03125 7.65625 0 7.5625 0 7.4375V6.5625C0 6.46875 0.03125 6.375 0.09375 6.3125C0.15625 6.25 0.25 6.1875 0.375 6.1875H11.0312L6.1875 1.34375C6.125 1.28125 6.09375 1.1875 6.09375 1.0625C6.09375 0.96875 6.125 0.875 6.1875 0.8125L6.8125 0.1875Z\" fill=\"#169FE6\"><\/path><\/svg><\/a>\n            <\/div>\n<\/div>\n<\/div>\n<h2>Seam carving with OpenCV, Python, and scikit-image<\/h2>\n<p>The first part of this blog post will discuss <em>what<\/em> the seam carving algorithm is and <em>why<\/em> we may prefer to use it over traditional resizing methods.<\/p>\n<p>From there I&#8217;ll demonstrate how to use seam carving using OpenCV, Python, and scikit-image.<\/p>\n<p>Finally, I&#8217;ll wrap up this tutorial by providing a demonstration of the seam carving algorithm in action.<\/p>\n<h3>The seam carving algorithm<\/h3>\n<p>Introduced by Avidan and Shimar in 2007, the seam carving algorithm is used to resize (both downsample and upsample) an image by removing\/adding <em>seams<\/em> that have <em>low energy<\/em>.<\/p>\n<p>Seams are defined as connected pixels that flow from left-to-right or top-to-bottom provided that they traverse the <em>entire<\/em> width\/height of the image.<\/p>\n<p>Thus, in order to perform seam carving we need two important inputs:<\/p>\n<ol>\n<li><strong>The original image.<\/strong> This is the input image that we want to resize.<\/li>\n<li><strong>The energy map.<\/strong> We derive the energy map from the original image. The energy map should represent the most salient regions of the image. Typically, this is either the gradient magnitude representation (i.e., output of Sobel, Scharr, etc. operators), entropy maps, or saliency maps.<\/li>\n<\/ol>\n<p>For example, let&#8217;s take a look at the following image:<\/p>\n<p><figure id=\"attachment_5008\" aria-describedby=\"caption-attachment-5008\" style=\"width: 274px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-5008\" src=\"https:\/\/pyimagesearch.com\/wp-content\/uploads\/2017\/01\/seam_carving_input.png\" alt=\"Figure 1: Our input image to the seam carving algorithm [source: Wikipedia].\" width=\"274\" height=\"186\" srcset=\"https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_input.png?size=126x86&amp;lossy=2&amp;strip=1&amp;webp=1 126w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_input.png?lossy=2&amp;strip=1&amp;webp=1 274w\" sizes=\"(max-width: 274px) 100vw, 274px\" \/><figcaption id=\"caption-attachment-5008\" class=\"wp-caption-text\"><strong>Figure 1:<\/strong> Our input image to the seam carving algorithm [source: <a href=\"https:\/\/en.wikipedia.org\/wiki\/File:BroadwayTowerSeamCarvingA.png\" target=\"_blank\" rel=\"noopener noreferrer\">Wikipedia<\/a>].<\/figcaption><\/figure>Using this image as an input, we can compute the gradient magnitude to serve as our energy map:<\/p>\n<p><figure id=\"attachment_5009\" aria-describedby=\"caption-attachment-5009\" style=\"width: 274px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-5009\" src=\"https:\/\/pyimagesearch.com\/wp-content\/uploads\/2017\/01\/seam_carving_gradient_magnitude.png\" alt=\"Figure 2: Computing the gradient magnitude representation of of the input image. This representation will serve as our energy map [source: Wikipedia].\" width=\"274\" height=\"186\" srcset=\"https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_gradient_magnitude.png?size=126x86&amp;lossy=2&amp;strip=1&amp;webp=1 126w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_gradient_magnitude.png?lossy=2&amp;strip=1&amp;webp=1 274w\" sizes=\"(max-width: 274px) 100vw, 274px\" \/><figcaption id=\"caption-attachment-5009\" class=\"wp-caption-text\"><strong>Figure 2:<\/strong> Computing the gradient magnitude representation of of the input image. This representation will serve as our energy map [source: <a href=\"https:\/\/en.wikipedia.org\/wiki\/File:BroadwayTowerSeamCarvingB.png\" target=\"_blank\" rel=\"noopener noreferrer\">Wikipedia<\/a>].<\/figcaption><\/figure>Given our energy map we can then generate a set of seams that either span the image from left-to-right or top-to-bottom:<\/p>\n<p><figure id=\"attachment_5010\" aria-describedby=\"caption-attachment-5010\" style=\"width: 274px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-5010\" src=\"https:\/\/pyimagesearch.com\/wp-content\/uploads\/2017\/01\/seam_carving_finding_seams.png\" alt=\"Figure 3: Generating seams from the energy map. Low energy seams can be removed\/duplicated to perform the actual resizing [source: Wikipedia].\" width=\"274\" height=\"186\" srcset=\"https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_finding_seams.png?size=126x86&amp;lossy=2&amp;strip=1&amp;webp=1 126w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_finding_seams.png?lossy=2&amp;strip=1&amp;webp=1 274w\" sizes=\"(max-width: 274px) 100vw, 274px\" \/><figcaption id=\"caption-attachment-5010\" class=\"wp-caption-text\"><strong>Figure 3:<\/strong> Generating seams from the energy map. Low energy seams can be removed\/duplicated to perform the actual resizing [source: <a href=\"https:\/\/en.wikipedia.org\/wiki\/File:BroadwayTowerSeamCarvingC.png\" target=\"_blank\" rel=\"noopener noreferrer\">Wikipedia<\/a>].<\/figcaption><\/figure>These seams are efficiently computed via <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dynamic_programming\" target=\"_blank\" rel=\"noopener noreferrer\">dynamic programming<\/a> and are sorted by their energy. Seams with <em>low energy <\/em>are placed at the front of the list while <em>high energy seams<\/em> are placed at the back of the list.<\/p>\n<p>To resize an image we either <em>remove seams<\/em> with low energy to downsample an image or we <em>duplicate seams<\/em> with low energy to upsample the image.<\/p>\n<p>Below is an example of taking the original image, finding the seams with the lowest energy, and then removing them to reduce the final size of the output image:<\/p>\n<p><figure id=\"attachment_5011\" aria-describedby=\"caption-attachment-5011\" style=\"width: 160px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-5011\" src=\"https:\/\/pyimagesearch.com\/wp-content\/uploads\/2017\/01\/seam_carving_output.png\" alt=\"Figure 4: Removing low energy seams from an image using the seam carving algorithm [source: Wikipedia].\" width=\"160\" height=\"186\"><figcaption id=\"caption-attachment-5011\" class=\"wp-caption-text\"><strong>Figure 4:<\/strong> Removing low energy seams from an image using the seam carving algorithm [source: <a href=\"https:\/\/en.wikipedia.org\/wiki\/File:BroadwayTowerSeamCarvingE.png\" target=\"_blank\" rel=\"noopener noreferrer\">Wikipedia<\/a>].<\/figcaption><\/figure>For more information on the seam carving algorithm, <a href=\"http:\/\/perso.crans.org\/frenoy\/matlab2012\/seamcarving.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">please see the original publication<\/a>.<\/p>\n<h3>Why use traditional seam carving over traditional resizing?<\/h3>\n<p>Keep in mind that the purpose of seam carving is to preserve the most salient (i.e., &#8220;interesting&#8221;) regions of an image while still resizing the image itself.<\/p>\n<p>Using traditional methods for resizing changes the dimensions of the <em>entire<\/em> image &#8212; no care is taken to determine <em>what<\/em> part of the image is most or least important.<\/p>\n<p>Seam carving instead applies heuristics\/path finding derived from the energy map to determine <em>which<\/em> regions of the image can be removed\/duplicated to ensure (1) all &#8220;interesting&#8221; regions of the image are preserved and (2) this is done in an aesthetically pleasing way.<\/p>\n<p><em><strong>Note:<\/strong> Preserving the most interesting regions of an image in an aesthetically pleasing manner is a lot harder than it sounds. While seam carving may seem like magic, it&#8217;s actually not &#8212; and it has its limitations. See the &#8220;Summary&#8221; section for more information on these limitations.<\/em><\/p>\n<p>To compare traditional resizing versus seam carving, consider the following input image:<\/p>\n<figure id=\"attachment_5016\" aria-describedby=\"caption-attachment-5016\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-5016\" src=\"https:\/\/pyimagesearch.com\/wp-content\/uploads\/2017\/01\/seam_carving_example_resize.jpg\" alt=\"Figure 5: An example image to resize.\" width=\"600\" height=\"450\" srcset=\"https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_example_resize.jpg?size=126x95&amp;lossy=2&amp;strip=1&amp;webp=1 126w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_example_resize-300x225.jpg?lossy=2&amp;strip=1&amp;webp=1 300w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_example_resize.jpg?size=378x284&amp;lossy=2&amp;strip=1&amp;webp=1 378w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_example_resize.jpg?size=504x378&amp;lossy=2&amp;strip=1&amp;webp=1 504w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_example_resize.jpg?lossy=2&amp;strip=1&amp;webp=1 600w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><figcaption id=\"caption-attachment-5016\" class=\"wp-caption-text\"><strong>Figure 5:<\/strong> An example image to resize.<\/figcaption><\/figure>\n<p>This image has a width of 600 pixels and I would like to resize it to approximately 500 pixels.<\/p>\n<p>Using traditional interpolation methods my resized image would look like this:<\/p>\n<figure id=\"attachment_5017\" aria-describedby=\"caption-attachment-5017\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-5017\" src=\"https:\/\/pyimagesearch.com\/wp-content\/uploads\/2017\/01\/seam_carving_traditional.jpg\" alt=\"Figure 6: Resizing an image using traditional interpolation techniques.\" width=\"500\" height=\"416\" srcset=\"https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_traditional.jpg?size=126x105&amp;lossy=2&amp;strip=1&amp;webp=1 126w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_traditional-300x250.jpg?lossy=2&amp;strip=1&amp;webp=1 300w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_traditional.jpg?size=378x314&amp;lossy=2&amp;strip=1&amp;webp=1 378w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_traditional.jpg?lossy=2&amp;strip=1&amp;webp=1 500w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><figcaption id=\"caption-attachment-5017\" class=\"wp-caption-text\"><strong>Figure 6:<\/strong> Resizing an image using traditional interpolation techniques. Notice how the height changes along with the width to retain the aspect aspect ratio.<\/figcaption><\/figure>\n<p>However, by applying seam carving I can &#8220;shrink&#8221; the image along the horizontal dimension and still preserve the most interesting regions of the image <em>without <\/em>changing the image height:<\/p>\n<figure id=\"attachment_5018\" aria-describedby=\"caption-attachment-5018\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-5018 size-full\" src=\"https:\/\/pyimagesearch.com\/wp-content\/uploads\/2017\/01\/seam_carving_carved.jpg\" alt=\"Figure 7: Resizing the image using seam carving.\" width=\"600\" height=\"573\" srcset=\"https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_carved.jpg?size=126x120&amp;lossy=2&amp;strip=1&amp;webp=1 126w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_carved-300x287.jpg?lossy=2&amp;strip=1&amp;webp=1 300w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_carved.jpg?size=378x361&amp;lossy=2&amp;strip=1&amp;webp=1 378w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_carved.jpg?size=504x481&amp;lossy=2&amp;strip=1&amp;webp=1 504w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_carved.jpg?lossy=2&amp;strip=1&amp;webp=1 600w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><figcaption id=\"caption-attachment-5018\" class=\"wp-caption-text\"><strong>Figure 7:<\/strong> Resizing the image using seam carving.<\/figcaption><\/figure>\n<h3>Utilizing seam carving in computer vision and image processing<\/h3>\n<p>In this section I&#8217;ll demonstrate how to use seam carving with OpenCV, Python, and scikit-image.<\/p>\n<p>I&#8217;ll assume you already have OpenCV installed on your system &#8212; if not, <a href=\"https:\/\/pyimagesearch.com\/opencv-tutorials-resources-guides\/\" target=\"_blank\" rel=\"noopener noreferrer\">please refer to this page<\/a> where I provided resources to install OpenCV on many different operating systems.<\/p>\n<p>From there, you should ensure you have <a href=\"http:\/\/scikit-image.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">scikit-image<\/a> installed as well. <a href=\"http:\/\/scikit-image.org\/docs\/stable\/install.html\" target=\"_blank\" rel=\"noopener noreferrer\">This page<\/a> provides more information on installing scikit-image, but for most systems you can use <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pip<\/code> :<\/p>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"Seam carving with OpenCV, Python, and scikit-image\" data-enlighter-group=\"1\">$ pip install --upgrade scikit-image\n<\/pre>\n\n\n<p>Let&#8217;s go ahead and see how we can apply seam carving to our own images.<\/p>\n<p>Open up a new file, name it <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">seam_carving.py<\/code> , and insert the following code:<\/p>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"Seam carving with OpenCV, Python, and scikit-image\" data-enlighter-group=\"3\"># import the necessary packages\nfrom skimage import transform\nfrom skimage import filters\nimport argparse\nimport cv2\n\n# construct the argument parse and parse the arguments\nap = argparse.ArgumentParser()\nap.add_argument(\"-i\", \"--image\", required=True,\n\thelp=\"path to input image file\")\nap.add_argument(\"-d\", \"--direction\", type=str,\n\tdefault=\"vertical\", help=\"seam removal direction\")\nargs = vars(ap.parse_args())\n<\/pre>\n\n\n<p><strong>Lines 2-5<\/strong> import our required Python packages while <strong>Lines 8-13<\/strong> parse our command line arguments. This script will require one argument followed by a second optional one:<\/p>\n<ul>\n<li><code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">--image<\/code> : The path to the input image we want to apply seam carving to.<\/li>\n<li><code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">--direction<\/code> : The direction in which we&#8217;ll apply seam carving. A value of <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">vertical<\/code>  will adjust the image width while a value of <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">horizontal<\/code>  will adjust the image height. We default the carving direction to <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">vertical<\/code> .<\/li>\n<\/ul>\n<p>Next, let&#8217;s load our input image from disk, convert it to grayscale, and compute the Sobel gradient magnitude representation (i.e., our <em>energy map<\/em>):<\/p>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"15\" data-enlighter-title=\"Seam carving with OpenCV, Python, and scikit-image\" data-enlighter-group=\"9\"># load the image and convert it to grayscale\nimage = cv2.imread(args[\"image\"])\ngray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)\n\n# compute the Sobel gradient magnitude representation\n# of the image -- this will serve as our \"energy map\"\n# input to the seam carving algorithm\nmag = filters.sobel(gray.astype(\"float\"))\n\n# show the original image\ncv2.imshow(\"Original\", image)\n<\/pre>\n\n\n<p>In order to apply seam carving we&#8217;ll be using <a href=\"http:\/\/scikit-image.org\/docs\/dev\/api\/skimage.transform.html#seam-carve\" target=\"_blank\" rel=\"noopener noreferrer\">the implementation inside the scikit-image library<\/a>. The <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">seam_carve<\/code>  function accepts four required parameters:<\/p>\n<ol>\n<li>The input <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">image<\/code>  that we are applying seam carving to.<\/li>\n<li>An energy map.<\/li>\n<li>The direction in which we&#8217;ll be applying seam carving (either horizontal or vertical).<\/li>\n<li>The number of seams to remove. At this point in time the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">seam_carve<\/code>  function only supports <em>downsampling<\/em> images &#8212; no upsample support is provided.<\/li>\n<\/ol>\n<p>To demonstrate seam carving in action, let&#8217;s loop over a number of seams to remove:<\/p>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"27\" data-enlighter-title=\"Seam carving with OpenCV, Python, and scikit-image\" data-enlighter-group=\"13\"># loop over a number of seams to remove\nfor numSeams in range(20, 140, 20):\n\t# perform seam carving, removing the desired number\n\t# of frames from the image -- `vertical` cuts will\n\t# change the image width while `horizontal` cuts will\n\t# change the image height\n\tcarved = transform.seam_carve(image, mag, args[\"direction\"],\n\t\tnumSeams)\n\tprint(\"[INFO] removing {} seams; new size: \"\n\t\t\"w={}, h={}\".format(numSeams, carved.shape[1],\n\t\t\tcarved.shape[0]))\n\n\t# show the output of the seam carving algorithm\n\tcv2.imshow(\"Carved\", carved)\n\tcv2.waitKey(0)\n<\/pre>\n\n\n<p>We call the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">seam_carve<\/code>  function on <strong>Lines 33 and 34<\/strong>, removing the current number of <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">numSeams<\/code> .<\/p>\n<p>The new carved image dimensions are printed to our terminal on <strong>Lines 35-37<\/strong>.<\/p>\n<p>We also display the seam carved image to our screen on <strong>Lines 40 and 41<\/strong>.<\/p>\n<h3>Seam carving results<\/h3>\n<p>To give this seam carving example a try for yourself, be sure to download the source code and example image using the <strong><em>&#8220;Downloads&#8221;<\/em><\/strong> section at the bottom of this blog post.<\/p>\n<p>From there, execute the following command:<\/p>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"Seam carving with OpenCV, Python, and scikit-image\" data-enlighter-group=\"16\">$ python seam_carving.py --image bryce_canyon.jpg\n<\/pre>\n\n\n<figure id=\"attachment_5013\" aria-describedby=\"caption-attachment-5013\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-5013\" src=\"https:\/\/pyimagesearch.com\/wp-content\/uploads\/2017\/01\/seam_carving_vertical.jpg\" alt=\"Figure 8: (Left) The original input image. (Right) Removing vertical seams from the image, thereby decreasing the image width.\" width=\"600\" height=\"264\" srcset=\"https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_vertical.jpg?size=126x55&amp;lossy=2&amp;strip=1&amp;webp=1 126w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_vertical-300x132.jpg?lossy=2&amp;strip=1&amp;webp=1 300w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_vertical.jpg?size=378x166&amp;lossy=2&amp;strip=1&amp;webp=1 378w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_vertical.jpg?size=504x222&amp;lossy=2&amp;strip=1&amp;webp=1 504w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_vertical.jpg?lossy=2&amp;strip=1&amp;webp=1 600w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><figcaption id=\"caption-attachment-5013\" class=\"wp-caption-text\"><strong>Figure 8:<\/strong> <em>(Left)<\/em> The original input image. <em>(Right) <\/em>Removing vertical seams from the image, thereby decreasing the image width.<\/figcaption><\/figure>\n<p>On the <em>left<\/em> you can see the original input image &#8212; a photo of <a href=\"https:\/\/www.nps.gov\/brca\/index.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Bryce Canyon<\/a>, one of the most beautiful National Parks to visit in the United States. Then on the <em>right<\/em> we have the seam carved image. As you can see, we have <em>removed vertical seams<\/em> from the image, thereby decreasing the image width.<\/p>\n<p>We can reduce the image height by <em>removing horizontal seams<\/em>:<\/p>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"Seam carving with OpenCV, Python, and scikit-image\" data-enlighter-group=\"17\">$ python seam_carving.py --image bryce_canyon.jpg --direction horizontal\n<\/pre>\n\n\n<figure id=\"attachment_5014\" aria-describedby=\"caption-attachment-5014\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-5014\" src=\"https:\/\/pyimagesearch.com\/wp-content\/uploads\/2017\/01\/seam_carving_horizontal.jpg\" alt=\"Figure 9: (Left) The original image. (Right) Removing horizontal seams from the image to decrease height.\" width=\"600\" height=\"250\" srcset=\"https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_horizontal.jpg?size=126x53&amp;lossy=2&amp;strip=1&amp;webp=1 126w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_horizontal-300x125.jpg?lossy=2&amp;strip=1&amp;webp=1 300w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_horizontal.jpg?size=378x158&amp;lossy=2&amp;strip=1&amp;webp=1 378w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_horizontal.jpg?size=504x210&amp;lossy=2&amp;strip=1&amp;webp=1 504w, https:\/\/b2633864.smushcdn.com\/2633864\/wp-content\/uploads\/2017\/01\/seam_carving_horizontal.jpg?lossy=2&amp;strip=1&amp;webp=1 600w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><figcaption id=\"caption-attachment-5014\" class=\"wp-caption-text\"><strong>Figure 9:<\/strong> <em>(Left)<\/em> The original image. <em>(Right)<\/em> Removing horizontal seams from the image to decrease height.<\/figcaption><\/figure>\n<p>I have also included a GIF animation below that demonstrates seam carving one pixel at a time to give you a better feel for the algorithm:<\/p>\n<figure id=\"attachment_5020\" aria-describedby=\"caption-attachment-5020\" style=\"width: 291px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-5020\" src=\"https:\/\/pyimagesearch.com\/wp-content\/uploads\/2017\/01\/seam_carving_animation.gif\" alt=\"Figure 10: Applying seam carving to an image using OpenCV, Python, and scikit-image.\" width=\"291\" height=\"234\" \/><figcaption id=\"caption-attachment-5020\" class=\"wp-caption-text\"><strong>Figure 10:<\/strong> Applying seam carving to an image using OpenCV, Python, and scikit-image.<\/figcaption><\/figure>\n<div id=\"pitch\" style=\"padding: 40px; width: 100%; background-color: #F4F6FA;\">\r\n\t<h3>What's next? We recommend <a target=\"_blank\" href=\"https:\/\/pyimagesearch.com\/pyimagesearch-university\/?utm_source=blogPost&utm_medium=bottomBanner&utm_campaign=What%27s%20next%3F%20I%20recommend\">PyImageSearch University<\/a>.<\/h3>\r\n\r\n\t<script src=\"https:\/\/fast.wistia.com\/embed\/medias\/kno0cmko2z.jsonp\" async><\/script><script src=\"https:\/\/fast.wistia.com\/assets\/external\/E-v1.js\" async><\/script><div class=\"wistia_responsive_padding\" style=\"padding:56.25% 0 0 0;position:relative;\"><div class=\"wistia_responsive_wrapper\" style=\"height:100%;left:0;position:absolute;top:0;width:100%;\"><div class=\"wistia_embed wistia_async_kno0cmko2z videoFoam=true\" style=\"height:100%;position:relative;width:100%\"><div class=\"wistia_swatch\" style=\"height:100%;left:0;opacity:0;overflow:hidden;position:absolute;top:0;transition:opacity 200ms;width:100%;\"><img decoding=\"async\" src=\"https:\/\/fast.wistia.com\/embed\/medias\/kno0cmko2z\/swatch\" style=\"filter:blur(5px);height:100%;object-fit:contain;width:100%;\" alt=\"\" aria-hidden=\"true\" onload=\"this.parentNode.style.opacity=1;\" \/><\/div><\/div><\/div><\/div>\r\n\r\n\t<div style=\"margin-top: 32px; margin-bottom: 32px; \">\r\n\t\t<strong>Course information:<\/strong><br\/>\r\n\t\t86+ total classes \u2022 115+ hours hours of on-demand code walkthrough videos \u2022 Last updated: May 2026<br\/>\r\n\t\t<span style=\"color: #169FE6;\">\u2605\u2605\u2605\u2605\u2605<\/span> 4.84 (128 Ratings) \u2022 16,000+ Students Enrolled\r\n\t<\/div>\r\n\r\n\t<p><strong>I strongly believe that if you had the right teacher you could <em>master<\/em> computer vision and deep learning.<\/strong><\/p>\r\n\r\n\t<p>Do you think learning computer vision and deep learning has to be time-consuming, overwhelming, and complicated? Or has to involve complex mathematics and equations? Or requires a degree in computer science?<\/p>\r\n\r\n\t<p>That\u2019s <em>not<\/em> the case.<\/p>\r\n\r\n\t<p>All you need to master computer vision and deep learning is for someone to explain things to you in <em>simple, intuitive<\/em> terms. <em>And that\u2019s exactly what I do<\/em>. My mission is to change education and how complex Artificial Intelligence topics are taught.<\/p>\r\n\r\n\t<p>If you're serious about learning computer vision, your next stop should be PyImageSearch University, the most comprehensive computer vision, deep learning, and OpenCV course online today. Here you\u2019ll learn how to <em>successfully<\/em> and <em>confidently<\/em> apply computer vision to your work, research, and projects. Join me in computer vision mastery.<\/p>\r\n\r\n\t<p><strong>Inside PyImageSearch University you'll find:<\/strong><\/p>\r\n\r\n\t<ul style=\"margin-left: 0px;\">\r\n\t\t<li style=\"list-style: none;\">&check; <strong>86+ courses<\/strong> on essential computer vision, deep learning, and OpenCV topics<\/li>\r\n\t\t<li style=\"list-style: none;\">&check; <strong>86 Certificates<\/strong> of Completion<\/li>\r\n\t\t<li style=\"list-style: none;\">&check; <strong>115+ hours hours<\/strong> of on-demand video<\/li>\r\n\t\t<li style=\"list-style: none;\">&check; <strong>Brand new courses released <em>regularly<\/em><\/strong>, ensuring you can keep up with state-of-the-art techniques<\/li>\r\n\t\t<li style=\"list-style: none;\">&check; <strong>Pre-configured Jupyter Notebooks in Google Colab<\/strong><\/li>\r\n\t\t<li style=\"list-style: none;\">&check; Run all code examples in your web browser \u2014 works on Windows, macOS, and Linux (no dev environment configuration required!)<\/li>\r\n\t\t<li style=\"list-style: none;\">&check; Access to <strong>centralized code repos for <em>all<\/em> 540+ tutorials<\/strong> on PyImageSearch<\/li>\r\n\t\t<li style=\"list-style: none;\">&check; <strong> Easy one-click downloads<\/strong> for code, datasets, pre-trained models, etc.<\/li>\r\n\t\t<li style=\"list-style: none;\">&check; <strong>Access<\/strong> on mobile, laptop, desktop, etc.<\/li>\r\n\t<\/ul>\r\n\r\n\t<p style=\"text-align: center;\">\r\n\t\t<a target=\"_blank\" class=\"button link\" href=\"https:\/\/pyimagesearch.com\/pyimagesearch-university\/?utm_source=blogPost&utm_medium=bottomBanner&utm_campaign=What%27s%20next%3F%20I%20recommend\" style=\"background-color: #6DC713; border-bottom: none;\">Click here to join PyImageSearch University<\/a>\r\n\t<\/p>\r\n<\/div>\n<h2>Summary<\/h2>\n<p>In today&#8217;s blog post I discussed the seminal seam carving algorithm used for content-aware resizing of images.<\/p>\n<p>This is a classic algorithm in computer vision literature, so if you haven&#8217;t read the original publication, <a href=\"http:\/\/perso.crans.org\/frenoy\/matlab2012\/seamcarving.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">I suggest you add it to your reading list<\/a>.<\/p>\n<p>Inside the paper Avidan and Shimar demonstrate that seam carving can not only be used for reducing image size, but also for\u00a0<em>increasing image size<\/em> as well; however, the scikit-image implementation currently only supports downsampling.<\/p>\n<p>While this algorithm may have felt like &#8220;magic&#8221; to myself as an undergraduate, I eventually learned there is no such thing as magic in the computer vision world &#8212;\u00a0<em>every algorithm has its limitations.<\/em><\/p>\n<p>For seam carving, these limitations often demonstrate themselves as less than visually appealing results where important semantic information of the image is partially destroyed or cut out entirely. A great example would be applying seam carving to an image that contains faces and seams from the faces are removed.<\/p>\n<p>To get around this we can annotate our image to provide &#8220;hints&#8221; to the seam carving algorithm, ensuring the labeled regions are not cut during the seam carving process. In an ideal world, we could provide energy maps that better reflect the salient regions of the image we wish to keep, thereby requiring no modification to the actual seam carving algorithm.<\/p>\n<p>Personally, I&#8217;m interested to see the future landscape of seam carving. With deep learning algorithms used for tasks such as saliency detection, these salient maps can then be used for seam carving. We may eventually see an end-to-end seam carving network.<\/p>\n<p>Anyway, I hope you enjoyed the discussion of this classic computer vision paper!<\/p>\n<p><em><strong>To be notified when future blog posts go live, be sure to enter your email address in the form below.<\/strong><\/em><\/p>\n<div id=\"download-the-code\" class=\"post-cta-wrap\">\n<div class=\"gpd-post-cta\">\n\t<div class=\"gpd-post-cta-content\">\n\t\t\n\n\t\t\t<div class=\"gpd-post-cta-top\">\n\t\t\t\t<div class=\"gpd-post-cta-top-image\"><img decoding=\"async\" src=\"https:\/\/pyimagesearch.com\/wp-content\/uploads\/2020\/01\/cta-source-guide-1.png\" alt=\"\" \/><\/div>\n\t\t\t\t\n\t\t\t\t<div class=\"gpd-post-cta-top-title\"><h4>Download the Source Code and FREE 17-page Resource Guide<\/h4><\/div>\n\t\t\t\t<div class=\"gpd-post-cta-top-desc\"><p>Enter your email address below to get a .zip of the code and a <strong>FREE 17-page Resource Guide on Computer Vision, OpenCV, and Deep Learning.<\/strong> Inside you'll find my hand-picked tutorials, books, courses, and libraries to help you master CV and DL!<\/p><\/div>\n\n\n\t\t\t<\/div>\n\n\t\t\t<div class=\"gpd-post-cta-bottom\">\n\t\t\t\t<form id=\"footer-cta-code\" class=\"footer-cta\" action=\"https:\/\/www.getdrip.com\/forms\/4130035\/submissions\" method=\"post\" target=\"blank\" data-drip-embedded-form=\"4130035\">\n\t\t\t\t\t<input name=\"fields[email]\" type=\"email\" value=\"\" placeholder=\"Your email address\" class=\"form-control\" \/>\n\n\t\t\t\t\t<button type=\"submit\">Download the code!<\/button>\n\n\t\t\t\t\t<div style=\"display: none;\" aria-hidden=\"true\"><label for=\"website\">Website<\/label><br \/><input type=\"text\" id=\"website\" name=\"website\" tabindex=\"-1\" autocomplete=\"false\" value=\"\" \/><\/div>\n\t\t\t\t<\/form>\n\t\t\t<\/div>\n\n\n\t\t\n\t<\/div>\n\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Easily one of my all-time favorite papers in computer vision literature is Seam Carving for Content-Aware Image Resizing by Avidan and Shamir from Mitsubishi Electric Research Labs (MERL). Originally published in the SIGGRAPH 2007 proceedings, I read this paper for&hellip;<\/p>\n","protected":false},"author":1,"featured_media":5014,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[14,2,27],"tags":[55,15,147,407],"class_list":{"0":"post-4991","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-image-processing","8":"category-libraries","9":"category-tutorials","10":"tag-image-processing-2","11":"tag-resizing","12":"tag-scikit-image","13":"tag-seam-carving","14":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.6.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Seam carving with OpenCV, Python, and scikit-image - PyImageSearch<\/title>\n<meta name=\"description\" content=\"Learn how to apply seam carving for content-aware image resizing using OpenCV, Python, and scikit-image.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/pyimagesearch.com\/2017\/01\/23\/seam-carving-with-opencv-python-and-scikit-image\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Seam carving with OpenCV, Python, and scikit-image - PyImageSearch\" \/>\n<meta property=\"og:description\" content=\"Learn how to apply seam carving for content-aware image resizing using OpenCV, Python, and scikit-image.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/pyimagesearch.com\/2017\/01\/23\/seam-carving-with-opencv-python-and-scikit-image\/\" \/>\n<meta property=\"og:site_name\" content=\"PyImageSearch\" \/>\n<meta property=\"article:published_time\" content=\"2017-01-23T15:00:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-04-17T18:47:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/pyimagesearch.com\/wp-content\/uploads\/2017\/01\/seam_carving_horizontal.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"600\" \/>\n\t<meta property=\"og:image:height\" content=\"250\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Adrian Rosebrock\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Adrian Rosebrock\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/pyimagesearch.com\/2017\/01\/23\/seam-carving-with-opencv-python-and-scikit-image\/\",\"url\":\"https:\/\/pyimagesearch.com\/2017\/01\/23\/seam-carving-with-opencv-python-and-scikit-image\/\",\"name\":\"Seam carving with OpenCV, Python, and scikit-image - PyImageSearch\",\"isPartOf\":{\"@id\":\"https:\/\/pyimagesearch.com\/#website\"},\"datePublished\":\"2017-01-23T15:00:37+00:00\",\"dateModified\":\"2021-04-17T18:47:18+00:00\",\"author\":{\"@id\":\"https:\/\/pyimagesearch.com\/#\/schema\/person\/5901b399e2f20b986362a00636181cca\"},\"description\":\"Learn how to apply seam carving for content-aware image resizing using OpenCV, Python, and scikit-image.\",\"breadcrumb\":{\"@id\":\"https:\/\/pyimagesearch.com\/2017\/01\/23\/seam-carving-with-opencv-python-and-scikit-image\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/pyimagesearch.com\/2017\/01\/23\/seam-carving-with-opencv-python-and-scikit-image\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/pyimagesearch.com\/2017\/01\/23\/seam-carving-with-opencv-python-and-scikit-image\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/pyimagesearch.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Seam carving with OpenCV, Python, and scikit-image\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/pyimagesearch.com\/#website\",\"url\":\"https:\/\/pyimagesearch.com\/\",\"name\":\"PyImageSearch\",\"description\":\"You can master Computer Vision, Deep Learning, and OpenCV - PyImageSearch\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/pyimagesearch.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/pyimagesearch.com\/#\/schema\/person\/5901b399e2f20b986362a00636181cca\",\"name\":\"Adrian Rosebrock\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/pyimagesearch.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/57e1f3a95feeb9b113f80510f086d7d81b6f62badd9bd69134e51037a8b79925?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/57e1f3a95feeb9b113f80510f086d7d81b6f62badd9bd69134e51037a8b79925?s=96&d=mm&r=g\",\"caption\":\"Adrian Rosebrock\"},\"description\":\"Hi there, I\u2019m Adrian Rosebrock, PhD. All too often I see developers, students, and researchers wasting their time, studying the wrong things, and generally struggling to get started with Computer Vision, Deep Learning, and OpenCV. I created this website to show you what I believe is the best possible way to get your start.\",\"url\":\"https:\/\/pyimagesearch.com\/author\/adrian\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Seam carving with OpenCV, Python, and scikit-image - PyImageSearch","description":"Learn how to apply seam carving for content-aware image resizing using OpenCV, Python, and scikit-image.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/pyimagesearch.com\/2017\/01\/23\/seam-carving-with-opencv-python-and-scikit-image\/","og_locale":"en_US","og_type":"article","og_title":"Seam carving with OpenCV, Python, and scikit-image - PyImageSearch","og_description":"Learn how to apply seam carving for content-aware image resizing using OpenCV, Python, and scikit-image.","og_url":"https:\/\/pyimagesearch.com\/2017\/01\/23\/seam-carving-with-opencv-python-and-scikit-image\/","og_site_name":"PyImageSearch","article_published_time":"2017-01-23T15:00:37+00:00","article_modified_time":"2021-04-17T18:47:18+00:00","og_image":[{"width":600,"height":250,"url":"https:\/\/pyimagesearch.com\/wp-content\/uploads\/2017\/01\/seam_carving_horizontal.jpg","type":"image\/jpeg"}],"author":"Adrian Rosebrock","twitter_misc":{"Written by":"Adrian Rosebrock","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/pyimagesearch.com\/2017\/01\/23\/seam-carving-with-opencv-python-and-scikit-image\/","url":"https:\/\/pyimagesearch.com\/2017\/01\/23\/seam-carving-with-opencv-python-and-scikit-image\/","name":"Seam carving with OpenCV, Python, and scikit-image - PyImageSearch","isPartOf":{"@id":"https:\/\/pyimagesearch.com\/#website"},"datePublished":"2017-01-23T15:00:37+00:00","dateModified":"2021-04-17T18:47:18+00:00","author":{"@id":"https:\/\/pyimagesearch.com\/#\/schema\/person\/5901b399e2f20b986362a00636181cca"},"description":"Learn how to apply seam carving for content-aware image resizing using OpenCV, Python, and scikit-image.","breadcrumb":{"@id":"https:\/\/pyimagesearch.com\/2017\/01\/23\/seam-carving-with-opencv-python-and-scikit-image\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/pyimagesearch.com\/2017\/01\/23\/seam-carving-with-opencv-python-and-scikit-image\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/pyimagesearch.com\/2017\/01\/23\/seam-carving-with-opencv-python-and-scikit-image\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/pyimagesearch.com\/"},{"@type":"ListItem","position":2,"name":"Seam carving with OpenCV, Python, and scikit-image"}]},{"@type":"WebSite","@id":"https:\/\/pyimagesearch.com\/#website","url":"https:\/\/pyimagesearch.com\/","name":"PyImageSearch","description":"You can master Computer Vision, Deep Learning, and OpenCV - PyImageSearch","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/pyimagesearch.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/pyimagesearch.com\/#\/schema\/person\/5901b399e2f20b986362a00636181cca","name":"Adrian Rosebrock","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/pyimagesearch.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/57e1f3a95feeb9b113f80510f086d7d81b6f62badd9bd69134e51037a8b79925?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/57e1f3a95feeb9b113f80510f086d7d81b6f62badd9bd69134e51037a8b79925?s=96&d=mm&r=g","caption":"Adrian Rosebrock"},"description":"Hi there, I\u2019m Adrian Rosebrock, PhD. All too often I see developers, students, and researchers wasting their time, studying the wrong things, and generally struggling to get started with Computer Vision, Deep Learning, and OpenCV. I created this website to show you what I believe is the best possible way to get your start.","url":"https:\/\/pyimagesearch.com\/author\/adrian\/"}]}},"_links":{"self":[{"href":"https:\/\/pyimagesearch.com\/wp-json\/wp\/v2\/posts\/4991","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pyimagesearch.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pyimagesearch.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pyimagesearch.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pyimagesearch.com\/wp-json\/wp\/v2\/comments?post=4991"}],"version-history":[{"count":5,"href":"https:\/\/pyimagesearch.com\/wp-json\/wp\/v2\/posts\/4991\/revisions"}],"predecessor-version":[{"id":21313,"href":"https:\/\/pyimagesearch.com\/wp-json\/wp\/v2\/posts\/4991\/revisions\/21313"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pyimagesearch.com\/wp-json\/wp\/v2\/media\/5014"}],"wp:attachment":[{"href":"https:\/\/pyimagesearch.com\/wp-json\/wp\/v2\/media?parent=4991"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pyimagesearch.com\/wp-json\/wp\/v2\/categories?post=4991"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pyimagesearch.com\/wp-json\/wp\/v2\/tags?post=4991"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}