游程幅值对数据_恢复图像块

游程:连续0的个数

幅值:非零数

《游程幅值对数据_恢复图像块》

 游程-幅值对按照如图的红色路径给出的。

根据游程-幅值对恢复图像块的代码

#include<iostream> 
#include<vector>
using namespace std;
//======================
//右(1,0);下(0,1);斜下(-1,1)斜上(1,-1)
#define GoR(x,y) x+1,y
#define GoD(x,y) x,y+1
#define GoLD(x,y) x-1,y+1
#define GoRU(x,y) x+1,y-1
bool InScale(int x, int y, int row, int line)
{ 
	return(row >= 0 &&row < x && line >= 0 && line < y);
}
void matchImage(int**imageNode, int x, int y, vector<int>*swim)
{
	char r = 'r';
	int rx = 0, ry = 0;
	for (vector<int>::iterator iter=swim->begin(); iter != swim->end(); iter++)//久没有写,忘了这个。我去swim->begin()
	{ 
		switch (r)
		{
		case 'r':
			imageNode[ry][rx] = (*iter);
			if (InScale(x, y, GoRU(rx, ry)))
			{
				rx++;
				ry--;
			}
			else
			{
				r = 'x';
				if (rx+ 1 < x)
					rx++;
				else ry++;
				
			}
			break;
		case 'x':imageNode[ry][rx] = (*iter);
			if (InScale(x, y, GoLD(rx, ry)))
			{
				rx--;
				ry++;
			}
			else
			{
				r = 'r';
				if (ry + 1 < y)
					ry++;
				else rx++;
				
			}
			break;
		}
	}
}

void display(int**imageNode, int &x, int &y)
{
	for (int i = 0; i < y; i++)
	{
		for (int j = 0; j < x; j++)
			cout << imageNode[i][j] << " ";
		cout << endl;
	}

}
int main()
{
	int x, y;
	//===========================
	cout << "请输入像素块x*y" << endl << "x:";
	cin >> x;
	cout << "y:";
	cin >> y;
	//================================
	cout << "游程 幅值输入" << endl;
	vector<int> swim;
	int xx, yy;
	do
	{
		cin >> xx >> yy; 
		while (xx>0)
		{
			swim.push_back(0);
			xx--;
		}
		if (yy != 0)
			swim.push_back(yy);
	} while (yy != 0);
	if (swim.size() != (x*y))
	{
		cout << "输入数据不匹配";
		return 0;
	}
	//====================================
	int**imageNode;
	imageNode = new int*[y]; 
	for (int i = 0; i<y; i++)
		imageNode[i] = new int[x];
	matchImage(imageNode, x, y, &swim);
	display(imageNode, x, y);
	for (int i = 0; i<y; i++)
		delete []imageNode[i];
	delete []imageNode;
	system("pause");
	return 0;
}

《游程幅值对数据_恢复图像块》

    原文作者:游程编码问题
    原文地址: https://blog.csdn.net/u014646950/article/details/51287731
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞