能给出一个图象去蓝处理的例子或资料吗?

guanxuegong 2000-06-25 05:47:00
我对算法研究甚少,但最近工作中遇到了一个问题,需对扫描后的图象进行去污处理后存入数据库。图象是bmp格式的。请各位不惜赐教,谢谢!
...全文
196 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
michaelh 2001-01-28
  • 打赏
  • 举报
回复
sorry, I missed something:
#define IMGWIDTH 640 // please define the max size of the image!
#define IMGHEIGHT 480
void BMPDelBlue(char *inFileName,char* outFileName)
{
FILE *infile,*outfile;
BYTE Buff[IMGWIDTH*IMGHEIGHT*3]; // or alloc memory for Buff
BYTE Head[54];
int i,j,p;
short ImgWidth,ImgHeight;
BYTE bt1,bt2,bt3;
BYTE *stuff;

infile=fopen(inFileName,"rb");
if(infile==NULL)
printf("Open bitmap file failed!");
outfile=fopen(outFileName,"wb");
if(outfile==NULL)
printf("Open bitmap file failed!");

fread(Head,1,54,infile); // 24bit bitmap only!
ImgWidth =*(Head+18)+(*(Head+19))*256;
ImgHeight=*(Head+22)+(*(Head+23))*256;
p=(ImgWidth*3)%4;

fwrite(Head,1,54,outfile);

fseek(infile,54,SEEK_SET);
for(i=0;i<ImgHeight;i++)
{
for(j=0;j<ImgWidth;j++)
{
fread((BYTE *)&bt1,1,1,infile); // Blue
fread((BYTE *)&bt2,1,1,infile); // Green
fread((BYTE *)&bt3,1,1,infile); // Red

fwrite(0x00,1,1,outfile);
fwrite(&bt2,1,1,outfile);
fwrite(&bt3,1,1,outfile);
}
if(p!=0)
{
fread(stuff,1,(4-p),infile);
fwrite(stuff,1,(4-p),outfile);
}
}
fclose(infile);
fclose(outfile);
}

michaelh 2001-01-28
  • 打赏
  • 举报
回复
very simple!please look below:

void BMPDelBlue(char *inFileName,char* outFileName)
{
FILE *infile;
BYTE Buff[IMGWIDTH*IMGHEIGHT*3];
BYTE Head[54];
int i,j,p;
short ImgWidth,ImgHeight;
BYTE bt1,bt2,bt3;
BYTE *stuff;

infile=fopen(inFileName,"rb");
if(infile==NULL)
printf("Open bitmap file failed!");
outfile=fopen(outFileName,"wb");
if(outfile==NULL)
printf("Open bitmap file failed!");

fread(Head,1,54,infile); // 24bit bitmap only!
fwrite(Head,1,54,outfile);

fseek(infile,54,SEEK_SET);
for(i=0;i<ImgHeight;i++)
{
for(j=0;j<ImgWidth;j++)
{
fread((BYTE *)&bt1,1,1,infile); // Blue
fread((BYTE *)&bt2,1,1,infile); // Green
fread((BYTE *)&bt3,1,1,infile); // Red

fwrite(0x00,1,1,outfile);
fwrite(&bt2,1,1,outfile);
fwrite(&bt3,1,1,outfile);
}
if(p!=0)
{
fread(stuff,1,(4-p),infile);
fwrite(stuff,1,(4-p),outfile);
}
}
fclose(infile);
fclose(outfile);
}
wangminfu 2000-06-30
  • 打赏
  • 举报
回复
原理很简单:
1。一幅图可以用一个二维数组表示,数组元素就是某点的颜色;
2。颜色可以分解为R G B 三色;
3。循环处理所有点,用 + - * / and not or xor 求补等算法实现颜色变换;
4。如果必要,可以按照BMP的格式存储处理后的图片数据到磁盘文件.


去兰例程:
image1.picture.loadfromfile(yourBMP);
deBlueButton.onclick:
deBlue(degree:real); //degree是0--1间的实数,表示要去除多少兰色;
procedure deBlue(degree:real);
var
deb,i,j:integer;
begin
deb:=RGB(255,255,degree*255);
for i:=0 to image1.picture.width-1
for j:=0 to image1.picture.height-1 do
image1.picture.canvas.pexils[i,j]:=
image1.picture.canvas.pexils[i,j] and deb;
end;{deBlue}





33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧