看不懂? 写一个循环,每个点的颜色值用周围连自己一共9个点的值乘以上面那个数组里面的权重然后加起来,会把?给你个示范吧: a:array [-1..1,-1..1] of real= ((0,-1/5,0), (-1/5,1,1/5), (0,1/5,0)); sum:real; ... for x:=x0 to x1 do for y:=y0 to y1 do begin sum:=0; for i:=-1 to 1 do for j:=-1 to 1 do sum:=pixels[x+i,y+j]*a[i,j]; newPixels[x,y]=sum; end; 这样总明白了吧?这里pixels数组只是做个示范,实际你抄的时候需要red,blue,green分开处理。这个你再看不懂,我就不值得帮你了。
KISS,我来救你吧,不过嘿嘿,别忘给分啊 :-P //求出该点区域的像素平均值,返回平均值。 function TForm1.AverageP(HD:THandle;CPX,CPY:Integer):Integer; var ResultP:Real; I,J:Integer; begin ResultP:=0; for I:=CPX-1 to CPX+1 do for J:=CPY-1 to CPY+1 do ResultP:=ResultP+(GetPixel(HD,I,J)/9); Result:=Round(ResultP); end;//填充。 procedure TForm1.BitBtn1Click(Sender: TObject); var SourceHD:THandle; I,J,CurrentPixel:Integer; begin SourceHD:=Image1.Canvas.Handle;//假设Image1内有图片了。 CurrentPixel:=0; for I:=12 to 100 do //填充区域(12,100)--(12,100) for J:=12 to 100 do begin if (I Mod 3=0) or (J Mod 3=0) then CurrentPixel:=AverageP(SourceHD,I,J); SetPixel(SourceHD,I,J,CurrentPixel); end; Image1.Refresh; end;不过这个没有分离RGB,要分离再说吧 : ) 加个函数就成。
计算源图像像素的像素值与边缘上相邻像素的像素值的平均值,将该值作为该区域的像素值。
浮雕:
G:处理后的像素值
F:源图像像素
r,g,b:颜色分量
r1,g1,b1:源图像像素的RGB分量
r2,g2,b2:相邻像素的RGB分量 r:=r1-r2+128
g:=g1-g2+128
b:=b1-b2+128
G(x,y)=F(x,y)-F(x-1,y)+Const // 常数
[email protected]
^^^^^^^^^^^^^^
我很久不做delphi了,不大熟悉了。
在java里面建一个什么什么filter(记不得叫filter了),代进去一个数组:
模糊化是
{1/9,1/9,1/9,
1/9,1/9,1/9,
1/9,1/9,1/9],
意思是每个点取周围八个方向还有自己一共九个点的颜色进行平均;
清晰化是
[0,-1/5,0,
-1/5,1,1/5,
0,1/5,0](大致如此,你可以改具体的数值),意思是每个点取周围这些点的颜色值乘以权重求和,只要保证权重加起来是1就可以了。
你用delphi,可以自己写程序做这样的运算,也很简单的。
写一个循环,每个点的颜色值用周围连自己一共9个点的值乘以上面那个数组里面的权重然后加起来,会把?给你个示范吧:
a:array [-1..1,-1..1] of real=
((0,-1/5,0),
(-1/5,1,1/5),
(0,1/5,0));
sum:real;
...
for x:=x0 to x1 do
for y:=y0 to y1 do begin
sum:=0;
for i:=-1 to 1 do
for j:=-1 to 1 do
sum:=pixels[x+i,y+j]*a[i,j];
newPixels[x,y]=sum;
end;
这样总明白了吧?这里pixels数组只是做个示范,实际你抄的时候需要red,blue,green分开处理。这个你再看不懂,我就不值得帮你了。
//求出该点区域的像素平均值,返回平均值。
function TForm1.AverageP(HD:THandle;CPX,CPY:Integer):Integer;
var
ResultP:Real;
I,J:Integer;
begin
ResultP:=0;
for I:=CPX-1 to CPX+1 do
for J:=CPY-1 to CPY+1 do
ResultP:=ResultP+(GetPixel(HD,I,J)/9);
Result:=Round(ResultP);
end;//填充。
procedure TForm1.BitBtn1Click(Sender: TObject);
var
SourceHD:THandle;
I,J,CurrentPixel:Integer;
begin
SourceHD:=Image1.Canvas.Handle;//假设Image1内有图片了。
CurrentPixel:=0;
for I:=12 to 100 do //填充区域(12,100)--(12,100)
for J:=12 to 100 do
begin
if (I Mod 3=0) or (J Mod 3=0) then
CurrentPixel:=AverageP(SourceHD,I,J);
SetPixel(SourceHD,I,J,CurrentPixel);
end;
Image1.Refresh;
end;不过这个没有分离RGB,要分离再说吧 : ) 加个函数就成。
马赛克简单的,另开一个canvas作为缓冲区,用小尺寸draw一下你的image,然后保存下来,再重新用原来尺寸draw一下,就搞定,不需要涉及具体的点
可以打开 Delphi 5 的 Windows SDK 帮助,然后查找
COLORADJUSTMENT
调整亮度:需要同时增加或减少像素点的R,G,B值,增加或减少的R,G,B值应该相等!比如均增加
或减少10;
调整对比度:首先设定一个阀值,通常是128;然后判断像素点的R,G,B值,凡是大于128的,
增加一个值,小于128的,减少一个值!
简单的调节,试试SetPalette API 吧
我找回以前的程序,试了一下,仅仅对于有调色板的图像,例如256色图像
才能用Window API处理。若对于16位或24位真彩色图像只能自己处理。
建议先识别图像的颜色深度,然后再处理。
不要使用TBitmap的Pixel属性,应使用ScanLine。若不是使用TBitmap,
也是类似,要直接获得象素的内存指针来操作。
处理方法就如【卷起千堆雪tyn】所说的那样。
==============================================================我照资料写了代码,但是怎么也不能实现
procedure TForm1.Button1Click(Sender: TObject);
var
x,y,i: integer;
BitMap : TBitMap;
ptr : PByteArray;
begin
BitMap := TBitMap.Create;
try
BitMap.LoadFromFile('lanmannt.bmp');
BitMap.PixelFormat := pf24bit;
for y := 0 to BitMap.Height - 1 do begin
ptr := BitMap.ScanLine[y];
for x := 0 to ((BitMap.Width * 3) - 1) do begin
ptr[x] := (ptr[x] - 1);
ptr[x+1] := (ptr[x] - 1);
ptr[x+2] := (ptr[x] - 1);
end;
end;
Image1.Canvas.Draw(0,0,BitMap);
Application.ProcessMessages;
finally
BitMap.free;
end;
end;
^^^^^^^^^^^^^^^^^
没有人能说出浮雕化的算法,我也说不出,
你有本事去翻photoshop的动态连接库,呵呵从上千个函数的数字代码里面调用吧。哈哈。
居然来问这种问题,
回去好好学学图像学,你就不会问出如此痴呆的问题了。
void __fastcall Tfrm_photo_modi::SpeedButton4Click(TObject *Sender)
{
int flt[9];
flt[0]=5;flt[1]=5;flt[2]=5;
flt[3]=5;flt[4]=60;flt[5]=5;
flt[6]=5;flt[7]=5;flt[8]=5;
DoFilter(flt,100);
}void Tfrm_photo_modi::DoFilter(int * flt, int Div)
{
int XX[3];
BYTE *ptr,*ptru,*ptrd,*ptr1;
Graphics::TBitmap *Bitmap=new Graphics::TBitmap();
Graphics::TBitmap *tmpBitmap=new Graphics::TBitmap();
Bitmap->Assign((TPersistent*)Image1->Picture->Graphic);
Bitmap->PixelFormat=pf24bit;
tmpBitmap->Assign((TPersistent*)Image1->Picture->Graphic);
tmpBitmap->PixelFormat=pf24bit;
for (int y = 1; y < tmpBitmap->Height-1; y++)
{
ptr=(BYTE *)Bitmap->ScanLine[y];
ptr1=(BYTE *)tmpBitmap->ScanLine[y];
ptru=(BYTE *)tmpBitmap->ScanLine[y-1];
ptrd=(BYTE *)tmpBitmap->ScanLine[y+1];
for (int x=3;x<(tmpBitmap->Width-1)*3;x+=3){
XX[0]=0;XX[1]=0;XX[2]=0;
for (int i=-1;i<=1;i++)
for (int j=0;j<3;j++)
XX[j]+=ptr1[x+3*i+j]*flt[4+i];
for (int i=-1;i<=1;i++)
for (int j=0;j<3;j++)
XX[j]+=ptru[x+3*i+j]*flt[1+i];
for (int i=-1;i<=1;i++)
for (int j=0;j<3;j++)
XX[j]+=ptrd[x+3*i+j]*flt[7+i];
for (int i=0;i<3;i++){
XX[i]=XX[i]/Div;
XX[i]=MAX(XX[i],0);
XX[i]=MIN(XX[i],255);
ptr[x+i]=XX[i];
}
}
}
Image1->Picture->Graphic=Bitmap;
delete tmpBitmap;
delete Bitmap;
就是每个点的颜色newColor[x,y]:=(color[x,y]-color[x-1,y])*a+b,这里a和b是参数,你试验一下慢慢调整。
这样总明白了吧?
我不用delphi,就不给你写了。