>>>>> "KP" == Komtanoo Pinpimai <[EMAIL PROTECTED]> writes:

  KP> There are 2 black-white rectangular images (each one kept in 2d array,
  KP> 0/1 as black/white).
  KP> First rectangular has A and B as its sides.
  KP> Second rectangular has C and D as its sides. C is less than A and D is
  KP> less than B.

  KP> I want to place the second rectangular into the first one with the
  KP> least overlaped pixels. (the second regtangular can be placed
  KP> exceedingly the bound of the larger reg., but it is worse than
  KP> overlaped pixel)

have you thought about doing bit string operations? you claim a 2d array
but you don't mention how it is stored. it could be an array of B bit
strings all of length A. the Bit::Vector module could be very handy
here.

then you can OR (or XOR) lines at a time and then sum up the bits to see
how much overlap there is. you still would have to shift the C sized
bit string to test against A. and you would still have to scan down the
B array but it seems like much less cpu would be needed than a full 4D
loop.

also you could try some heuristics (unless you must have the maximum
match) where you try to only maximize certain (random?) lines and rows
thereby shrinking the search space. you may get a suboptimal match but
it will/should take much less time.

also even though Bit::Vector is mostly in C you could write your own
specialized code with Inline::C to speed up those row/bit tests.

uri

-- 
Uri Guttman  ------  [EMAIL PROTECTED]  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to