图像转置

代码如下:

void Ctry::OnTryTyr1()
{
	 //TODO:  在此添加命令处理程序代码
	IplImage *img = cvLoadImage("C:\\Users\\Administrator\\Desktop\\3838.jpg");
	IplImage *TransPose  = cvCreateImage(cvSize(img->height, img->width), 8, 3);

	CvScalar pixel;
	for (int i = 0; i < img->width; i++)
	{	
		for (int j = 0; j < img->height; j++)
		{
			pixel = cvGet2D(img, j, i);
			cvSet2D(TransPose, i, j, pixel);
		}
	}
	
	cvNamedWindow("TransPose", CV_WINDOW_AUTOSIZE);
	cvShowImage("TransPose", TransPose);
	cvNamedWindow("img", CV_WINDOW_AUTOSIZE);
	cvShowImage("img", img);
	cvWaitKey(0);

	cvReleaseImage(&img);
	cvReleaseImage(&TransPose);
	cvDestroyWindow("TransPose");
	cvDestroyWindow("img");
}

效果图: 图像转置_第1张图片           

你可能感兴趣的:(图像转置)