在c中按x角旋转图像
我将图像旋转x(45度)角,但旋转后的图像中有一些黑点 如何避免这些黑点 我使用的逻辑如下在c中按x角旋转图像,c,image,rotation,C,Image,Rotation,我将图像旋转x(45度)角,但旋转后的图像中有一些黑点 如何避免这些黑点 我使用的逻辑如下 double sinx = sin((M_PI/4)*(180.0/M_PI)); //45 degrees double cosx = cos((M_PI/4)*(180.0/M_PI)); xCenter = height/2; // Rotate image by its center. yCenter = width/2; for(x=0; x<height; x++)
double sinx = sin((M_PI/4)*(180.0/M_PI)); //45 degrees
double cosx = cos((M_PI/4)*(180.0/M_PI));
xCenter = height/2; // Rotate image by its center.
yCenter = width/2;
for(x=0; x<height; x++) {
for(y=0; y<width; y++) {
xt = x-xCenter; yt=y-yCenter;
xRotate = (int) round( ((xt*cosx)-(yt*sinx)) + xCenter );
yRotate = (int) round( ((yt*cosx)+(xt*sinx)) + yCenter );
if( (x >= 0) && (x < height) && (y >= 0) && (y < width) ) {
rotatedImage[xRotate][yRotate] = inputImage[x][y];
}
}
}
double sinx=sin((μPI/4)*(180.0/μPI))//45度
双余弦=余弦((μPI/4)*(180.0/μPI));
xCenter=高度/2;//按图像中心旋转图像。
中心=宽度/2;
对于(x=0;x=0)和(y
与其在未旋转图像的像素上循环,不如在旋转图像上循环。这意味着您不会因为将旋转坐标舍入到int
而错过像素,而不是在未旋转图像的像素上循环,而是在旋转图像上循环。这意味着您不会因为将旋转坐标舍入到int
sin((M_PI/4)*(180.0/M_PI)),而错过像素代码>不是“45度”的正弦值。它是45弧度的正弦。关于双余弦相同
建议double sinx=sin(45.0/180.0*M_-PI)代码>
还考虑<代码> LCOND()/VS> vs>代码>(int)循环()/<代码> <
此外,
xRotate,yRotate
的范围比height,width
的范围大大约sqrt(2)倍。从double
转换时,代码应注意整数溢出
重复回答并评论
下面使用类似OP的代码,但由于代码是从inputImage
映射的,所以使用-45旋转
#defined SIND(a) (sin((a)/180.0 * M_PI)
#defined COSD(a) (cos((a)/180.0 * M_PI)
double sinx = SIND(-45); // -degrees
double cosx = COSD(-45);
xCenter = height; // Rotate image by its center.
yCenter = width;
for(x=0; x<height; x++) {
xt = x - xCenter;
double xt_cosx = xt*cosx;
double xt_sinx = xt*sinx;
for(y=0; y<width; y++) {
yt = y - yCenter;
long xRotate = lround(xt_cosx - (yt*sinx)) + xCenter;
long yRotate = lround((yt*cosx) + xt_sinx) + yCenter;
if( (xRotate >= 0) && (xRotate < height) && (yRotate >= 0) && (yRotate < width) ) {
rotatedImage[x][y] = inputImage[xRotate][yRotate];
} else {
rotatedImage[x][y] = Default_Pixel;
}
}
}
#定义的SIND(a)(sin((a)/180.0*M#PI)
#定义的COSD(a)(cos((a)/180.0*M_-PI)
双sinx=SIND(-45);//-度
双余弦=余弦(-45);
xCenter=height;//按图像中心旋转图像。
中心=宽度;
对于(x=0;x=0)和(Y酸盐<宽度)){
rotateImage[x][y]=输入图像[xRotate][yRotate];
}否则{
旋转图像[x][y]=默认的_像素;
}
}
}
sin((μPI/4)*(180.0/μPI));
不是“45度”的正弦。它是45弧度的正弦。关于双余弦也是如此
建议double sinx=sin(45.0/180.0*M_PI);
还考虑<代码> LCOND()/VS> vs>代码>(int)循环()/<代码> < /P>
此外,
xRotate,yRotate
的范围比高度,宽度的范围多出大约sqrt(2)倍。从双精度
转换时,代码应注意整数溢出
重复回答并评论
下面使用类似OP的代码,但由于代码是从inputImage
映射的,所以使用-45旋转
#defined SIND(a) (sin((a)/180.0 * M_PI)
#defined COSD(a) (cos((a)/180.0 * M_PI)
double sinx = SIND(-45); // -degrees
double cosx = COSD(-45);
xCenter = height; // Rotate image by its center.
yCenter = width;
for(x=0; x<height; x++) {
xt = x - xCenter;
double xt_cosx = xt*cosx;
double xt_sinx = xt*sinx;
for(y=0; y<width; y++) {
yt = y - yCenter;
long xRotate = lround(xt_cosx - (yt*sinx)) + xCenter;
long yRotate = lround((yt*cosx) + xt_sinx) + yCenter;
if( (xRotate >= 0) && (xRotate < height) && (yRotate >= 0) && (yRotate < width) ) {
rotatedImage[x][y] = inputImage[xRotate][yRotate];
} else {
rotatedImage[x][y] = Default_Pixel;
}
}
}
#定义的SIND(a)(sin((a)/180.0*M#PI)
#定义的COSD(a)(cos((a)/180.0*M_-PI)
双sinx=SIND(-45);//-度
双余弦=余弦(-45);
xCenter=height;//按图像中心旋转图像。
中心=宽度;
对于(x=0;x=0)和(Y酸盐<宽度)){
rotateImage[x][y]=输入图像[xRotate][yRotate];
}否则{
旋转图像[x][y]=默认的_像素;
}
}
}
从原始图像X中的每个像素计算旋转图像X'中的位置,但应反过来计算:对于旋转图像X'中的每个像素,计算原始图像中的相应位置,并复制它(如果存在),即如果它不在原始图像外。这样,每个像素都在X'cov中你可以根据原始图像X中的每个像素计算旋转图像X'中的位置,但你应该反过来计算:对于旋转图像X'中的每个像素,计算原始图像中的相应位置,并复制它(如果存在),也就是说,如果它不在原始图像之外。这样,你就可以将每个像素都包含在X'封面中预计起飞时间。