Finding pixels!

Please discuss general Delphi programming topics here.

Finding pixels!

Postby Sina » March 7th, 2007, 2:43 pm

Hi
I'm looking for some code which can help me get the location of a light in a black picture{ Sample picture is attached to this post}
In this picture you see 5 lights (it seems to be 3 :D!!!)
I want to get the location of these lights !
or at least one of them :D
Best Regards
Attachments
gggdgg.JPG
Sample picture!
gggdgg.JPG (7.15 KiB) Viewed 1319 times
User avatar
Sina
Junior Member
Junior Member
 
Posts: 32
Joined: August 29th, 2005, 8:33 am
Location: United States

Postby Johnny_Bit » March 7th, 2007, 6:57 pm

Divide and conquer using scan lines. Simply: divide pic to about 16 regions, count average lightness of every area. Then count which area has biggest lightness picks and that area is sure to have at least one light. After locating regions with lights create one big region containing found lights. Divide that region again to 16 smaller regions and repeat the procedure, then you'll have small region that has most probably every light in it. locating exactly where is the light: find highest peaks and there you have your light.

For this one you'll need HLS coulor palette instead of typical RGB. conversion is fairly simple and I can give you routines for that.
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am

Postby Sina » March 13th, 2007, 5:10 am

Please help me with dividing picture and about converting rgb to hls :D
regards
User avatar
Sina
Junior Member
Junior Member
 
Posts: 32
Joined: August 29th, 2005, 8:33 am
Location: United States

Postby Johnny_Bit » March 13th, 2007, 6:36 pm

Code: Select all
Procedure RGBToHLS(const R, G, B: Byte; var H: Integer; var L, S: Byte);

var

   Hue, Lightness, Saturation: Real;



   Procedure FloatRGBToHLS(const R,G,B: Real; var H,L,S: Real);

   {R, G, B, L, S are in [0,1]; H is in [0,360)}

   var

      Delta, Min, Max: Real;

   begin

      Max:=MaxValue([R, G, B]);

      Min:=MinValue([R, G, B]);

      L:=(Max+Min)/2.0;

      if Max=Min then

         begin

            S:=0.0;

            H:=NaN;

         end

      else

         begin

            Delta:=Max-Min;

            if L<=0.5 then

               S:=Delta/(Max+Min)

            else

               S:=Delta/(2.0-(Max+Min));

            if R=Max then

               H:=(60.0*(G-B))/Delta

            else

               if G=Max then

                  H:=120+(60.0*(B-R))/Delta

               else

                  H:=240+(60.0*(R-G))/Delta;

            if H<0 then

               H:=H+360.0;

         end;

   end;



begin

   FloatRGBToHLS(R/255, G/255, B/255, Hue, Lightness, Saturation);

   if IsNaN(Hue) then

      H:=iNan

   else

      H:=Round(Hue);

   L:=Round(Lightness*255);

   S:=Round(Saturation*255);

end;

Function IsiNan(Value: Integer): Boolean;

begin

   Result:=Value=iNaN;

end;

const

   iNAN=-1;


that's for sure...

Now... you know somethiong about scanlines? or bitmap copying? it's important, so before we dive in the code, let us see how you can handle this one.
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am


Return to Delphi Programming

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron