procedure ConvertToBoolMask(reference: TColor32; tolerance: integer; colorFunc: TCompareFunction; maskBg: TColor32 = clWhite32; maskFg: TColor32 = clBlack32);
Converts a colored image into a 2 colored mask image (default black on white).
The 'reference' color is compared with each pixel in the image using the supplied 'colorFunc' function. Matching pixels will be colored with 'maskFg' (default = black) and non-matching pixels will be colored 'maskBg' (default = white). The meaning of 'tolerance' will depend on the function. For example, using the CompareRGB function, pixels that deviate no more that 'tolerance' from the reference color in each of the three color channels will be considered a match.
uses Img32, Img32.Fmt.PNG, Img32.Vector, Img32.Extra; ... var img: TImage32; paths: TPathsD; begin img := TImage32.Create; img.LoadFromFile('beetle.png'); //create a mask from pure black pixels, making black //pixels maroon while everything else becomes clear img.ConvertToBoolMask(clBlack32, 0, CompareRGB, clNone32, clMaroon32); img.SaveToFile('.\beetle2.png'); //and to vectorize the result paths := Vectorize(img, $FF000000, CompareAlpha, $0); paths := RamerDouglasPeucker(paths, 2); paths := SmoothToBezier(paths, true, 3, 2); paths := FlattenCBezier(paths); img.Clear; DrawPolygon(img, paths, frEvenOdd, clMaroon32); img.SaveToFile('.\beetle3.png'); img.Free;
ConvertToAlphaMask, SetRGB, GetBoolMask
Copyright ©2010-2023 Angus Johnson - Image32 4.8 - Help file built on 17 Jan 2025