【发布时间】:2017-09-28 02:08:59
【问题描述】:
我有一些 C 代码示例。我需要进行直方图均衡。但是,我需要一步一步地向前。我被困在第一步。第一步是将文件从RGB转换为YCbCr。所以,我将与您分享代码。我拥有的所有代码都不适合这些区域。另外,我添加了一张显示我失败的图片。我想知道我错在哪里。我希望有人能给我指点光明。错误消息说“在预期浮点值的地方使用了指针值”。这条消息是什么意思?
`
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<string.h>
#include <fcntl.h>
#include <malloc.h>
#include <math.h>
#define PI 3.1415926535897932384626433832795
struct ppm_header
{
char pgmtype1;
char pgmtype2;
int pwidth;
int pheight;
int pmax;
};
struct ppm_file
{
struct ppm_header *pheader;
unsigned char *rdata,*gdata,*bdata;
};
// The codes that I've begin from here.
/*struct RGB // In fact, this structer is not a comment. I changed it.
{
unsigned char R;
unsigned char G;
unsigned char B;
};*/
struct YCbCr
{
float Y;
float Cb;
float Cr;
};
struct YCbCr RGBToYCbCr(struct ppm_file rgb) {
float fr = (float)rgb.rdata / 255;
float fg = (float)rgb.gdata / 255;
float fb = (float)rgb.bdata / 255;
struct YCbCr ycbcr;
ycbcr.Y = (float)(0.2989 * fr + 0.5866 * fg + 0.1145 * fb);
ycbcr.Cb = (float)(-0.1687 * fr - 0.3313 * fg + 0.5000 * fb);
ycbcr.Cr = (float)(0.5000 * fr - 0.4184 * fg - 0.0816 * fb);
return ycbcr;
}
// The codes that I added end here.
void get_image_data(char *filename,struct ppm_file *image);
void write_image(char *filename,struct ppm_file *image);
// I do not have the enough space for the get_image_data and the write_image functions implementation.
// If I will a solution for the space, I'll add the functions.
main()
{
struct ppm_file resim;
get_image_data("mandrill1.ppm",&resim);
printf("pgmtype...=%c%c\n",resim.pheader->pgmtype1,resim.pheader->pgmtype2);
printf("width...=%d\n",resim.pheader->pwidth);
printf("height...=%d\n",resim.pheader->pheight);
printf("max gray level...=%d\n",resim.pheader->pmax);
write_image("pnr.ppm",&resim);
return 0;
}
`
【问题讨论】:
-
@Piglet 你可以通过这篇文章看到我的挣扎。
-
@NominalAnimal 你可以通过这篇文章看到我的挣扎。
-
看到这比你糟糕的上一篇文章要好得多。离How to Ask 还很远,但你走在了一个好路上。错误信息告诉你一切。您正在使用编译器期望浮点数的指针。它甚至告诉你在哪一行。您不能将 unsigned char 指针转换为浮点数。请做一个c教程
-
您在 2 天前问了很多相同的问题。如果已关闭,请勿重新发布问题!编辑它,解决 cmets 给出的问题和关闭原因并要求重新打开!
标签: c image-processing histogram rgb ppm