Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.pascal.misc > Newsgroup comp.lang.pascal.delphi.misc

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 08-30-2003, 05:47 PM
name
Guest
 
Posts: n/a
Default Find color in Region

Hello,

There is a square, the square has four colors, black white orange grey.

The selected region covers some of black and some of white but mostly orange
and has no grey.

How can I find the x,y position of *any* point on a specified color?

My current solution is to run the mouse along the region and using the
GetPixel API call it will stop if it comes into contact with a pixel of the
specified color.

The problem with this is that its very slow, how else can this be done?

Thank you.


Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 08-30-2003, 07:50 PM
Maarten Wiltink
Guest
 
Posts: n/a
Default Re: Find color in Region

name wrote in message ...

>There is a square, the square has four colors, black white orange grey.
>
>The selected region covers some of black and some of white but mostly

orange
>and has no grey.
>
>How can I find the x,y position of *any* point on a specified color?



You mean you have a point but you don't know where it is?
Then how do you have a point at all?

Or do you mean that given a region and a colour, you want
to return "some" point in the region that has that colour?

Groetjes,
Maarten Wiltink



Reply With Quote
  #3 (permalink)  
Old 08-30-2003, 08:06 PM
name
Guest
 
Posts: n/a
Default Re: Find color in Region


"Maarten Wiltink" <maarten@kittensandcats.net> wrote in message
news:3f50ffed$0$49100$e4fe514c@news.xs4all.nl...
> name wrote in message ...
>
> >There is a square, the square has four colors, black white orange grey.
> >
> >The selected region covers some of black and some of white but mostly

> orange
> >and has no grey.
> >
> >How can I find the x,y position of *any* point on a specified color?

>
>
> You mean you have a point but you don't know where it is?
> Then how do you have a point at all?
>
> Or do you mean that given a region and a colour, you want
> to return "some" point in the region that has that colour?


I mean that given a region and a colour i want to return "some" point in
that region that has that colour.

>
> Groetjes,
> Maarten Wiltink
>
>
>



Reply With Quote
  #4 (permalink)  
Old 08-30-2003, 08:59 PM
Maarten Wiltink
Guest
 
Posts: n/a
Default Re: Find color in Region

name wrote in message
<0t74b.6510$Om1.3506@newsread2.news.atl.earthlink. net>...
[...]
>I mean that given a region and a colour i want to return
>"some" point in that region that has that colour.



That sounds non-deterministic, and non-deterministic sounds
scary.

Offhand I don't see any way to beat the algorithm of simply
running past every pixel in the region. What might give an
improvement is to randomise the order in which you visit them.
Obviously, borderline cases where one colour is grossly
underrepresented will always be slow.

Real gains are to be made in pre-processing the value you're
looking for. In a paletted bitmap, don't ask for an RGB triplet
by coordinate but do the (inverse) palette lookup beforehand
and look for the colour index. In any case, look as much as
possible in the raw data; scanlines in the case of a bitmap.
If all you have is a canvas, blit it to a bitmap first so you
have raw data to begin with.

The big win would be to know how the region has been coloured
to begin with. If you know that it's "a red circle here, and
a yellow square there, on a blue background", you're as good as
home free if someone asks for a yellow pixel.

Groetjes,
Maarten Wiltink



Reply With Quote
  #5 (permalink)  
Old 08-30-2003, 09:59 PM
Martin Harvey
Guest
 
Posts: n/a
Default Re: Find color in Region

On Sat, 30 Aug 2003 22:59:24 +0200, "Maarten Wiltink"
<maarten@kittensandcats.net> wrote:

>name wrote in message
><0t74b.6510$Om1.3506@newsread2.news.atl.earthlink .net>...
>[...]
>>I mean that given a region and a colour i want to return
>>"some" point in that region that has that colour.

>
>
>That sounds non-deterministic, and non-deterministic sounds
>scary.
>
>Offhand I don't see any way to beat the algorithm of simply
>running past every pixel in the region. What might give an
>improvement is to randomise the order in which you visit them.
>Obviously, borderline cases where one colour is grossly
>underrepresented will always be slow.


GetPixel is gonna be slow. How about getting the canvas and converting
it to a DIB, so that he can look at the values directly? That will
most likely be orders of magnitude faster :-)

MH.
Reply With Quote
  #6 (permalink)  
Old 08-30-2003, 10:26 PM
name
Guest
 
Posts: n/a
Default Re: Find color in Region


"Martin Harvey" <martin@pergolesi_nospam_.demon.co.uk> wrote in message
news:if72lv4fb59igtfed2n4nlrev8vaif6h1k@4ax.com...
> On Sat, 30 Aug 2003 22:59:24 +0200, "Maarten Wiltink"
> <maarten@kittensandcats.net> wrote:
>
> >name wrote in message
> ><0t74b.6510$Om1.3506@newsread2.news.atl.earthlink .net>...
> >[...]
> >>I mean that given a region and a colour i want to return
> >>"some" point in that region that has that colour.

> >
> >
> >That sounds non-deterministic, and non-deterministic sounds
> >scary.
> >
> >Offhand I don't see any way to beat the algorithm of simply
> >running past every pixel in the region. What might give an
> >improvement is to randomise the order in which you visit them.
> >Obviously, borderline cases where one colour is grossly
> >underrepresented will always be slow.

>
> GetPixel is gonna be slow.


How about getting the canvas and converting
> it to a DIB, so that he can look at the values directly? That will
> most likely be orders of magnitude faster :-)


How much faster are we talking? The canvas is constantly shifting and if its
not very fast the copy of the canvas will be out of date with the actual
canvas. Ex. blue = 1, 200 on copy but on real canvas its 3, 197

>
> MH.



Reply With Quote
  #7 (permalink)  
Old 08-31-2003, 12:31 AM
name
Guest
 
Posts: n/a
Default Re: Find color in Region


"Nicholas Sherlock" <N_sherlock@hotmail.com> wrote in message
news:bireef$38r$1@lust.ihug.co.nz...
> name wrote:
> > "Martin Harvey" <martin@pergolesi_nospam_.demon.co.uk> wrote in
> > message news:if72lv4fb59igtfed2n4nlrev8vaif6h1k@4ax.com...
> >> On Sat, 30 Aug 2003 22:59:24 +0200, "Maarten Wiltink"
> >> <maarten@kittensandcats.net> wrote:
> >>
> >>> name wrote in message
> >>> <0t74b.6510$Om1.3506@newsread2.news.atl.earthlink. net>...
> >>> [...]
> >>>> I mean that given a region and a colour i want to return
> >>>> "some" point in that region that has that colour.
> >>>
> >>>
> >>> That sounds non-deterministic, and non-deterministic sounds
> >>> scary.
> >>>
> >>> Offhand I don't see any way to beat the algorithm of simply
> >>> running past every pixel in the region. What might give an
> >>> improvement is to randomise the order in which you visit them.
> >>> Obviously, borderline cases where one colour is grossly
> >>> underrepresented will always be slow.
> >>
> >> GetPixel is gonna be slow.

> >
> > How about getting the canvas and converting
> >> it to a DIB, so that he can look at the values directly? That will
> >> most likely be orders of magnitude faster :-)

> >
> > How much faster are we talking? The canvas is constantly shifting and
> > if its not very fast the copy of the canvas will be out of date with
> > the actual canvas. Ex. blue = 1, 200 on copy but on real canvas its
> > 3, 197

>
> Tell us, what are you actually trying to achieve?


I alredy told you -- given a region and a colour i want to return
"some" point in that region that has that colour.

>
> Cheers,
> Nicholas Sherlock
>
>



Reply With Quote
  #8 (permalink)  
Old 08-31-2003, 12:54 AM
name
Guest
 
Posts: n/a
Default Re: Find color in Region


"Nicholas Sherlock" <N_sherlock@hotmail.com> wrote in message
news:birgng$4sq$1@lust.ihug.co.nz...
> name wrote:
> > "Nicholas Sherlock" <N_sherlock@hotmail.com> wrote in message
> > news:bireef$38r$1@lust.ihug.co.nz...
> >> Tell us, what are you actually trying to achieve?

> >
> > I alredy told you -- given a region and a colour i want to return
> > "some" point in that region that has that colour.


> No, that's not what you are trying to achieve.

That is what i am trying to achive!

>Why do you need to do this?
> What is the context? Then perhaps we could think of an even better

solution.

I think, giving you the details that you seem to be after would not help you
think of a better soloution then one that could be found thinking of it in
terms of:
you have a region and a color
you need to find any point in that region that matches the color

If I am mistaken then please tell me how you "could think of an even better
solution"
>
> Cheers,
> Nicholas Sherlock
>
>



Reply With Quote
  #9 (permalink)  
Old 08-31-2003, 05:59 AM
Steven
Guest
 
Posts: n/a
Default Re: Find color in Region

name wrote:
> "Nicholas Sherlock" <N_sherlock@hotmail.com> wrote in message
> news:bireef$38r$1@lust.ihug.co.nz...
>>
>> Tell us, what are you actually trying to achieve?

>
> I alredy told you -- given a region and a colour i want to return
> "some" point in that region that has that colour.
>


Nicholas' question is to the point: we might offer you better help if we
know what you try to achieve. What you tell us is how you want to solve your
problem without telling what the actual problem is. Maybe there's a
completely different, but easier, approach.

I think your "working method" is like this:
You think of some problem which may be solved by a computer program (or you
ask us to invent such problems). Then you look at what Delphi can do,
regardless of the problem, and try to use it.
Problem: Delphi offers a _lot_ of features.

Wouldn't it be better to
1. better define the limits of your problem
2. think of what you need to accomplish this
3. check which of these _you_ can't do in Delphi
4. if the list from 3. is too long the problem is way over your head. Put it
aside for later.
5. if the list from 3. has only a few features, spend some time to
understand how to solve them in Delphi _as separate tasks_. Create a small
project just to learn each thing. Don't go back to your original project
until you know how to use it.

As I said before, it occurs to me that you want to use everything Delphi
offers and therefore not only your region is constantly changing, but so are
your projects.


Reply With Quote
  #10 (permalink)  
Old 08-31-2003, 08:52 AM
AlanGLLoyd
Guest
 
Posts: n/a
Default Re: Find color in Region

In article <rq54b.5332$Om1.2952@newsread2.news.atl.earthlink. net>, "name"
<e@m.a> writes:

>There is a square, the square has four colors, black white orange grey.
>
>The selected region covers some of black and some of white but mostly orange
>and has no grey.
>
>How can I find the x,y position of *any* point on a specified color?
>


If you used windows "Regions" then you could create the elements of your square
as separate regions (using CreateRectRgn), allocating a region to them. Also
store the color associated with each region (either in your own TColorRegion
class or in a record of region handles and colors in a list).

Then when you drag a selection, you could turn the selection into a TRect,
check which regions of the square it overlaps (using RectInRegion), and get the
color from the stored region color.

Alan Lloyd
alanglloyd@aol.com
Reply With Quote
  #11 (permalink)  
Old 08-31-2003, 10:03 AM
J French
Guest
 
Posts: n/a
Default Re: Find color in Region

On 31 Aug 2003 08:52:43 GMT, alanglloyd@aol.com (AlanGLLoyd) wrote:

<snip>
>
>If you used windows "Regions" then you could create the elements of your square
>as separate regions (using CreateRectRgn), allocating a region to them. Also
>store the color associated with each region (either in your own TColorRegion
>class or in a record of region handles and colors in a list).
>
>Then when you drag a selection, you could turn the selection into a TRect,
>check which regions of the square it overlaps (using RectInRegion), and get the
>color from the stored region color.


Although, in his typical 'name-ish' he refuses to tell us the 'full
picture'

- however he has let slip that the Image is changing rapidly, so I
rather suspect that the Image(s) are coming in from elsewhere
- perhaps a video camera

- that would, I think, preclude regions.
Reply With Quote
  #12 (permalink)  
Old 08-31-2003, 01:10 PM
name
Guest
 
Posts: n/a
Default Re: Find color in Region


"Steven" <stevenpantsvh@pandora.be> wrote in message
news:49g4b.10363$467.383093@phobos.telenet-ops.be...
> name wrote:
> > "Nicholas Sherlock" <N_sherlock@hotmail.com> wrote in message
> > news:bireef$38r$1@lust.ihug.co.nz...
> >>
> >> Tell us, what are you actually trying to achieve?

> >
> > I alredy told you -- given a region and a colour i want to return
> > "some" point in that region that has that colour.
> >

>
> Nicholas' question is to the point: we might offer you better help if we
> know what you try to achieve. What you tell us is how you want to solve

your
> problem without telling what the actual problem is. Maybe there's a
> completely different, but easier, approach.
>
> I think your "working method" is like this:
> You think of some problem which may be solved by a computer program (or

you
> ask us to invent such problems). Then you look at what Delphi can do,
> regardless of the problem, and try to use it.
> Problem: Delphi offers a _lot_ of features.
>
> Wouldn't it be better to
> 1. better define the limits of your problem
> 2. think of what you need to accomplish this
> 3. check which of these _you_ can't do in Delphi
> 4. if the list from 3. is too long the problem is way over your head. Put

it
> aside for later.
> 5. if the list from 3. has only a few features, spend some time to
> understand how to solve them in Delphi _as separate tasks_. Create a small
> project just to learn each thing. Don't go back to your original project
> until you know how to use it.
>
> As I said before, it occurs to me that you want to use everything Delphi
> offers and therefore not only your region is constantly changing, but so

are
> your projects.


I usually finish my projects in a timly fashion - they are ither doable or
put aside for later, currently i only have one put aside. Now for this
thread this is my problem:

I have a region and a color. I want to find any point in that region that is
that color.

What I am currently doing is looking at every point in the region and its
very slow, I am asking if there is a better way.


Reply With Quote
  #13 (permalink)  
Old 08-31-2003, 01:12 PM
name
Guest
 
Posts: n/a
Default Re: Find color in Region


"AlanGLLoyd" <alanglloyd@aol.com> wrote in message
news:20030831045243.21457.00000301@mb-m10.aol.com...
> In article <rq54b.5332$Om1.2952@newsread2.news.atl.earthlink. net>, "name"
> <e@m.a> writes:
>
> >There is a square, the square has four colors, black white orange grey.
> >
> >The selected region covers some of black and some of white but mostly

orange
> >and has no grey.
> >
> >How can I find the x,y position of *any* point on a specified color?
> >

>
> If you used windows "Regions" then you could create the elements of your

square
> as separate regions (using CreateRectRgn), allocating a region to them.

Also
> store the color associated with each region (either in your own

TColorRegion
> class or in a record of region handles and colors in a list).
>
> Then when you drag a selection, you could turn the selection into a TRect,
> check which regions of the square it overlaps (using RectInRegion), and

get the
> color from the stored region color.


By region I ment a user defines a square. So, I think, its not a windows
"Region"

>
> Alan Lloyd
> alanglloyd@aol.com



Reply With Quote
  #14 (permalink)  
Old 08-31-2003, 04:39 PM
Dunny
Guest
 
Posts: n/a
Default Re: Find color in Region


"name" <e@m.a> wrote in message
news:ntm4b.10367$Om1.5873@newsread2.news.atl.earth link.net...

> I have a region and a color. I want to find any point in that region that is
> that color.


> What I am currently doing is looking at every point in the region and its
> very slow, I am asking if there is a better way.


Sounds like he's trying to:

1. Get a handle to another app's window, and use as a canvas
2. Find something that's on the window
3. Do something to that app by hijacking it.

I'd leave this one alone guys, he's already proved himself to have suspect
motives - and do you notice how reluctant he is to tell us what he's doing?

D.



Reply With Quote
  #15 (permalink)  
Old 08-31-2003, 05:05 PM
name
Guest
 
Posts: n/a
Default Re: Find color in Region

<spam>
>
> I'd leave this one alone guys, he's already proved himself to have suspect
> motives - and do you notice how reluctant he is to tell us what he's

doing?

No one wanted to know about my little messenger program i posted and only
one person responded, I come up with a good idea i can actually do 99% alone
and you want to know it. No im not going to tell you about my program, deal
with it. I posted a Delphi problem and I expect a responce not a flame.

> D.


Omg.. if you were kids i could understand but you people are adults! Get
ahold of your self. If you cannot respond to a basic programming question
with out knowing what else im doing you have some issues.

I am trying to get a point in a region that matches a color -- You dont know
how to do that so you started to flame me. If you cant help, dont post.


Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: A question on finding subtotal and total Tom Hide Newsgroup comp.soft-sys.sas 0 05-08-2006 08:24 AM
Re: Another question on totals and subtotals Jiann-Shiun Huang Newsgroup comp.soft-sys.sas 0 05-07-2006 05:54 PM
Re: Clear Output, Clear Log, Find Madan Gopal Kundu Newsgroup comp.soft-sys.sas 0 04-01-2006 04:29 AM
Re: Clear Output, Clear Log, Find tataphani@GMAIL.COM Newsgroup comp.soft-sys.sas 0 03-31-2006 10:22 PM
Clear Output, Clear Log, Find Dean Hjelle Newsgroup comp.soft-sys.sas 0 03-31-2006 05:08 PM



All times are GMT. The time now is 03:43 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.