如何根据色彩值来选择区域,像PS那样的功能? ( 积分: 300 )

  • 主题发起人 主题发起人 wqhatnet
  • 开始时间 开始时间
W

wqhatnet

Unregistered / Unconfirmed
GUEST, unregistred user!
有谁做过这样的程序,分享一下
谢谢
图像是黑白的
 
设置一个阀值在图象中划分区域。
 
楼上的老兄
详细一点好不?
 
var
bkBmp: TBitmap;
bkPix: PRGBTriple;
bmpPix: PRGBTriple;
x, y: integer;
begin
bkbmp:=TBitMap.create;
try
bkBmp.Height:=bmp.Height;
bkbmp.Width:=bmp.Width;
bmp.PixelFormat:=pf24Bit;
bkBmp.PixelFormat:=pf24bit;
bkbmp.Canvas.CopyRect(Rect(0,0,bmp.Width,bmp.Height),SCanvas,Rect(Ax,Ay,Ax+bmp.Width,Ay+bmp.Height));
for y:=0 to bmp.Height-1 do
begin
bkPix:=bkBmp.ScanLine[y];
bmppix:=bmp.ScanLine[y];
for x:=0 to bmp.Width-1 do
begin
[blue] if Rgb(bmpPix^.rgbtRed, bmpPix^.rgbtGreen, bmpPix^.rgbtBlue)<>[/blue]TransColor then
begin
bkPix^.rgbtRed:=(bkPix^.rgbtRed*(255-Bvalue)+bmpPix^.rgbtRed * Bvalue) div 255;
bkPix^.rgbtGreen:=(bkPix^.rgbtGreen*(255-Bvalue)+bmpPix^.rgbtGreen * Bvalue) div 255;
bkPix^.rgbtBlue:=(bkPix^.rgbtBlue*(255-Bvalue)+bmpPix^.rgbtBlue * Bvalue) div 255;
end;
Inc(bkPix);
inc(bmpPix);
end;
end;
Scanvas.Draw(Ax,Ay,bkBmp);
finally
bkbmp.free;
end;
end;
 
楼上的代码通不过啊
 
我写过一个连通区域的代码能实现你要的效果.简单的说一下原理吧,先把BMP图象转化成一个二维数组.转化的方法自己上网查下.不困难.查连通区域的函数先定义一个足够大的堆栈用于存放满足条件的点的信息.先从point(0,0)的点查起,用过的点把他的used(x,y):=true(数组);满足条件的点压入堆栈然后进入查连通区域函数把满足条件的点的上下左右的点都查一遍,直到周围所有点都不满足条件跳出函数.把点的个数记录下来.就是你要的连通区域.
 
我写过一个连通区域的代码能实现你要的效果.
 
wqhnet@hotmail.com
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
657
import
I
I
回复
0
查看
768
import
I
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部