As expected, high-energy areas are generally marginal, and low-energy areas are expanded by a small number of similar colors (skies). From here we can estimate that the reduction of the height of the picture, the reduced portion should be mostly in the sky area, the other parts remain unchanged. The next step is to decide which pixels need to be removed. We will reduce the height of a pixel by one pixel, and we need a column of a column to find that pixel to remove. We want to find a range of pixel sets with the lowest total energy possible, removing these seam and minimizing the effect on the entire image. You can determine the best point to remove pixels in the following two steps: Generateseam returns the optimal level Seam.func generateseam (IM image) that can be eliminated. Image) Seam {mat: = Generatecostmatrix (IM) return Findlowestcostseam (MAT)}
The first step is to use an eight-connected area pixel to filter the entire image horizontally to obtain a depletion matrix containing the lowest accumulated energy of "seams". This time we first look at the following code: GenerateCostMatrix from the left end of the image to each pixel, create an indication of the minimum consumption seam matrix .//// mat[x][y] is the accumulated energy of seam from the left end of the image to the Y-pixel point of the column X row. Func generatecostmatrix (im image. Image) [][]float64 { min, max := im. Bounds (). Min, im. Bounds (). Max height, width := max. Y-min.y, max. X-min.x mat := make ([][]float64, width) for X := min. X; x < max. X; x++ { mat[x-min. X] = make ([]float64, height) } // initialize first column of matrix for y := min. Y; y < max. Y; y++ { e, _, _, a := im. at (0, y). RGBA () mat[0][Y-min. Y] = float64 (e) / float64 (a) } updatepoint := func (X, y int) { e, _, _ , a := im. at (x, y). RGBA () up, down := math. Maxfloat64, math. maxfloat64 left := mat[x-1][y] if y != min. Y&NBSP;{&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;UP&NBSP;=&NBSP;MAT[X-1][Y-1] } if y < max. y-1 { down = mat[x-1][y+ 1] } val := math. MIn (Float64 (left), math. Min (Float64 (UP), float64 (Down))) mat[x][y] = val + (Float64 (e) / float64 (a)) } // calculate the remaining columns iteratively for x := min. X + 1; x < max. X; x++ { for y := min. Y; y < max. Y; y++ { updatepoint (x, Y) } } return mat} |
Hxapp2 Translated 2 weeks ago 0 Person Top top translation of good Oh! |