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

游程:连续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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值