2006. december 18., hétfő
Select an area with similar color
Problem/Question/Abstract:
In my application, I want to select an area with similar color. This tool should work like Photoshop's Magic Wizard Tool. But how can I determine if 2 pixels are similar if they don't have the same RGB value?
Answer:
A "quick" solution is to compare the RGB components separately - if none of the red, green or blue components differ by more than the threshold amount then you can assume that the colours are "similar". There are more optically correct methods of comparing colours but this might be good enough for your purposes.
function ColoursAreSimilar(Col1, Col2: TRGBQuad; Threshold: Integer): Boolean;
begin
Result := (Abs(Col1.rgbRed - Col2.rgbRed) <= Threshold) and
(Abs(Col1.rgbGreen - Col2.rgbGreen) <= Threshold) and
(Abs(Col1.rgbBlue - Col2.rgbBlue) <= Threshold);
end;
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése