gpt4 book ai didi

c - 用 C 将图像写入文本/原始文件

转载 作者:太空宇宙 更新时间:2023-11-04 04:36:39 24 4
gpt4 key购买 nike

#include <stdio.h>
#include <stdlib.h>

int main()
{
unsigned char **T;
int H[256];
int I[256][256];
int i,j,a,aux[256];
FILE *fp=fopen("Collines400300.ima","rb");
FILE *fp1=fopen("image4.raw","wb");
int height = 300;
int width = 400;

T=(unsigned char**)malloc(height*sizeof(unsigned char*));
for(i=0;i<height;i++)
{
if (feof(fp))
{
//handle error... could just malloc and memset to zero's
break;
}
T[i]=(unsigned char*)malloc(width*sizeof(unsigned char*));
fread(T[i],1,400,fp);
}
for(i=0;i<256;i++)
H[i]=0;

//filling up the histogram
for(i=0;i<300;i++)
{
for(j=0;j<400;j++)
H[T[i][j]]++;
}
//printing out the values of each gray scale value in the histogram
for(i=0;i<256;i++)
printf("%d ",H[i]);

//converting the values from a scale of 3000 to a scaale of 256 to fit in our new image
for(i=0;i<256;i++)
{
a=(H[i]+6)/12;
aux[i]=a;
}
//initialising the 2D image to white
for(i=0;i<256;i++)
{
for(j=0;j<256;j++)
I[i][j]=255;
}
//the loop to make the graph for my histogram. This is where the problem is.
for(i=0;i<256;i++)
{
for(j=254;j>254-aux[i];j--)
{
I[j][i]=0;
fwrite(I[i],1,aux[i],fp1);
}
}
fclose(fp);
fclose(fp1);



return 0;


}

给定一张图像,我应该制作图像的直方图,我做到了。然后在二维图像中制作直方图的图形并将其写入文件。我没有得到我想要的图表,而是一张非常模糊的图像,没有任何意义。感谢您事先提供的任何帮助。

最佳答案

我[j][i]=0; fwrite(I[i],1,aux[i],fp1); 您是要将 column 行写入此处的文件吗?它不是那样工作的。您正在修改内存中 (column number i) 行号 j 中的元素,然后写入行号 i归档。

关于c - 用 C 将图像写入文本/原始文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30013302/

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