gpt4 book ai didi

裁剪图像数组

转载 作者:行者123 更新时间:2023-11-30 17:36:49 25 4
gpt4 key购买 nike

我尝试通过创建用户分配的变量然后从图像的宽度和高度的最大值中减去该变量来裁剪图像。 问题是,当我对结果进行减法运算符而不是 HEIGHT - input = number 时,我得到一个奇怪的数字,类似于 -180000...

这是我的代码

#define _CRT_SECURE_NO_DEPRECATE 1
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
//#include "functions.h"
#define _CRT_SECURE_NO_WARNINGS 1
#define HEIGHT 128
#define WIDTH 256
int image02[HEIGHT][WIDTH][3];
int image03[HEIGHT][WIDTH][3];
int x, y;

FILE*RED = NULL;
FILE*BLUE = NULL;
FILE*GREEN = NULL;
FILE*REDRead = NULL;
FILE*BLUERead = NULL;
FILE*GREENRead = NULL;
FILE*Write1 = NULL;
char cropans [30];
char red [30];
char green [30];
char blue [30];
char ppm [30];
char rotans [30];
int xcrop;
int ycrop;
int newheight;
int newwidth;

void main()
{

printf("Type in filenames of the image files, including extensions\nThe program will exit if it cannot read any files\n"); //this is the UI//
printf("Red channel data: ");
scanf("%s", &red);
REDRead = fopen(red, "r");
if (REDRead == NULL)
{
printf("\nCannot read red image data\n");
exit(0);
}
printf("Green channel data: ");
scanf("%s", &green);
GREENRead = fopen(green, "r");
if (GREENRead == NULL)
{
printf("\nCannot read green image data\n");
exit(0);
}
printf("Blue channel data: ");
scanf("%s", &blue);
BLUERead = fopen(blue, "r");
if (BLUERead == NULL)
{
printf("\nCannot read blue image data\n");
exit(0);
}


printf("\nNow type in the name of the file you want to create, with extension:\n");
scanf("%s", &ppm);
printf("\nWould you like to rotate a channel, or create an image without rotating any channels?(y/n)\n");
scanf("%s", &rotans);
printf("\nWould you like to crop the image? (y/n)");
scanf("%s", &cropans);
if (strcmp( cropans, "y") == 0)
{
printf("\ntype number of pixels to crop from x axis\n");
scanf("%s", &xcrop);
printf("\ntype number of pixels to crop from y axis\n");
scanf("%s", &ycrop);
}
else if(strcmp( cropans, "n") == 0);
{
printf("hi");
}
printf("got input correctly\n");


//Zeroing the seperate arrays//
for (y = 0; y<HEIGHT; y++)
{
for (x = 0; x<WIDTH; x++)
{
image02[y][x][0] = 0;
image02[y][x][1] = 0;
image02[y][x][2] = 0;
}
}


for (y = 0; y<HEIGHT; y++)
{
for (x = 0; x<WIDTH; x++)
{
image03[y][x][0] = 0;
image03[y][x][1] = 0;
image03[y][x][2] = 0;
}
}

{
int newwidth = (WIDTH - xcrop);
int newheight = (HEIGHT - ycrop);
}
//printing to file part//
//no rotation//

if(strcmp( rotans, "n") == 0)
{
for (y = 0; y<HEIGHT; y++)
{
for (x = 0; x<WIDTH; x++)
{
fscanf(REDRead,"%d", &image03[y][x][0]);
fscanf(GREENRead, "%d",&image03[y][x][1]);
fscanf(BLUERead,"%d", &image03[y][x][2]);
}
}

Write1 = fopen(ppm, "w");
printf("got here 1");
fprintf(Write1,"P3\n %d %d \n 255\n", WIDTH, HEIGHT);
for (y = 0; y<(HEIGHT); y++)
{
for (x = 0; x<(WIDTH); x++)
{
fprintf(Write1,"%d %d %d ", image03[y][x][0], image03[y][x][1], image03[y][x][2]);
}
}
printf("got here 1");
}

else if (strcmp( rotans, "y") == 0)
{
for (y = 0; y<HEIGHT; y++)
{
for (x = 0; x<WIDTH; x++)
{
fscanf(REDRead,"%d", &image02[y][x][0]);
fscanf(BLUERead,"%d", &image02[y][x][2]);
}
}

for (y = HEIGHT; y>0; y--)
{
for (x = WIDTH; x>0; x--)
{
fscanf(GREENRead,"%d", &image02[y][x][1]);
}
}

Write1 = fopen(ppm, "w");
printf("got here 1");
fprintf(Write1,"P3\n %d %d \n 255\n", WIDTH, HEIGHT);
for (y = 0; y<HEIGHT; y++)
{
for (x = 0; x<WIDTH; x++)
{
fprintf(Write1,"%d %d %d ", image02[y][x][0], image02[y + 11][x + 11][1], image02[y][x][2]);
}
}
printf("got here 1");
}

}

我对此很困惑,任何帮助将不胜感激。 :)

最佳答案

您分配给新创建的 newheightnewwidth,它们是在您声明/分配它们的 block 中创建的。因为当该 block 结束时它们就会消失,所以您只剩下原始版本,而这些版本从未被分配给!

关于裁剪图像数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22566599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com