1. Faster way?

This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C2AB6F.97FC9E70
	charset="iso-8859-1"

Hello,
I'm wondering if there is a more efficient(meaning faster) way of
comparing each element of a sequence with each element of another
sequence of the same size.Im matching an image with a background =
image,and
any whitespace I find,I want to convert to the background image.




sequence image

sequence background

for i=3D 1 to length(image) by 1 do
   =20
 for j=3D1  to length(image[1]) by 1 do
 temp=3Dcompare(image[i][j],background[1][j])
=20
 if image[i][j]=3D255 then
 image[i][j]=3Dbackground[1][j]
   =20
 end if
   =20
  end for  =20
end for


Note:Sorry I havent been able to help on some of the other problems
posted here,its just that I really don't have much experience with
programming.Maybe someday I'll be able to help out more
                                   Thanks,
                                      JDUBE
------=_NextPart_000_0005_01C2AB6F.97FC9E70
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hello,<BR>I'm wondering if there is a =
more=20
efficient(meaning faster) way of<BR>comparing each element of a sequence =
with=20
each element of another<BR>sequence of the same size.Im matching an =
image with a=20
background image,and<BR>any whitespace I find,I want to convert to the=20
background image.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV><FONT face=3DArial size=3D2>
<DIV><BR>sequence image</DIV>
<DIV>&nbsp;</DIV>
<DIV>sequence background</DIV>
<DIV>&nbsp;</DIV>
<DIV>for i=3D 1 to length(image) by 1 do<BR>&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;for=20
j=3D1&nbsp; to length(image[1]) by 1=20
do<BR>&nbsp;temp=3Dcompare(image[i][j],background[1][j])<BR>&nbsp;<BR>&nb=
sp;if=20
image[i][j]=3D255 =
then<BR>&nbsp;image[i][j]=3Dbackground[1][j]<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;end if<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp; end for&nbsp;&nbsp; =
<BR>end=20
for</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>Note:Sorry I havent been able to help on some of the other=20
problems<BR>posted here,its just that I really don't have much =
experience=20
with<BR>programming.Maybe someday I'll be able to help out=20
more<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
Thanks,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;=20

------=_NextPart_000_0005_01C2AB6F.97FC9E70--

new topic     » topic index » view message » categorize

2. Re: Faster way?

Hi Jdube,
   I think there isn't a faster way to do that.
   But in your code, the line:
temp=compare(image[i][j],background[1][j])
   Is not being used for anything, and that routine will definitly slow
down your code. Why not to remove it?

Best Regards,
     Guillermo Bonvehi

--- dubetyrant at hotmail.com wrote:
> 
> Hello,
> I'm wondering if there is a more efficient(meaning faster) way of
> comparing each element of a sequence with each element of another
> sequence of the same size.Im matching an image with a background
> image,and
> any whitespace I find,I want to convert to the background image.
> 
> sequence image
> 
> sequence background
> 
> for i= 1 to length(image) by 1 do
>     
>  for j=1  to length(image[1]) by 1 do
>  temp=compare(image[i][j],background[1][j])
>  
>  if image[i][j]=255 then
>  image[i][j]=background[1][j]
>     
>  end if
>     
>   end for   
> end for

new topic     » goto parent     » topic index » view message » categorize

3. Re: Faster way?

oh,ok.I think I was testing something with that line...your right,
thank you very much.






>From: pampeano at rocketmail.com
>Subject: Re: Faster way?
>
>
>Hi Jdube,
>    I think there isn't a faster way to do that.
>    But in your code, the line:
>temp=compare(image[i][j],background[1][j])
>    Is not being used for anything, and that routine will definitly slow
>down your code. Why not to remove it?
>
>Best Regards,
>      Guillermo Bonvehi
>
>--- dubetyrant at hotmail.com wrote:
> >
> > Hello,
> > I'm wondering if there is a more efficient(meaning faster) way of
> > comparing each element of a sequence with each element of another
> > sequence of the same size.Im matching an image with a background
> > image,and
> > any whitespace I find,I want to convert to the background image.
> >
> > sequence image
> >
> > sequence background
> >
> > for i= 1 to length(image) by 1 do
> >
> >  for j=1  to length(image[1]) by 1 do
> >  temp=compare(image[i][j],background[1][j])
> >
> >  if image[i][j]=255 then
> >  image[i][j]=background[1][j]
> >
> >  end if
> >
> >   end for
> > end for
>
>
>

new topic     » goto parent     » topic index » view message » categorize

4. Re: Faster way?

On 24 Dec 2002, at 17:12, dubetyrant at hotmail.com wrote:

>  charset="iso-8859-1"
> 
> !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> HTML>HEAD>
> META http-equiv=3DContent-Type content=3D"text/html; charset=3Diso-
8859-1"= >
> META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR> 
STYLE>/STYLE>
> /HEAD> BODY bgColor=3D#ffffff> 
PRE>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D The
> Euphoria Mailing List =3D=3D= 
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=20 /PRE>
> 
> 
> DIV>FONT face=3DArial size=3D2>Hello,BR>I'm wondering if there is a 
more= =20
> efficient(meaning faster) way ofBR>comparing each element of a sequence 
wi=
> th=20 each element of anotherBR>sequence of the same size.Im 
matching an image
> w= ith a=20 background image,andBR>any whitespace I find,I want to 
convert to
> the=20 background image./FONT>/DIV> DIV>&nbsp;/DIV> DIV>FONT 
face=3DArial
> size=3D2>/FONT>&nbsp;/DIV> DIV>&nbsp;/DIV>FONT face=3DArial 
size=3D2>
> DIV>BR>sequence image/DIV> DIV>&nbsp;/DIV> DIV>sequence 
background/DIV>
> DIV>&nbsp;/DIV> DIV>for i=3D 1 to length(image) by 1 
doBR>&nbsp;&nbsp;&nbsp;
> BR>&nbsp;fo= r=20 j=3D1&nbsp; to length(image[1]) by 1=20
> 
doBR>&nbsp;temp=3Dcompare(image[i][j],background[1][j])BR>&nbsp;BR>&
nbsp=
> ;if=20 image[i][j]=3D255
> thenBR>&nbsp;image[i][j]=3Dbackground[1][j]BR>&nbsp;&nb= 
sp;&nbsp;=20
> BR>&nbsp;end ifBR>&nbsp;&nbsp;&nbsp; BR>&nbsp; end 
for&nbsp;&nbsp; BR>e=
> nd=20 for/DIV> DIV>&nbsp;/DIV> 

I would see if it couldn't be done in assy code, if you could get the pointers 
to the bitmaps. Aren't there some graphics libs in the archives in machine 
code?

Kat

new topic     » goto parent     » topic index » view message » categorize

5. Re: Faster way?

JDUBE writes:
> I'm wondering if there is a more efficient(meaning faster) way...
>
> for i= 1 to length(image) by 1 do
>     for j=1  to length(image[1]) by 1 do
>         temp=compare(image[i][j],background[1][j]) 
>         if image[i][j]=255 then
>             image[i][j]=background[1][j]
>         end if
>     end for   
> end for

I'm not sure if I understand exactly what you are trying to do here,
but for greater speed you should always try to remove 
calculations from the inner loop. That includes subscripts.

(untested)

for i = 1 to length(image) do
    image_row = image[i]
    back_row = background[i]
    for j = 1 to length(image_row) do
        if image_row[j] != 255 then
            back_row[j] = image_row[j]
        end if
    end for   
    background[i] = back_row
end for

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

6. Re: Faster way?

On Tue, 24 Dec 2002 17:12:09 -0500, dubetyrant at hotmail.com wrote:

<snip>;
 Mike gave you a one-liner, let us know how/if that helped

You also wrote:
>Note:Sorry I havent been able to help on some of the other problems
>posted here,its just that I really don't have much experience with
>programming.Maybe someday I'll be able to help out more

So I looked you up, Jason: on 10 Aug 2002 one post stood out:

>I stand corrected,thank you.

=46rom what I read of your previous posts, you are prepared to voice
your opinions, ask questions, acknowledge the answers, accept when
you might be wrong, and I think argue reasonably against someone
calling you wrong when you believe you are right.

Please do not apologise for being here; we need more of your type.
Besides, watching another newbie smack their head into the same old
brick wall [1] is always more instructive that listening to some old
hack argue about some semicolon or other.

Pete
[1] as well as being funny [(;-P)]
[2] only joking there, of course.

new topic     » goto parent     » topic index » view message » categorize

7. Re: Faster way?

This is a bit faster...

for i = 1 to length(image) do
    image_row = image[i]
    back_row = background[i]
    x = find(255,image_row)
    while x do
        image_row[x] = back_row[x]
        x = find(255,image_row)
    end while
    image[i] = image_row
end for

The difference is that you use the image sequence and not the resultant
background sequence.
It also assumes that 255 is not in the background sequence.

----------------
cheers,
Derek Parnell
----- Original Message -----
From: <dubetyrant at hotmail.com>
To: "EUforum" <EUforum at topica.com>
Sent: Wednesday, December 25, 2002 9:12 AM
Subject: Faster way?



Hello,
I'm wondering if there is a more efficient(meaning faster) way of
comparing each element of a sequence with each element of another
sequence of the same size.Im matching an image with a background image,and
any whitespace I find,I want to convert to the background image.




sequence image

sequence background

for i= 1 to length(image) by 1 do

 for j=1  to length(image[1]) by 1 do
 temp=compare(image[i][j],background[1][j])

 if image[i][j]=255 then
 image[i][j]=background[1][j]

 end if

  end for
end for


Note:Sorry I havent been able to help on some of the other problems
posted here,its just that I really don't have much experience with
programming.Maybe someday I'll be able to help out more
                                   Thanks,
                                      JDUBE

==^^===============================================================
This email was sent to: ddparnell at bigpond.com

new topic     » goto parent     » topic index » view message » categorize

8. Re: Faster way?

Yeah, but what about the inner loop?
It calculates length() every time the outer runs.
Perfect 2D sequences is going to have all same inner lengths.
Why bother checking size of each inner if they are all the same.

        Lucius L. Hilley III

----- Original Message -----
From: "Robert Elia" <bobelia200 at netzero.net>
To: "EUforum" <EUforum at topica.com>
Subject: RE: Faster way?



At 02:32 25.12.02 +0000, you wrote:

>
>
>dubetyrant at hotmail.com wrote:
> > Hello,
> > I'm wondering if there is a more efficient(meaning faster) way of
> > comparing each element of a sequence with each element of another
> > sequence of the same size.Im matching an image with a background
> > image,and

<snip>

>also you are using the 'length' function in your loop control statement.
>each time this statement is executed so would the length function be
>re-calculated.
>calculate it once prior to entering the loop would help.
>
>seqsize = length(image)
>for i = 1 to seqsize by 1 do
>if image[i] = 255 then
>image[i] = background[i]
>end if
>end for
>
>Merry Christmas and Happy New Year to All Euphorians
>Rudy
>lotterywars

         Actually, this is only true for while loops.  for loops use the
length() function only once.  Here's a demo:

---------------------------

sequence s

puts(1, "for loop:for i = 1 to length(s) do --accesses length(s) only
once\n")
s={1,2,3,4,5}
? s
for i = 1 to length(s) do --accesses length(s) only once
     printf(1, "%2d ", {length(s)})  ? s
     s = s & i
end for

puts(1, "while length(s) > 2 do  --accesses length(s) on each iteration\n")
? s

while length(s) > 2 do  --accesses length(s) on each iteration
     printf(1, "%2d ", {length(s)})  ? s
     s = s[2..length(s)]
end while

         I think Rob commented on this a while back.

                         Bob

==^^===============================================================
This email was sent to: l3euphoria at bellsouth.net





----------------------------------------------------------------------------
----


>
> ---
>

new topic     » goto parent     » topic index » view message » categorize

9. Re: Faster way?

--=======6B8C284E=======

At 08:31 PM 12/25/02 -0500, you wrote:

>
>Yeah, but what about the inner loop?
>It calculates length() every time the outer runs.
>Perfect 2D sequences is going to have all same inner lengths.
>Why bother checking size of each inner if they are all the same.
>
>         Lucius L. Hilley III
>
>----- Original Message -----
>From: "Robert Elia" <bobelia200 at netzero.net>
>To: "EUforum" <EUforum at topica.com>
>Sent: Wednesday, December 25, 2002 01:45 PM
>Subject: RE: Faster way?
> >also you are using the 'length' function in your loop control statement.
> >each time this statement is executed so would the length function be
> >re-calculated.
> >calculate it once prior to entering the loop would help.
> >
> >seqsize = length(image)
> >for i = 1 to seqsize by 1 do
> >if image[i] = 255 then
> >image[i] = background[i]
> >end if
> >end for
> >
> >Merry Christmas and Happy New Year to All Euphorians
> >Rudy
> >lotterywars

Ah, good point. I see that I took the statement out of context, since the 
inner loop was quoted out of context.  But someone else might, also.

         Thanks for the clarification,

                 Bob

--=======6B8C284E=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert;
x-avg-checked=avg-ok-5BDB4F3
Content-Disposition: inline


---

--=======6B8C284E=======--

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu