Announcement

Collapse
No announcement yet.

Counting dots in an image (birds, reindeer...)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Gösta H. Lovgren-2
    replied
    That person looks pretty small to click on so here it is again enlarged.

    ============================================
    "It's not the size of the dog in the fight,
    it's the size of the fight in the dog."
    Mark Twain (1835-1910)
    ============================================
    Attached Files

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Originally posted by Chris Holbrook View Post
    so how many people were on that beach, Gösta?
    Actually the people in that aerial view should be a lot easier to count than the swallows (above) as they are all the same size (nearly), say 2w x 8h px and (nearly) the same color so any block that size with the (range of) total color value of pixels would be considered a person. (see Beachfront_Person.jpg attached). What that picture does is allow a reasonable handcount to check against against any computer match algo (see attached Beachfront.jpg).
    How would you define sharpness?
    Pretty much anything that looks good to these old eyes.

    ==================================
    "There is one thing certain,
    namely,
    that we can have nothing certain;
    therefore it is not certain
    we can have nothing certain."
    Samuel Butler (1835-1903)
    ==================================
    Attached Files
    Last edited by Gösta H. Lovgren-2; 30 Dec 2008, 11:00 PM.

    Leave a comment:


  • Chris Holbrook
    replied
    Originally posted by Gösta H. Lovgren-2 View Post
    ...Lavalette...
    so how many people were on that beach, Gösta?

    Originally posted by Gösta H. Lovgren-2 View Post
    ...Sharper, imvho, than if they were 800x600 to start with.)
    How would you define sharpness?

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Originally posted by Chris Holbrook View Post
    I don't appear to have any storage format options with this camera. Next time I will use B&W mode straight from the camera, maybe lose less info that way.
    Or if possible take the picture at the highest camera resolution. That way there'll be a lot more information available in the same scene. For example had the swallow picture been 2000 x 1500 (low res by today's standards)instead of 640 x 480, then the number of birds could have been extracted much more accurately without much more work. (Using the blowup to examine pixel colors method)

    Not that I'm any kind of photographer or have any sophisticated equipment but when I take pics I always use the highest resolution. That way if I get a pic I want to print, using PBP it's easy to just clip out the relevant section (just the kids' heads maybe) and not lose any detail. Or use PBP (which has a host of format to save to) to compress it to the size wanted for web printing (say 800x600) and they stay *very* sharp (see www.SwedesDock.com/Lavallette for examples. Most of these original pics were much higher res - 2000x1500 or higher I think). Sharper, imvho, than if they were 800x600 to start with.)

    ==================================================
    "I am ready to meet my Maker.
    Whether my Maker is prepared for the great ordeal
    of meeting me is another matter."
    Sir Winston Churchill (1874-1965)
    ==================================================

    Leave a comment:


  • Chris Holbrook
    replied
    Originally posted by Paul Dixon View Post
    Second, the images are JPGs.
    I don't appear to have any storage format options with this camera. Next time I will use B&W mode straight from the camera, maybe lose less info that way.

    Leave a comment:


  • Chris Holbrook
    replied
    Originally posted by Gösta H. Lovgren-2 View Post
    ...Chris'll run off to Christies Ebay arm and sell it promissing a share to the rest of us "when he see's us."
    So whose dreams are we in now?

    Thinking again about the basic problem here with bird flocks. Had I been inside the flock (not as crazy as it sounds, as they were coming in to roost), it is likely that some birds would be close enough to take up many more pixels, which would lead to two problems, one, the algorithm would have to recognise these large blocks as birds, not aggregations of birds, two, these birds would obscure possibly many other birds. So as a useful technique maybe this sort of image analysis is better suited to a more 2-D subject, albeit still requiring high contrast. Bacterial plaque counting on Petri dishes, for example.

    Another application occurred to me yesterday as I approached the coast from a hill - counting white tops. I'm looking for a suitable observation point.

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    nd Chris will examine in meticulous detail and find what were passing for pixels were really relics of a late cubist phase of a Picasso fugue that has been painted over by Monet.

    Chris'll run off to Christies Ebay arm and sell it promissing a share to the rest of us "when he see's us."
    Because we are all enthrall watching Michael ducking quads and unions, we don't see Chris riding off into the matrix in a Don Wasson special

    Enough. One shouldn't type late at night with a head full Ambien, killing time till the sandman calls Mild stuff Ambien but still allows some mildly interesting hallucinacions

    Off to lala land now, if I don't keel over on the way first

    =====================================
    "Human history becomes more and more
    a race
    between education and catastrophe."
    H. G. Wells (1866-1946)
    =====================================

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Colour alone is never going to work, you need to look at the difference in colour between pixels in small areas of the image.
    Paul

    Having next to zero experience at this recognition stuff (zero before yesterday). I respectfully have to diagree . (For discussion purposes)

    What I would do in the geese example (sticking with Red (call it 10 for discussion puposes) (fdp) Any 10 (within a block) is a bird. In cases where red is mixed (a shared pixel call it color 5 fdp) then that color is a bird.

    Okay (thinking on the keyboard here) what about cases where where there are Reds (10's) other than geese (say flowers) then I would blow up the largest bird and count the most red pixels possible. The my algo would read:

    Code:
    For Next_Block = 1 to Some_Size Step Block_Size
     
    ' Count Pixel Colors Here:
     
    If Reds then
       If Reds > Max_Reds_in_a Bird Then Iterate Next_Block
     else
       Incr Bird_Count
    end if
     
     
    If Mixed_In_Block then
       If Mixed_In_Block_Count > Max_MIB_in_a Bird Then Iterate Next_Block
     else
       Incr Bird_Count
    end if
     
    Next_Block
    I see what you mean (now) by a more sophisticated algo now (if reasoning above is correct).

    Oh, not that it makes any difference, but all the pics shown here are .bmp's, not .jpegs. Obviously I wouldn't know if the original (posted by Chris) was a jpg or some other format (unless all digital pics are jpegs to begin with which I don't know either. Boy it seems like I don't know a lot of stuff.

    Oh well...

    ==================================
    Anyone who goes to a psychiatrist
    ought to have his head examined.
    Samuel Goldwyn
    ==================================

    Leave a comment:


  • Paul Dixon
    replied
    Gösta,
    if one could find a color unique to the geese
    It's not that simple
    First, if a bird almost fills a single pixel then that pixel will be a dark shade of bird but if that same bird is half way between 2 pixels then each pixel will be a mix of the background colour and the bird so the colour of the pixel no longer identifies that there is a bird there. It might be different if the picture was a close up of the birds where each bird occupied many pixels so some pixels were always full of bird.

    Second, the images are JPGs. If you look at your zoomed in shot you can see lots of artifacts introduced by the JPG compression. These show up as patches of varying light and dark pixels around each bird. The APPARENT colour to a person might be a reasonable match for the real image but to a computer these colours are just noise and crude approximations to the real colour in the scene and don't match at all. This is the reason my simple method earlier of checking the brightness each side of a pixel didn't work, it identified the JPG artifacts as changes in colour so thought they were birds.

    I think you're on the right lines to zoom in and take a look at what a computer sees when it looks at the image pixel by pixel. You just need to come up with the algoritm that the computer needs to correctly identify bird from noise. Colour alone is never going to work, you need to look at the difference in colour between pixels in small areas of the image.


    Paul.

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Originally posted by Chris Holbrook View Post
    Yes. If you were to use such a technique in "production", you might have to use different strategies to maximise the number of objects discerned, assuming that the birds are smaller than cloud features.Geese against a "mackerel sky" would be challenging.
    Assuming the picture was in color, It seems geese would be easier and more accurate in some respects, if one could find a color unique to the geese (say a green or red or brown). Then one could just search for that particular color (grouping). In the first run I examine blocks of 25. If one were searching for Red, then any reds in the block would be a (1) goose.

    What made this particular exercise rewarding for me was the technique Paul showed (putting the image into an array of pixel colors). Quite clever really for one unfamilar with graphics work. (me that is, not Paul)

    At any rate, here's the colors for a 21H x 11W section which looks like it has 6 of the smaller (fainter) birds.

    Code:
     
    section.bmp
      1  8,754,606  8,688,813  8,754,093  8,688,300  8,688,300  8,688,300  8,819,372  8,885,165  8,885,165  8,885,165  8,885,165 
      2  8,885,163  8,885,163  8,754,347  8,688,554  8,688,300  8,688,300  8,688,300  8,688,300  8,819,372  8,885,165  8,884,650 
      3  8,819,370  8,819,370  8,688,554  8,688,554  8,688,554  8,688,554  8,688,300  8,688,300  8,819,372  8,885,165  8,884,650 
      4  8,819,370  8,819,370  8,754,347  8,688,554  8,688,554  8,688,554  8,688,300  8,688,300  8,885,165  8,885,165  8,950,445 
      5  8,885,163  8,885,163  8,885,163  8,885,163  8,885,163  8,885,163  8,819,372  8,885,165  8,885,165  8,885,165  8,885,165 
      6  8,885,163  8,885,163  8,885,163  8,885,163  8,885,163  8,885,163  8,819,372  8,885,165  8,885,165  8,819,372  8,819,372 
      7  8,885,163  8,885,163  8,950,956  8,885,163  8,885,163  8,885,163  8,819,372  8,885,165  8,885,165  8,819,372  8,819,372 
      8  8,885,165  8,885,165  8,950,956  8,885,163  8,819,370  8,819,370  8,819,372  8,885,165  8,885,165  8,819,372  8,819,372 
      9  8,885,165  8,950,958  8,950,956  8,885,163  8,819,370  8,819,370  8,885,163  8,885,163  8,885,165  8,819,372  8,885,165 
     10  9,016,749  8,885,163  9,016,490  8,884,904  8,950,443  8,950,443  8,950,445  8,950,445  9,016,238  8,950,445  8,885,165 
     11  9,082,542  8,753,577  8,490,146  8,161,181  8,621,478  9,082,029  9,082,031  9,016,238  9,016,238  8,950,445  8,819,372 
     12  9,082,542  8,819,370  8,424,099  7,502,997  7,371,411  7,568,790  8,753,066  8,950,445  9,016,238  9,016,238  9,016,238 
     13  8,885,163  9,016,749  9,148,335  8,753,577  8,818,857  8,950,443  8,884,652  8,950,445  8,818,859  8,884,652  9,082,031 
     14  9,016,749  8,885,163  8,950,956  8,819,370  9,016,749  9,148,335  8,885,165  8,621,993  8,029,343  8,226,722  8,884,652 
     15  9,148,335  8,950,956  9,016,749  8,885,163  8,950,956  8,819,370  8,753,579  8,687,786  8,029,856  8,227,235  8,884,652 
     16  9,082,029  8,884,650  8,950,956  8,950,956  9,082,542  8,885,163  9,016,751  9,148,337  8,555,945  8,687,531  9,147,824 
     17  9,147,822  9,016,236  9,016,749  8,885,163  8,950,956  8,950,956  8,687,786  8,621,993  7,898,015  8,292,773  9,082,031 
     18  8,950,958  8,885,165  9,016,751  8,950,958  8,819,372  8,950,958  8,885,165  8,819,372  7,964,063  8,490,407  9,147,569 
     19  8,950,958  8,885,165  9,016,751  8,950,958  8,885,165  9,016,751  8,885,165  9,082,544  8,687,786  8,950,958  9,147,824 
     20  9,016,238  9,016,238  9,082,544  9,016,751  8,950,958  9,016,751  8,885,165  9,082,544  9,082,544  9,082,544  9,016,751 
     21  9,016,496  9,082,289  9,082,544  8,950,958  8,950,958  9,016,751  9,016,751  8,950,958  9,016,751  9,016,751  8,950,958
    The .bmp is attached and here is what it looks like blown up 300 times:
    http://www.SwedesDock.com/powerbasic/section21x11.bmp (size exceeds forum upload limit)

    Just kinda neat.

    ======================================================
    "How can I lose to such an idiot?"
    A shout from chessmaster Aaron Nimzovich (1886-1935)
    ======================================================

    Oh, just for the record, I made no claims as to the accuracy of the number of birds, only "My best guess is there's about 3,088.666666666666666667 birds in the picture {grin}."
    Attached Files
    Last edited by Gösta H. Lovgren-2; 27 Dec 2008, 09:40 PM. Reason: For the posterior record (as in posterity)

    Leave a comment:


  • Chris Holbrook
    replied
    Originally posted by Cliff Nichols View Post
    Seriously though I think the problem is more a context of color range vs the pixel being looked at to determine results
    Yes. If you were to use such a technique in "production", you might have to use different strategies to maximise the number of objects discerned, assuming that the birds are smaller than cloud features.Geese against a "mackerel sky" would be challenging.

    Leave a comment:


  • Cliff Nichols
    replied
    Quote:
    Originally Posted by Gösta H. Lovgren-2
    My best guess is there's about 3,088.666666666666666667 birds in the picture {grin}.

    That is the equivalent of 3,085 starlings, one seagull and a brace of sparrows.

    I am profoundly impressed.
    All together now....

    ....Annnnd a partridge in a pear treeeeeee!!!!!



    Seriously though I think the problem is more a context of color range vs the pixel being looked at to determine results

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Originally posted by Chris Holbrook View Post
    That is the equivalent of 3,085 starlings, one seagull and a brace of sparrows.

    I am profoundly impressed.
    Why? That I caught the sparrows?

    Actually Paul's code showing how to put a graphic into an array:

    Graphic Get Bits ...
    ReDim bmp(1 To xWidth, 1 To xHeight) As Long At StrPtr(Image1$) + 8 ...

    made it absurdly easy, which is not to say accurate. Actually I think the two sparrows may be seagull turds (they are so small details are hird to make out.)

    ===========================================
    "A pint of sweat saves a gallon of blood."
    General George S. Patton (1885-1945)
    ===========================================

    Leave a comment:


  • Chris Holbrook
    replied
    Originally posted by Gösta H. Lovgren-2 View Post
    My best guess is there's about 3,088.666666666666666667 birds in the picture {grin}.
    That is the equivalent of 3,085 starlings, one seagull and a brace of sparrows.

    I am profoundly impressed.

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Black & White estimate
    3,110 Birds in 12,065 Blocks of 5 square
    Color Total = 4,819,473,112,545 Color Avg = 15,688,389

    Color Estimate at 16,777,215 for a sky color
    3,078 Birds in 3,078 Pixels (at 1 Px per bird) 1% of total

    Grey Estimate at 16,777,215 for a sky color
    3,078 Birds in 8,839 Pixels (at 1 Px per bird) 3% of total

    '*****************

    My best guess is there's about 3,088.666666666666666667 birds in the picture {grin}.


    '
    Code:
     'PBWIN 9.00 - WinApi 05/2008 - XP Pro SP3
    'http://www.powerbasic.com/support/pbforums/showthread.php?t=39425
    'Original code by Paul Dixon
    #Register All ' suggestion by Theo G. faster running?
    '#Dim All                             
    #Include "WIN32API.INC"
    Macro wate
      Graphic ReDraw
      Graphic WAITKEY$
    End Macro
    '
    Macro pf = Print #nfile, 
    '
    Macro Load_Picture
      Open Pic$ For Binary As nFile& 'get size of bitmap
      Get #nFile&, 19, nWidth 'width begins at 19th byte
      Get #nFile&, 23, nHeight 'Height begibsa at 23rd byte
      Close nFile&
      '
      'load the bitmap 
      Graphic Bitmap Load Pic$, nWidth&, nHeight& To hBmp1 'assign the bitmap to a handle (DC?)
      '
      Graphic Attach hBmp1, 0 'assign a target for future graphic satements
      '
      Graphic Get Bits To Image1$ 'put the bmp ito a string
      '
      xWidth = Cvl(image1$,1) 'width is first 4 bytes (long)
      xHeight = Cvl(image1$,5) 'Height is next four
      '
      'show it on screen so I can see the effect of each stage of processing
      Graphic Window "Starlings", 1, 1, xWidth, xHeight To hWin1 'assign to a window handle
      Graphic Attach hWin1, 0, ReDraw 'assign a target for future graphic satements
      '
      Graphic Copy hBmp1,0 'copy Pic$ to "Starlings" window created above
      '
      ReDim bmp(1 To xWidth, 1 To xHeight) As Long At StrPtr(Image1$) + 8 'create a working array
      ReDim Colrs(1 To xWidth * xHeight) 'put color values in
      '
      Graphic ReDraw
      wate
    End Macro
    '
    Function PBMain
      Local Margin, ctr, ctr1, ctr2, ctr3, hctr, wctr, Bird_Count, Bird_Size, xWidth, xHeight, nWidth, nHeight, nfile As Long
      Local Bird_Pixels_DR, Pixels_Total, Bird_Pixels, Bird_Color, Color_Avg, Colrs(), Block_Size, Blocks_Total As Long
      Local Image1, Pic As String 
      Local hBmp1, hWin1 As Dword
      Local Color_Ttl As Quad
    '  
     Pic$ = "starlings_BW.bmp"
     nfile = FreeFile 
    '
       Load_Picture
    '
     
       For hctr = 1 To xheight
         For wctr = 1 To xWidth     
           Colrs(xWidth * xHeight) = bmp(wctr, hctr)
           Color_Ttl = Color_Ttl + bmp(wctr, hctr)
         Next wctr
       Next hctr                                   
    '                                               
      Color_Avg = Color_Ttl \ (xWidth * xHeight)
    '
    'no birds should be bigger than Bird_Size
      Bird_Size = 5
      Margin = 3 'Bird_Size \ 2
      Reset Bird_Count            
      Block_Size = Bird_Size * Bird_Size 
    '
    ' Any color within a Bird_Size Block = a bird 
              'start down a little   'stop up a little
       For hctr = Margin   To xHeight - Margin  Step Bird_Size
         For wctr = Margin To xWidth - Margin Step Bird_Size 
             Incr Blocks_Total
             'now see if any filled
             Reset ctr
             For ctr1 = -2 To 2
               For ctr2 = -2 To 2
                  If bmp(wctr + ctr2, hctr + ctr1) < 1 Then Incr ctr
               Next ctr2
             Next ctr1
    '         
             If ctr > 0 And ctr < Block_Size Then ' Case of block being all black
                Incr Bird_Count
             End If   
         Next wctr
       Next hctr
    '
    '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    '<<< Now do it in color
    '
    '   
       Bird_Color = RGB(90, 100, 100) 'picked from photo as darkest sky color
                                       'Anything darker (lower number) is considered a part of a bird  
     Pic$ = "starlings.bmp"
     nfile = FreeFile 
       Load_Picture
     
     
       For hctr = 1 To xHeight
         For wctr = 1 To xWidth
             Incr Pixels_Total
             'now see if any filled
              If bmp(wctr, hctr) <  Bird_Color Then Incr Bird_Pixels
         Next wctr
       Next hctr
    '
    '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    '<<< Now do it in DR's contrasted
    '
    '   
       Bird_Color = RGB(255, 255, 255) 'White
                                       'Anything darker (lower number) is considered a part of a bird  
     Pic$ = "starlingsDR.bmp"
     nfile = FreeFile 
       Load_Picture
     
     
       For hctr = 1 To xHeight
         For wctr = 1 To xWidth
             'now see if any filled
              If bmp(wctr, hctr) <  Bird_Color Then Incr Bird_Pixels_DR
         Next wctr
       Next hctr
    '
    '
    '
      wate
    '
       Open "Check.txt" For Output As #nfile
       Print #nfile, Using$("#, Wide  #, High = #, Total = #,  #,", xwidth, xHeight, xwidth * xHeight, Pixels_Total)   
       Print #nfile, ,"Black & White estimate"
       Print #nfile, Using$("#, Birds in #, Blocks of 5 square", Bird_Count, Blocks_Total)
       Print #nfile, Using$("Color Total = #,  Color Avg = #,", Color_Ttl, Color_Avg)
       ctr = 1
       pf " "                                                                    
       pf Using$("Color Estimate at #, for a sky color", Bird_Color)
       pf Using$("#, Birds in #, Pixels (at # Px per bird) #% of total", _
                  Bird_Pixels \ ctr, Bird_Pixels, ctr,  Bird_Pixels / Pixels_Total * 100)
     
       ctr = 1
       pf " "                                                                    
       pf Using$("Grey Estimate at #, for a sky color", Bird_Color)
       pf Using$("#, Birds in #, Pixels (at # Px per bird) #% of total", _
                  Bird_Pixels \ ctr, Bird_Pixels_DR, ctr,  Bird_Pixels_DR / Pixels_Total * 100)
     
       Close
    End Function
    '
    =====================================================
    "Without accepting the fact that everything changes,
    we cannot find perfect composure.
    But unfortunately, although it is true,
    it is difficult for us to accept it.
    Because we cannot accept
    the truth of transience,
    we suffer."
    Shunryu Suzuki
    =====================================================
    Last edited by Gösta H. Lovgren-2; 27 Dec 2008, 12:09 AM. Reason: Added the grey scale

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Originally posted by David Roberts View Post
    Gösta's tip re grey scale is the way to go with this image but I reckon you've been a bit heavy on the contrast peddle, Gösta.
    A heavy foot has been a problem for me all my life {sigh}.
    I've used less contrast on the whole image then applied selective contrast to the lower part. Paint Shop Pro has an Edge Effect and the Trace Contour works a treat on the image so far giving a higher retention of them thar birds.
    I have no idea how to do that. Used PBP since it was version 1 and shareware. Just kept updating as each version came to support the original author (forget his name) who gave great support. I should have stopped around version 4 or 5 (my last is 8.xx) because then it started becoming more and more complex for the (very) casual user. {oh well}.
    I tried your code Gösta but it GPF'd and I haven't had time to check why.
    It runs fine here (picture should be in same folder as program). You may have to put in "Drve:\Folder\Starlings..." if you have it elsewhere (though I don't think that would cause a GPF).

    ===================================
    "The gods too are fond of a joke."
    Aristotle (384-322 B.C.)
    ===================================

    Leave a comment:


  • David Roberts
    replied
    Gösta's tip re grey scale is the way to go with this image but I reckon you've been a bit heavy on the contrast peddle, Gösta.

    I've used less contrast on the whole image then applied selective contrast to the lower part. Paint Shop Pro has an Edge Effect and the Trace Contour works a treat on the image so far giving a higher retention of them thar birds.



    I tried your code Gösta but it GPF'd and I haven't had time to check why.

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Originally posted by Chris Holbrook View Post
    Gösta, Thanks for the BW copy - how did you make it?
    Paint Brush Pro (a PhotoShp type program) has a BW option.

    What I was going to do (haven't started yet) was look at 5x5 (or 4x or 3x) blocks of pixels and if any were not zero), count it as a bird. In BW, it should be pretty easy. In color, much harder.

    i{later} Finished. I came up with 3,110 Birds in 12,065 Blocks.

    Building on Paul's code'
    Code:
     'PBWIN 9.00 - WinApi 05/2008 - XP Pro SP3
    'http://www.powerbasic.com/support/pbforums/showthread.php?t=39425
    'Original code by Paul Dixon
    #Register All ' suggestion by Theo G. faster running?
    '#Dim All                             
    #Include "WIN32API.INC"
    Macro wate
      Graphic ReDraw
      Graphic WAITKEY$
    End Macro
    '
    Function PBMain
      Local Image1, Pic As String 
      Local Margin, ctr, ctr1, ctr2, ctr3, hctr, wctr, Bird_Count, Bird_Size, xWidth, xHeight, nWidth, nHeight, nfile As Long
      Local Block_Size, Blocks_Total As Long
      Local hBmp1, hWin1 As Dword
    '  
     Pic$ = "starlings_BW.bmp"
     nfile = FreeFile
    '
    Open Pic$ For Binary As nFile& 'get size of bitmap
    Get #nFile&, 19, nWidth 'width begins at 19th byte
    Get #nFile&, 23, nHeight 'Height begibsa at 23rd byte
    Close nFile&
    '
    'load the bitmap 
    Graphic Bitmap Load Pic$, nWidth&, nHeight& To hBmp1 'assign the bitmap to a handle (DC?)
    '
    Graphic Attach hBmp1, 0 'assign a target for future graphic satements
    Graphic Get Bits To Image1$ 'put the bmp ito a string
    '
    xWidth = Cvl(image1$,1) 'width is first 4 bytes (long)
    xHeight = Cvl(image1$,5) 'Height is next four
    '
    'show it on screen so I can see the effect of each stage of processing
    Graphic Window "Starlings", 1, 1, xWidth, xHeight To hWin1 'assign to a window handle
    Graphic Attach hWin1, 0, ReDraw 'assign a target for future graphic satements
    '
    Graphic Copy hBmp1???,0 'copy Pic$ to "Starlings" window created above
    '
    Dim bmp(1 To xWidth, 1 To xHeight) As Long At StrPtr(Image1$) + 8 'create a working array
    '
    '
    'no birds should be bigger than Bird_Size
      Bird_Size = 5
      Margin = 3 'Bird_Size \ 2
      Reset Bird_Count            
      Block_Size = Bird_Size * Bird_Size 
    '  
              'start down a little   'stop up a little
       For hctr = Margin   To xHeight - Margin  Step Bird_Size
         For wctr = Margin To xWidth - Margin Step Bird_Size 
             Incr Blocks_Total
             'now see if any filled
             Reset ctr
             For ctr1 = -2 To 2
               For ctr2 = -2 To 2
                  If bmp(wctr + ctr2, hctr + ctr1) < 1 Then Incr ctr '> 0 is black color
               Next ctr2
             Next ctr1
    '         
             If ctr > 0 And ctr < Block_Size Then ' Case of block being all black
                Incr Bird_Count
             End If   
         Next wctr
       Next hctr
    '
    '   
    '
    Graphic ReDraw
    '
      wate
    '
       Open "Check.txt" For Output As #nfile
       Print #nfile, Using$("#, Wide  #, High", xwidth, xHeight)   
       Print #nfile, Using$("#, Birds in #, Blocks ", Bird_Count, Blocks_Total)
    '                                                                       
       For hctr = 1 To xHeight        
        Print #nfile, Using$("#,#### ", hctr);
         For wctr = 1 To 10 'just to see how it looks
           Print #nfile, Using$("#, ", bmp(wctr, hctr));
         Next wctr
         Print #nfile, " "
       Next hctr
       Close
    End Function
    '
    In file
    640 Wide 480 High
    3,110 Birds in 12,065 Blocks
    ...
    While probably not an accurate count, I'd bet it's pretty close.
    Last edited by Gösta H. Lovgren-2; 26 Dec 2008, 04:23 PM. Reason: clarity?

    Leave a comment:


  • Conrad Hoffman
    replied
    FWIW & AFAIK the biggest application of this is cell counting in medical applications. Google "cell counting" and software to get a good overview of what's out there. Hopefully there will be some papers that show how they go about it.

    Leave a comment:


  • Chris Holbrook
    replied
    Originally posted by Eric Pearson View Post
    Why not simply count the number of dark pixels in the picture, then divide by your best guess of pixels-per-bird?
    Eric, that is a reasonable approach on an image-at-a-time basis. Pixels per bird brings in yet another variable, the distance between the camera and the flock. What I am hoping to work out is how to distinguish an irregular shape from its background. I'm sure that this has many applications and people are doing it all the time in process control, crop measurement, security, military applications. I would just like to join that club, even as a very junior member!

    Leave a comment:

Working...
X