user-0 提问: C语言实现128*128到300*300的图像放大

回复:
user: user-1
content: 定义动态数组吧，不然容易出现stack overflow错误

user: user-2
content: 引用 15 楼 jasminesst 的回复:[quote=引用 14 楼 wenbei2006 的回复:] http://wenku.baidu.com/view/a3816b0d4a7302768e993972.html，看一下这个原理吧；如果要代码的话，这里有 http://download.csdn.net/detail/zjfly2008/1185942  这样可以不？？你看看！  #include <stdio.h> #include <iostream>  void main() { 	int i,j; 	float k1,k2; 	float c1,c2; 	int id,jd;  	float temp; 	float Data[128][128];         float Data1[300][300];  	FILE *q; 	q=fopen("atte_para_newC_1.img","rb");  	for (i=1;i<=128;i++) 	{ 		for(j=1;j<=128;j++) 		{ 			fread(&temp,sizeof(float),1,q); 			Data[i][j]=temp; 		} 	} 	fclose(q);  	k1=300/128; 	k2=300/128; 	c1=1/k1; 	c2=1/k2;  	for (i=1;i<=300;i++) 	{ 		for(j=1;j<=300;j++) 		{ 			id=ceil(c1*i); 			jd=ceil(c2*j); 			Data1[i][j]=Data[id][jd]; 		} 	}  	FILE *fp; 	fp=fopen("bm.img","wb"); 	fwrite(Data1,sizeof(float),128*128,fp); 	fclose; }[/quote]这个能够实现最基本的方法，还是建议楼主从最简单的nearest，bilinear方法看起，然后到cubic，spline样条插值，稍微复杂一些的lanczos插值等等

user: user-0
content: 引用 14 楼 wenbei2006 的回复:http://wenku.baidu.com/view/a3816b0d4a7302768e993972.html，看一下这个原理吧；如果要代码的话，这里有 http://download.csdn.net/detail/zjfly2008/1185942  这样可以不？？你看看！  #include <stdio.h> #include <iostream>  void main() { 	int i,j; 	float k1,k2; 	float c1,c2; 	int id,jd;  	float temp; 	float Data[128][128];         float Data1[300][300];  	FILE *q; 	q=fopen("atte_para_newC_1.img","rb");  	for (i=1;i<=128;i++) 	{ 		for(j=1;j<=128;j++) 		{ 			fread(&temp,sizeof(float),1,q); 			Data[i][j]=temp; 		} 	} 	fclose(q);  	k1=300/128; 	k2=300/128; 	c1=1/k1; 	c2=1/k2;  	for (i=1;i<=300;i++) 	{ 		for(j=1;j<=300;j++) 		{ 			id=ceil(c1*i); 			jd=ceil(c2*j); 			Data1[i][j]=Data[id][jd]; 		} 	}  	FILE *fp; 	fp=fopen("bm.img","wb"); 	fwrite(Data1,sizeof(float),128*128,fp); 	fclose; }

user: user-2
content: http://wenku.baidu.com/view/a3816b0d4a7302768e993972.html，看一下这个原理吧；如果要代码的话，这里有 http://download.csdn.net/detail/zjfly2008/1185942

user: user-3
content: 应该是周围8个点的RGB平均值效果会好些吧

user: user-4
content: 搜 NearestNeighbor Bilinear HighQualityBilinear Bicubic HighQualityBicubic

user: user-0
content: 引用 5 楼 xiaohuh421 的回复:放大最重要的就是插值算法, 有线性插值,也有非线性插值, 当然, 非线性插值的放大效果会好一些.  大家说的有道理，如何扩大插值，求一个具体的方法详解下啊！！

user: user-4
content: Using Interpolation Mode to Control Image Quality During Scaling   --------------------------------------------------------------------------------  The interpolation mode of a Graphics object influences the way Microsoft Windows GDI+ scales (stretches and shrinks) images. The InterpolationMode enumeration in Gdiplusenums.h defines several interpolation modes, some of which are shown in the following list:   InterpolationModeNearestNeighbor  InterpolationModeBilinear  InterpolationModeHighQualityBilinear  InterpolationModeBicubic  InterpolationModeHighQualityBicubic  To stretch an image, each pixel in the original image must be mapped to a group of pixels in the larger image. To shrink an image, groups of pixels in the original image must be mapped to single pixels in the smaller image. The effectiveness of the algorithms that perform these mappings determines the quality of a scaled image. Algorithms that produce higher-quality scaled images tend to require more processing time. In the preceding list, InterpolationModeNearestNeighbor is the lowest-quality mode and InterpolationModeHighQualityBicubic is the highest-quality mode.  To set the interpolation mode, pass one of the members of the InterpolationMode enumeration to the SetInterpolationMode method of a Graphics object.  The following example draws an image and then shrinks the image with three different interpolation modes:  Show Example  Image image(L"GrapeBunch.bmp"); UINT width = image.GetWidth(); UINT height = image.GetHeight(); // Draw the image with no shrinking or stretching. graphics.DrawImage(    &image,    Rect(10, 10, width, height),  // destination rectangle      0, 0,        // upper-left corner of source rectangle    width,       // width of source rectangle    height,      // height of source rectangle    UnitPixel); // Shrink the image using low-quality interpolation.  graphics.SetInterpolationMode(InterpolationModeNearestNeighbor); graphics.DrawImage(    &image,    Rect(10, 250, 0.6*width, 0.6*height),  // destination rectangle     0, 0,        // upper-left corner of source rectangle    width,       // width of source rectangle    height,      // height of source rectangle    UnitPixel); // Shrink the image using medium-quality interpolation. graphics.SetInterpolationMode(InterpolationModeHighQualityBilinear); graphics.DrawImage(    &image,    Rect(150, 250, 0.6 * width, 0.6 * height),  // destination rectangle     0, 0,        // upper-left corner of source rectangle    width,       // width of source rectangle    height,      // height of source rectangle    UnitPixel); // Shrink the image using high-quality interpolation. graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic); graphics.DrawImage(    &image,    Rect(290, 250, 0.6 * width, 0.6 * height),  // destination rectangle     0, 0,        // upper-left corner of source rectangle    width,       // width of source rectangle    height,      // height of source rectangle    UnitPixel); The following illustration shows the original image and the three smaller images.     --------------------------------------------------------------------------------

user: user-5
content: 引用 5 楼 xiaohuh421 的回复:放大最重要的就是插值算法, 有线性插值,也有非线性插值, 当然, 非线性插值的放大效果会好一些.  ++

user: user-6
content: 放大最重要的就是插值算法, 有线性插值,也有非线性插值, 当然, 非线性插值的放大效果会好一些.

user: user-7
content: 同意5楼的做法，7楼的朋友，你的代码到是简单了，但是会出现断层现象。举个例子：1，2，放大之后应该是1，1.5，2.而不该是1,1,2，或者1,2,2。

user: user-8
content: 最简单的：  void Zoom(unchar* pSrc[128], uchar* pDst[300]) {  for(int i=0;j<300;j++)  for(int j=0;i<300;i++) {  pDst[i][j]=pSrc[i*128/300][j*128/300]; } }

user: user-9
content: 你投的算法工程师么？我数字信号处理都忘了

user: user-10
content: 在纸上画画就清楚了。  引用 2 楼 jasminesst 的回复:[quote=引用 1 楼 turingo 的回复:] 最简单的做法就是有些像素点复制为2x2个点，而有些像素点复制为3x3个点，直到补满300x300个点。  [quote=引用 楼主 jasminesst 的回复:] C语言实现128*128到300*300的图像放大 函数定义为void Zoom(unchar* pSrc[128], uchar* pDst[300]);  求各位大神~！[/quote]  请您详解之，谢谢！！！[/quote]

user: user-0
content: 引用 1 楼 turingo 的回复:最简单的做法就是有些像素点复制为2x2个点，而有些像素点复制为3x3个点，直到补满300x300个点。  [quote=引用 楼主 jasminesst 的回复:] C语言实现128*128到300*300的图像放大 函数定义为void Zoom(unchar* pSrc[128], uchar* pDst[300]);  求各位大神~！[/quote]  请您详解之，谢谢！！！

user: user-10
content: 最简单的做法就是有些像素点复制为2x2个点，而有些像素点复制为3x3个点，直到补满300x300个点。  引用 楼主 jasminesst 的回复:C语言实现128*128到300*300的图像放大 函数定义为void Zoom(unchar* pSrc[128], uchar* pDst[300]);  求各位大神~！