PhotoShop算法实现--图像转置(十七)

PhotoShop算法实现--图像转置(十七)

[email protected]

http://blog.csdn.net/kezunhai

        图像的转置(Transpose)是将图像的x坐标和y坐标互换,该操作改变图像的大小,刚好是图像的宽和高互换。原理这么简单,赶快动手实现下吧,博主的实现代码如下:

// 图像的转置
void PhotoShop::Transpose(Mat& img, Mat& dst)
{
	if ( dst.empty())
		dst.create(img.cols, img.rows, img.type());

	int height = img.rows; 
	int width = img.cols;
	int chns = img.channels();

	int i, j;	
	for ( i=0; i<height; ++i)
	{
		const unsigned char* srcData = (unsigned char*)img.data + img.step*i;
		for ( j=0; j<width; ++j)
		{
			((unsigned char*)dst.data + dst.step*j)[i*chns] = srcData[j*chns];
			((unsigned char*)dst.data + dst.step*j)[i*chns+1] = srcData[j*chns+1];
			((unsigned char*)dst.data + dst.step*j)[i*chns+2] = srcData[j*chns+2];			 
		}
	}
}
        测试效果如下:




你可能感兴趣的:(transpose,图像转置,PhotoShop算法)