Welcome, Guest. Please login or register.

Author Topic: Help needed with a very silly idea...  (Read 3894 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Jose

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
Re: Help needed with a very silly idea...
« Reply #14 on: January 24, 2005, 08:45:05 PM »
@Karlos

Just another silly idea...
Could there be more than one object you're trying to identify in the same horizontal space? If not you could use some form of prediction about where the start of the object is based on the start of the previous line (after you detect the start of an horizontal line that is...).
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Help needed with a very silly idea...
« Reply #15 on: January 24, 2005, 08:50:13 PM »
Hi Jose,

Yes. It's basically the case that there will be several such shapes in any given 2D area. The idea is to find the smallest bounding boxes around them, within a tolerance threshold.

The problem is still open ended, but I'm also looking into another solution which may be more useful, especially for awkward shapes.
int p; // A
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Help needed with a very silly idea...
« Reply #16 on: January 24, 2005, 11:52:34 PM »
Here's an image to make the problem more visual:



The blue areas are outside our tolerance, the grey areas inside. The white rectangles are the areas I wish to find. Note from the diagram that:

A bounding rectangle may contain more than one 'blob', provided it properly fits the largest one.

A blob may be 'hollow' - I am only interested in the box around the outer extent.
int p; // A
 

Offline Jose

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
Re: Help needed with a very silly idea...
« Reply #17 on: January 27, 2005, 04:52:46 PM »
Hey. Since the blobs can repeat themselves in a line I think all pixels have to be scanned. So the thing would be to opimize the detection routine. I know you more than know this, it's just that the program I'm doing has a similar routine;) Except that instead of trying to identify pixels that fall within a certain range it compares pixels of two successive images. I'll let y'all know what it does when I get a good, completed working version. I had a doubt that I think applies here too:
 When comparing two pixels and checking the difference is there a way to use LONGs instead of BYTES to access compare and infere about the diference of each color component between 2 pixels? That would probably acceleratte it by 3 times or so..
I want to use C for now to make it portable to AOS4 so no 68k assembler (just for now :-D ).

Sorry for hijacking the thread  :-D but I think this could be usefull for the code that makes the pixel comparisons used in your detection routine too, it's practically the same I think, except that you're using a range (two pixel comparisons probably for the higher and lower values ?).

[EDIT] I meant, in your case it could be two pixel comparsions(higher and lower range value checking) each for each color component.
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Help needed with a very silly idea...
« Reply #18 on: January 27, 2005, 07:33:11 PM »
@Jose

Are your pixels arranged as 8-bit bytes? If your data reside in copyback memory, you will find that on 040+ bytewise comparison is not such a big issue. It is still slower but, not as bad as you might expect.

However, you can compare 2 sets of 4x8-bit pixels or 2 sets of 2x15/16-bit pixels using longwords.

If you exclusively or the two longwords together, you will highlight any bits that are different in each set of pixels. All the bits which are the same in both sets of pixels will be zero. Depending on what you intend to do with the data, I'm not sure if this will help you or not.

Oh - if you need to know which pixels are different, there are a couple of ways of working it out. Probably the easiest is to take the result of the 32-bit xor operation and mask it with four succesive 32-bit masks that each isolate a byte in the long word. Anything coming up as non zero is a difference.
int p; // A
 

Offline woof

  • Jr. Member
  • **
  • Join Date: Feb 2003
  • Posts: 94
    • Show only replies by woof
    • http://uae.is.free.fr
Re: Help needed with a very silly idea...
« Reply #19 on: January 27, 2005, 09:46:49 PM »
>I don't see why you need to scan vertically
All right i said vertically but you can scan first horizontally : but my idea was to not scan each line after
another (but skip N lines) so IF the shape is at the bottom (or right) of the screen you hit at first time only in several scan lines not by scanning all lines (or colonnes)

>Also by scanning vertically u arereading from RAM non->sequentially is very slow.
Absolutely right :-)

BTW with Altivec u can do massive compare of datas
some instructions on UBYTEs
vavgub         Average 16 UBYTE   
vcmpgtsb      Compare Greater-Than of 16 BYTE   
vmaxub         Maximum of 16 UBYTE   
vminub         Minimum of 16 UBYTE
etc...

Alain :-D
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Help needed with a very silly idea...
« Reply #20 on: January 27, 2005, 09:51:55 PM »
@woof

That's interesting to know - pity I dont have altivec :-(

Well, not yet ;-)

As it goes, this doesn't help my immediate problem - which is better explained by the image than anything I can easily write :-)

Mind you, course all I am looking for is to speed up something that isn't really time critical (or at least not yet anyway - that might change).
int p; // A
 

Offline Kronos

  • Resident blue troll
  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 4017
    • Show only replies by Kronos
    • http://www.SteamDraw.de
Re: Help needed with a very silly idea...
« Reply #21 on: January 27, 2005, 10:22:29 PM »
I cant say that I understood all in here, but that won't stop me from
adding my "mustard" ;)

I would create 2 arrays of "struct blob" (minx,maxx,miny,maxy), both
big enough to hold the maximum amount of blobs I expect per line
(+safety offcoure, lets say struct blob even[20] and odd[20]).

I would now start with line 0, and eachtime I get a hit I fill in
the mins into one odd blob.
I'll then search for the end of the blob in
this line and and add the maxx. Maxy is set to the same as miny.

Then I do the same for line 1 filling in odd blobs.

Now I do check wether blobs in even are connected to blobs in odd, and
change the odd ones to include the even one.

Even blobs that have no partner are fully found and pushed into the
outbuffer.

And now I fill the even blobs with line 2 and so one.

Makes sure at every pixel is only looked at once, and I don't think
the blob-comparing adds much overhead.

1. Make an announcment.
2. Wait a while.
3. Check if it can actually be done.
4. Wait for someone else to do it.
5. Start working on it while giving out hillarious progress-reports.
6. Deny that you have ever announced it
7. Blame someone else
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Help needed with a very silly idea...
« Reply #22 on: January 27, 2005, 10:28:54 PM »
int p; // A
 

Offline Waccoon

  • Hero Member
  • *****
  • Join Date: Apr 2002
  • Posts: 1057
    • Show only replies by Waccoon
Re: Help needed with a very silly idea...
« Reply #23 on: January 28, 2005, 06:47:08 AM »
Here's something cool I found, though it's designed for "shrinkwrap" boundings and not boxes:

http://cgm.cs.mcgill.ca/~orm/rotcal.html

What language are you using?  I'm thinking about writing some code to allow for a flood filler that won't work if an object is open (spilling out to the edges of the screen).  It's for a paint program that lets multiple people use one canvas.
 

Offline minator

  • Hero Member
  • *****
  • Join Date: Jan 2003
  • Posts: 592
    • Show only replies by minator
    • http://www.blachford.info
Re: Help needed with a very silly idea...
« Reply #24 on: January 28, 2005, 11:14:54 AM »
@ Karlos

Out of interest, what is this for?
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Help needed with a very silly idea...
« Reply #25 on: January 28, 2005, 12:12:49 PM »
@Waccoon

I'm using C. Well, I'm really using C++, but the code might be used in a related C project so it might as well be just C.

@Minator

I could tell you, but then I'd have to kill you :lol:

Nah, it isn't for anything important, it was just a small problem that cropped up in a recent project that I suddenly found interesting in it's own right.

Basically I am determining some bounding-box extents based on the opacity of an image for some processing I need to do. As it goes, contrary to what you might expect, I need the actual bounding box and not the pixel-exact 'mask' of the area.

That said, even if one does find the pixel exact mask, one can easily determine the bounding box, but I thought there might be a quicker way that takes advantage of not needing the exact mask...
int p; // A
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12113
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Re: Help needed with a very silly idea...
« Reply #26 on: January 28, 2005, 01:56:58 PM »
Ahhh... Karlos... just get a 4Ghz (or preferably an Athlon64 4000+) machine and brute force it, by scanning every pixel :-D

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Help needed with a very silly idea...
« Reply #27 on: January 28, 2005, 03:04:37 PM »
bleh, you lazy, unoptimizing git :lol:
int p; // A
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12113
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Re: Help needed with a very silly idea...
« Reply #28 on: January 28, 2005, 03:07:39 PM »
Quote

Karlos wrote:
bleh, you lazy, unoptimizing git :lol:


:roflmao: Well what you are suggesting is like trying to dig a tunnel with spoon... use a spade man!!! ;-)

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Help needed with a very silly idea...
« Reply #29 from previous page: January 28, 2005, 03:14:58 PM »
You know, it's an interesting in point.

I know a few people who write the most atrocious code imaginable, simply because they are spoiled by the performance of their hardware. People who should not be let anywhere near a compiler, for that matter. Their only skill is in the application of brute force to solve any problem. Then they use some convenience-oriented, high-level language/design tools with which to write their ill thought out code.

I worry that the arts of problem analysis, algorithm design and implementation efficiency are fast dying.
int p; // A