An introduction to image compression algorithm based on seam clipping

Source: Internet
Author: User

Given a pair of color images, it consists of an MXN pixel array a[1..m,1..n], each pixel is a red-green-blue (RGB) brightness of the ternary group. Suppose we want to compress this image mildly. Specifically, we want to remove one pixel from each row, making the image narrower by one pixel. But to avoid the effects of visual effects, we require that the pixels removed in the next two rows must be in the same column or adjacent columns. That is, the deleted pixels make up a seam (seam) from the top row to the end row, and the neighboring pixels are adjacent vertically or diagonally.

A. Proof: the number of possible seams is an exponential function of M, assuming n>1.

In line 1th there are n possibilities for selecting pixel points, and there are 2-3 (a[i][j-1],a[i][j],a[i][j+1) in each row in the 2nd to M rows. (J=1 or J=n, is 2 possible), so there is a total of at least greater than n*2^ (M-1).

B Assuming now for each pixel a[i,j] we have calculated a real "degree of destruction" d[i,j], which means that deleting a pixel a[i,j] destroys the visual effect of the image. Visually, the lower the destruction of a pixel, the higher its similarity to neighboring pixels. It is assumed that the degree of destruction of a seam is defined as the sum of the degree of destruction of the contained loudness. Design algorithms to find the seams with the lowest degree of disruption. Analyze the time complexity of the algorithm.

It is simple to find the seams with the lowest degree of destruction, C[i,j] record the minimum degree of disruption of the seam to the current pixel. Starting from the first line, C[i,j] only the current pixel damage, direct assignment can be, line I, the previous pixel source of each pixel a total of three, the upper left, the upper and upper right, each time the calculation of c[i,j], you need to go to three cases of the lowest degree of destruction and then add the current pixel destruction degree, is the lowest degree of disruption to the current pixel of the seam. The recursive type is c[i][j]=d[i][j]+min{c[i-1][j-1],c[i-1][j],c[i-1][j+1]}.

Reference Link: http://www.ithao123.cn/content-6605545.html

15-8.cpp: Defines the entry point of the console application. #include "stdafx.h" #include <iostream> #include <time.h> #define ROW 10#define COL 10#define left-1#define Center 0#define Right 1#define INF 65536using namespace Std;int c[row + 1][col + 2];int R[row + 1][col + 1];int maxj;void Carving (int d[][col + 1]) {//give No. 0, 1 rows assignment for (int j = 0; J <= COL; j + +) {C[0][j] = 0;r[0][j] = center;c[1][j] = D[1][j];r [1] [j] = Center;} Assign a Sentinel to the boundary 0,col, thus c[i][j] without checking if J is 0 or col;for (int i = 0; I <= ROW; i++) {C[i][0] = Inf;c[i][col + 1] = INF;} According to Recursive C[i][j], starting from the second line for (int i=2;i<=row;i++) for (int j = 1; J <= COL; j + +) {int temp = inf;for (int k = J-1 ; K <= J + 1; k++) {if (C[i-1][k] < temp) {temp = c[i-1][k];r[i][j] = k-j;}} C[I][J] = temp+d[i][j];} The minimum value for the last line is the minimum clipping cost int temp = inf;for (int j = 1; J <= COL; j + +) if (C[row][j] < temp) {temp = C[ROW][J];MAXJ = J;}  Print out c[i][j]cout << "c[i][j]:\n" << "minimum slit cost for" << temp << Endl; for (int i = 1; I <= ROW; i++{for (int j = 1; J <= COL; j + +) cout << c[i][j] << ' \ t '; cout << Endl;}} Because the path is rolled back from the last line, it is returned with a return print void display (int row,int maxj) {switch (R[ROW][MAXJ]) {Case-1:display (row-1, maxj-1); cout &L t;< "\" << Endl;   Break Case 0:display (row-1, MAXJ); cout << "| |" << ENDL;   Break Case 1:display (row-1, MAXJ + 1); cout << "//" << Endl; Break;}}   int main () {//Initialize D[i][j];srand ((int) time (0) with 5-15 random number); Generate random number seed int D[row + 1][col + 1];for (int i = 0; I <= ROW; i++) for (int j = 0; J <= COL; j + +) D[i][j] = 5 + rand ()% 10;cout << "d[i][j]:\n"; for (int i = 1; I <= ROW, i++) {for (int j = 1; J <= COL; j + +) cout << D[i][j] &l t;< ' t '; cout << Endl;}    cout << "----------------------------------------------------------------------------" << Endl; Carving (d); cout << "----------------------------------------------------------------------------" <<    Endl;display (ROW, MAXJ); while (1); RetUrn 0;} 

The results are as follows:

An introduction to image compression algorithm based on seam clipping

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.