We are given a color picture consisting of an m?n array AŒ1::m;1::n? of pixels, where each pixel specifies a triple of red, green, and blue (RGB) intensities. Sup- pose that we wish to compress this picture slightly. Specifically, we wish to remove one pixel from each of the m rows, so that the whole picture becomes one pixel narrower. To avoid disturbing visual effects, however, we require that the pixels removed in two adjacent rows be in the same or adjacent columns; the pixels re- moved form a “seam” from the top row to the bottom row where successive pixels in the seam are adjacent vertically or diagonally.
Show that the number of such possible seams grows at least exponentially in m, assuming that n > 1.
Suppose now that along with each pixel AŒi;j?, we have calculated a real- valued disruption measure , indicating how disruptive it would be to remove pixel . Intuitively, the lower a pixel’s disruption measure, the more similar the pixel is to its neighbors. Suppose further that we define the disruption measure of a seam to be the sum of the disruption measures of its pixels.
write a program in any modern language. Python because the output can be put in a visual representation
Part 1 reinforces the recurrence relation of the Fibonacci sequence with a comparison to the dynamic programming algorithm. (goals 1, 3, 4)
Using the same algorithm in different ways illustrates the efficiency achieved by different algorithmic methods.
Part 2 reinforce the use of algorithms using a modern language.
a) In the first column, we have n choices, so, we can choose any of the n pixels in the first row, however, in the subsequent rows, we will be restricted to choose any one of the following 3 pixels:
pixel directly below the current pixel
pixel to the left of the pixel below the current pixel
pixel to the right of the pixel below the current pixel
So, the total number of possible seams are
n*3*3. . .3 up to the last row
N = n*3m-1, which is exponential
b) Our approach for solving the problem is:
To find a minimum cost seam from row x to y, choose a valid pixel from row x, and find the minimum cost seam from x+1 to y . Find the pixel from x that minimizes the total cost.
Here is the formulation of the solution:

in the above expression, x is the row, y is the column and c is the chosen pixel in x-1 row.
Implementation above algorithm as it is would be exponential. But we can reduce it's complexity by using dynamic programming. We store the value of MinSeam(i,j,k) in a 3D array. Hence using DP, our algorithm is:
MinSeam(M,d,x,y,c)
if M[x,y,c] != -1
return M[x,y,c]
else
if x=1
res = Min1<=k<=n{d[1,k] + MinSeam(M,d,x+1,y,k)}
M[x,y,c] = res
return res
else if x=n
res = Minc-1<=k<=c+1{d[n,k] }
M[x,y,c] = res
return res
else
res = Minc-1<=k<=c+1{d[x,k] + MinSeam(M,d,x+1,y,k)}
M[x,y,c] = res
return res
To get the minimum cost seam for given array, create an array M of size mxnxn initialized to -1. and call MinSeam(M,d,1,n,0)
we are calculating the value for every entry in M, it take O(n) when x is 1 and for rest, we can calculate in constant time.
So, time complexity of our algorithm is O(mn2)
We are given a color picture consisting of an m?n array AŒ1::m;1::n? of pixels, where each...
Psuedocode works! DP is dynamic programming for this
algorithm
Problem 4.2. (Difficulty 3) Seam carving is a real-world application of DP for content- aware image resizing. The simplest way to reduce the size of an image is cropping and scaling, i.e. cutting out parts of the image and scaling down the size. However, cropping leaves visible crop lines of incontinuity while scaling reduces the details of the image. We would like to intelligently reducing the size while accounting for the...