Results 1 to 10 of 10

Thread: Comparing a bitmap to a bitmap

  1. #1
    Join Date
    Nov 2011
    Posts
    68
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default Comparing a bitmap to a bitmap

    How can I compare a bitmap to another bitmap?

  2. #2
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    Compare as in this?
    Simba Code:
    function CalculatePixelShift(Bmp1, Bmp2: Integer; CompareBox: TBox): Integer;
    ^ will measure the change from 1 bitmap to another.
    If no, more information as to what you wish to do with the bitmaps would help to aide in finding something to compare the bitmaps.

  3. #3
    Join Date
    Nov 2011
    Posts
    68
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default

    thanks for help. +rep
    Last edited by Toby1; 08-18-2012 at 10:02 PM.

  4. #4
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    33
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by Le Jingle View Post
    Compare as in this?
    Simba Code:
    function CalculatePixelShift(Bmp1, Bmp2: Integer; CompareBox: TBox): Integer;
    ^ will measure the change from 1 bitmap to another.
    If no, more information as to what you wish to do with the bitmaps would help to aide in finding something to compare the bitmaps.
    Thank you.. I'm trying this function out atm, I wish the docs were a bit more complete. The thing is we want to compare a bitmap to a part of another bitmap (second bitmap being bigger in width and height).

    Bump.
    Last edited by Zyt3x; 08-19-2012 at 03:01 PM. Reason: no need to bump a 1 day old thread
    Respect your elders.

  5. #5
    Join Date
    Apr 2012
    Location
    Australia
    Posts
    1,252
    Mentioned
    1 Post(s)
    Quoted
    22 Post(s)

    Default

    What are these bitmaps you are trying to compare? It may be possible that there is an easier way to do this using functions/other features of the include. Without us knowing what you are trying to do it is difficult to make a suggestion.

  6. #6
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,691
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by Chewar View Post
    Thank you.. I'm trying this function out atm, I wish the docs were a bit more complete. The thing is we want to compare a bitmap to a part of another bitmap (second bitmap being bigger in width and height).
    My suggestion:

    Set the larger bitmap as a target, use FindBitmapDeformedToleranceIn with the smaller bitmap in a part to see how much they match.
    http://docs.villavu.com/simba/script...maptolerancein



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  7. #7
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Quote Originally Posted by Wizzup? View Post
    My suggestion:

    Set the larger bitmap as a target, use FindBitmapDeformedToleranceIn with the smaller bitmap in a part to see how much they match.
    http://docs.villavu.com/simba/script...maptolerancein
    Now there's a good idea. I see loading the big bitmap and setting it as the target (then finding the small bitmap within the large) is really straight forward, but how would we set our original target back after comparing the two bitmaps? Getting the original target ID and setting that ID back, that I don't know how to do.

    I can see where this would lead to a similar SPS.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  8. #8
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    Now there's a good idea. I see loading the big bitmap and setting it as the target (then finding the small bitmap within the large) is really straight forward, but how would we set our original target back after comparing the two bitmaps? Getting the original target ID and setting that ID back, that I don't know how to do.

    I can see where this would lead to a similar SPS.
    FindAndSetTarget? Never use it before though so i'm not sure if that's what you are looking for.

  9. #9
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    I can't get the goto to work. If you do though, this should work.

    Simba Code:
    Function FindBitmapInBitmap(BMP, BitmapToFind: Integer; var P: TPoint; Area: TBox; Tolerance: Integer): Boolean;
    var
      BmpW, BmpH, DX, DY, I, J, X, Y, W, H: Integer;
      FindColours, SearchColours: T2DIntegerArray;
      Label Skip;

    begin
      GetBitmapSize(BMP, W, H);
      GetBitmapSize(BitmapToFind, BmpW, BmpH);
      SearchColours := GetBitmapAreaColors(BMP, 0, 0, W, H);
      FindColours := GetBitmapAreaColors(BitmapToFind, 0, 0, BmpW, BmpH);
      BmpW := BmpW - 1;
      BmpH := BmpH - 1;
      dX := (Area.X2 - Area.X1) - BmpW;
      dY := (Area.Y2 - Area.Y1) - BmpH;

      For I := 0 To DY Do
        For J := 0 To DX Do
        begin
          For Y := 0 To BmpH Do
            For X := 0 To BmpW Do
            begin
              if (FindColours[Y][X] <> 0) then
                  if (Not SimilarColors(FindColours[Y][X], SearchColours[Y + I][X + J], Tolerance)) then
                    GoTo Skip;
            end;
          P := Point(J + Area.X1, I + Area.Y1);
          Resul:= True;
          Exit;
          Skip:
            continue;
        end;
      P(-1, -1);
      Result := False;
    end;
    I am Ggzz..
    Hackintosher

  10. #10
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    I can't get the goto to work. If you do though, this should work.

    Simba Code:
    Function FindBitmapInBitmap(BMP, BitmapToFind: Integer; var P: TPoint; Area: TBox; Tolerance: Integer): Boolean;
    var
      BmpW, BmpH, DX, DY, I, J, X, Y, W, H: Integer;
      FindColours, SearchColours: T2DIntegerArray;
      Label Skip;

    begin
      GetBitmapSize(BMP, W, H);
      GetBitmapSize(BitmapToFind, BmpW, BmpH);
      SearchColours := GetBitmapAreaColors(BMP, 0, 0, W, H);
      FindColours := GetBitmapAreaColors(BitmapToFind, 0, 0, BmpW, BmpH);
      BmpW := BmpW - 1;
      BmpH := BmpH - 1;
      dX := (Area.X2 - Area.X1) - BmpW;
      dY := (Area.Y2 - Area.Y1) - BmpH;

      For I := 0 To DY Do
        For J := 0 To DX Do
        begin
          For Y := 0 To BmpH Do
            For X := 0 To BmpW Do
            begin
              if (FindColours[Y][X] <> 0) then
                  if (Not SimilarColors(FindColours[Y][X], SearchColours[Y + I][X + J], Tolerance)) then
                    GoTo Skip;
            end;
          P := Point(J + Area.X1, I + Area.Y1);
          Resul:= True;
          Exit;
          Skip:
            continue;
        end;
      P(-1, -1);
      Result := False;
    end;
    You cant call goto within a loop. Easiest way to do it would be to set a boolean to true then break out of the loop first, then check the boolean and call goto.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •