comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » making a checkerboard array?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
making a checkerboard array? [message #55935] Tue, 25 September 2007 09:27 Go to next message
Mike[2] is currently offline  Mike[2]
Messages: 99
Registered: December 2005
Member
I'm trying to make a checkerboard mask for an array, but I'm missing
something that is likely to be obvious to the IDL array masters. The
following code makes a pattern like this (use a fixed width font):

+++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++

Can anyone help me fill in the missing rectangles like this?

+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++


Nx=300
Ny=200
Nrects = 10
Xside = Nx/Nrects
Yside = Ny/Nrects
xs = [replicate(1,Xside), replicate(0,Xside)]
while n_elements(xs) lt Nx do xs = [xs, [replicate(1,Xside),
replicate(0,Xside)]]
xs = xs[0:Nx-1]
ys = [replicate(1,Yside), replicate(0,Yside)]
while n_elements(ys) lt Ny do ys = [ys, [replicate(1,Yside),
replicate(0,Yside)]]
ys = ys[0:Ny-1]
window, xsize=Nx, ysize=Ny
tvscl, xs # ys
Re: making a checkerboard array? [message #55984 is a reply to message #55935] Wed, 26 September 2007 10:39 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
JD Smith writes:

> In case that wasn't clear, here it is dfanning style ;)
>
> theRamp = LINDGEN( theNumberofXPixels , theNumberofYPixels )
> theCheckerBoardHorizontalPeriod = 2 * theCheckWidth
> theHorizontalRamp = theRamp MOD theCheckerBoardHorizontalPeriod
> theHorizontalBands = theHorizontalRamp LT theCheckWidth
>
> theRowNumbers = theRamp/theNumberofXPixels
> theCheckerBoardVerticalPeriod = 2 * theCheckHeight
> theVerticalRamp = theRowNumbers MOD theCheckerBoardVerticalPeriod
> theVerticalBands = theVerticalRamp GE theCheckHeight
>
> theCheckerBoard = theHorizontalBands XOR theVerticalBands

Oh, hell. I think I'm going back to all lowercase. :-(

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: making a checkerboard array? [message #55985 is a reply to message #55935] Wed, 26 September 2007 10:27 Go to previous messageGo to next message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Tue, 25 Sep 2007 15:52:33 -0600, David Fanning wrote:

> JD Smith writes:
>
>>> I'm trying to make a checkerboard mask for an array, but I'm missing
>>> something that is likely to be obvious to the IDL array masters.
>>
>> l=lindgen(nx,ny)
>> l=(l mod (xside*2) lt xside) XOR (l/nx mod (yside*2) ge yside)
>
> Well, uh, it's not obvious to me. :-(


Well, l mod (xside*2) produces a horizontal ramp from 0... xside*2,
repeating over and over, the same for each row (as long as the array
width is an even multiple of xside). Comparing this ramp to xside,
ala (ramp lt xside) produces alternating vertical bars of width xside.
Similarly for l/nx (the row number), producing alternating horizontal
bars of height yside. Put them on top of each other and you have a
lovely quilt pattern. But we don't want a quilt, we want a
checkerboard, i.e. we want only those spots where the two bar patterns
don't overlap, hence the exclusive or (XOR).

In case that wasn't clear, here it is dfanning style ;)

theRamp = LINDGEN( theNumberofXPixels , theNumberofYPixels )
theCheckerBoardHorizontalPeriod = 2 * theCheckWidth
theHorizontalRamp = theRamp MOD theCheckerBoardHorizontalPeriod
theHorizontalBands = theHorizontalRamp LT theCheckWidth

theRowNumbers = theRamp/theNumberofXPixels
theCheckerBoardVerticalPeriod = 2 * theCheckHeight
theVerticalRamp = theRowNumbers MOD theCheckerBoardVerticalPeriod
theVerticalBands = theVerticalRamp GE theCheckHeight

theCheckerBoard = theHorizontalBands XOR theVerticalBands

JD
Re: making a checkerboard array? [message #55986 is a reply to message #55935] Wed, 26 September 2007 10:29 Go to previous messageGo to next message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
Allan Whiteford wrote:
> Bruce Bowler wrote:
>>> http://www.nerdtests.com/ft_nq.php ;-)
>>
>>
>> Arghhhhhh 91. I didn't think I was *that* nerdy :-)
>>
>
> The test is scoring people too highly... I don't deserve the 94 I got.
> Maybe a few years ago, but not now... surely not now!?!

I got a 97. That seems a bit high, but I'm not inclined to dispute it.
Re: making a checkerboard array? [message #55993 is a reply to message #55935] Wed, 26 September 2007 09:44 Go to previous messageGo to next message
R.G.Stockwell is currently offline  R.G.Stockwell
Messages: 163
Registered: October 2004
Senior Member
"Bruce Bowler" <bbowler@bigelow.org> wrote in message
news:pan.2007.09.26.15.19.33@bigelow.org...
>> http://www.nerdtests.com/ft_nq.php ;-)
>
> Arghhhhhh 91. I didn't think I was *that* nerdy :-)


OHOH!

{takes test results, prints them to printer, and burns them! Pleasantly
dreams of
scoring only 91}
Re: making a checkerboard array? [message #55994 is a reply to message #55935] Wed, 26 September 2007 09:37 Go to previous messageGo to next message
Allan Whiteford is currently offline  Allan Whiteford
Messages: 117
Registered: June 2006
Senior Member
Bruce Bowler wrote:
>> http://www.nerdtests.com/ft_nq.php ;-)
>
>
> Arghhhhhh 91. I didn't think I was *that* nerdy :-)
>

The test is scoring people too highly... I don't deserve the 94 I got.
Maybe a few years ago, but not now... surely not now!?!

Maybe it's just English majors bringing the average down ;).

I could tell I was heading for a high score when there wasn't an option
to pick "None of the above, it should be a lower case 'c'" which is what
I really wanted to answer.

Thanks,

Allan
Re: making a checkerboard array? [message #55999 is a reply to message #55935] Wed, 26 September 2007 08:29 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Bruce Bowler writes:

> Arghhhhhh 91. I didn't think I was *that* nerdy :-)

Let's just say in college I was an English major and
let it go at that. :-(

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: making a checkerboard array? [message #56000 is a reply to message #55935] Wed, 26 September 2007 08:28 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Bruce Bowler writes:

> Arghhhhhh 91. I didn't think I was *that* nerdy :-)

Are you available for some map documentation translation work?

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: making a checkerboard array? [message #56001 is a reply to message #55935] Wed, 26 September 2007 08:19 Go to previous messageGo to next message
Bruce Bowler is currently offline  Bruce Bowler
Messages: 128
Registered: September 1998
Senior Member
> http://www.nerdtests.com/ft_nq.php ;-)

Arghhhhhh 91. I didn't think I was *that* nerdy :-)

--
+-------------------+--------------------------------------- ------------+
Bruce Bowler | Those who cast the votes decide nothing. Those who
1.207.633.9600 | count the votes decide everything. - Anon
bbowler@bigelow.org |
+-------------------+--------------------------------------- ------------+
Re: making a checkerboard array? [message #56003 is a reply to message #55935] Wed, 26 September 2007 08:02 Go to previous messageGo to next message
Mike[2] is currently offline  Mike[2]
Messages: 99
Registered: December 2005
Member
On Sep 25, 12:56 pm, David Fanning <n...@dfanning.com> wrote:

> Are you working through Gonzales and Woods? My 3rd Edition just
> arrived yesterday! :-)

No - I'm making an image fuser that might work better than alpha
blending for pairs of PET images. Your solution almost works. If I
congrid it to make the squares bigger, it is just right. But JD's
is ... well ... I have no idea how a mind just pops that out!

Mike

P.S. Someone who is happy to get his new image processing book may
appreciate the quiz that is going around the lab here:
http://www.nerdtests.com/ft_nq.php ;-)
Re: making a checkerboard array? [message #56006 is a reply to message #55935] Wed, 26 September 2007 07:46 Go to previous messageGo to next message
Mike[2] is currently offline  Mike[2]
Messages: 99
Registered: December 2005
Member
On Sep 25, 5:34 pm, JD Smith <jdsm...@as.arizona.edu> wrote:
>
> l=lindgen(nx,ny)
> l=(l mod (xside*2) lt xside) XOR (l/nx mod (yside*2) ge yside)

I'm speachless - thanks!

Mike
Re: making a checkerboard array? [message #56020 is a reply to message #55935] Tue, 25 September 2007 15:59 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jean H writes:

> IDL> nx=20
> IDL> ny=20
> IDL> l=lindgen(nx,ny)
> IDL> l=(l mod (nx*2) lt nx) XOR (l/nx mod (ny*2) ge ny)
> IDL> print,l

If there is a question in there, I think this is the answer:

IDL> nx=20
IDL> ny=20
IDL> l =lindgen(nx, ny)
IDL> l=(l mod (2) lt 1) XOR (l/nx mod (2) ge 1)
IDL> print, l
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 1

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: making a checkerboard array? [message #56021 is a reply to message #55935] Tue, 25 September 2007 15:07 Go to previous messageGo to next message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
David Fanning wrote:
> JD Smith writes:
>
>
>>> I'm trying to make a checkerboard mask for an array, but I'm missing
>>> something that is likely to be obvious to the IDL array masters.
>>
>> l=lindgen(nx,ny)
>> l=(l mod (xside*2) lt xside) XOR (l/nx mod (yside*2) ge yside)
>
>
> Well, uh, it's not obvious to me. :-(
>
> Cheers,
>
> David
IDL> nx=20
IDL> ny=20
IDL> l=lindgen(nx,ny)
IDL> l=(l mod (nx*2) lt nx) XOR (l/nx mod (ny*2) ge ny)
IDL> print,l
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0
Re: making a checkerboard array? [message #56022 is a reply to message #55935] Tue, 25 September 2007 14:52 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
JD Smith writes:

>> I'm trying to make a checkerboard mask for an array, but I'm missing
>> something that is likely to be obvious to the IDL array masters.
>
> l=lindgen(nx,ny)
> l=(l mod (xside*2) lt xside) XOR (l/nx mod (yside*2) ge yside)

Well, uh, it's not obvious to me. :-(

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: making a checkerboard array? [message #56023 is a reply to message #55935] Tue, 25 September 2007 14:34 Go to previous messageGo to next message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Tue, 25 Sep 2007 09:27:17 -0700, Mike wrote:

> I'm trying to make a checkerboard mask for an array, but I'm missing
> something that is likely to be obvious to the IDL array masters.

> Can anyone help me fill in the missing rectangles like this?
>
> +++++00000+++++00000+++++00000
> +++++00000+++++00000+++++00000
> +++++00000+++++00000+++++00000
> 00000+++++00000+++++00000+++++
> 00000+++++00000+++++00000+++++
> 00000+++++00000+++++00000+++++
> +++++00000+++++00000+++++00000
> +++++00000+++++00000+++++00000
> +++++00000+++++00000+++++00000
> 00000+++++00000+++++00000+++++
> 00000+++++00000+++++00000+++++
> 00000+++++00000+++++00000+++++
> +++++00000+++++00000+++++00000
> +++++00000+++++00000+++++00000
> +++++00000+++++00000+++++00000
> 00000+++++00000+++++00000+++++
> 00000+++++00000+++++00000+++++
> 00000+++++00000+++++00000+++++

l=lindgen(nx,ny)
l=(l mod (xside*2) lt xside) XOR (l/nx mod (yside*2) ge yside)

JD
Re: making a checkerboard array? [message #56033 is a reply to message #55935] Tue, 25 September 2007 09:56 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mike writes:

> I'm trying to make a checkerboard mask for an array, but I'm missing
> something that is likely to be obvious to the IDL array masters. The
> following code makes a pattern like this (use a fixed width font):

Here is my implementation:

Function Checkerboard, xsize, ysize, white, black

IF N_Elements(xsize) EQ 0 THEN xsize = 512
IF N_Elements(ysize) EQ 0 THEN ysize = 512
IF N_Elements(white) EQ 0 THEN white = 255
IF N_Elements(black) EQ 0 THEN black = 0

IF xsize MOD 2 NE 0 THEN $
Message, 'The X size must be an even number.'
IF ysize MOD 2 NE 0 THEN $
Message, 'The Y size must be an even number.'

horizontalBoard = FltArr(xsize, ysize)
verticalboard = FltArr(xsize, ysize)
xhalfSize = xsize / 2
x = IndGen(xhalfSize) * 2
yhalfSize = ysize / 2
y = IndGen(yhalfsize) * 2

horizontalBoard[x,*] = 1
verticalBoard[*,y] = 1
verticalBoard = Temporary(verticalBoard) + horizontalBoard
verticalBoard[Where(verticalBoard EQ 2)] = 0
board = FltArr(xsize, ysize) + white
board[Where(verticalBoard GT 0)] = black
RETURN, board
END

Are you working through Gonzales and Woods? My 3rd Edition just
arrived yesterday! :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: making a checkerboard array? [message #56071 is a reply to message #55993] Thu, 27 September 2007 07:54 Go to previous message
edward.s.meinel@aero. is currently offline  edward.s.meinel@aero.
Messages: 52
Registered: February 2005
Member
On Sep 26, 12:44 pm, "R.G. Stockwell" <noem...@please.com> wrote:
> "Bruce Bowler" <bbow...@bigelow.org> wrote in message
>
> news:pan.2007.09.26.15.19.33@bigelow.org...
>
>>> http://www.nerdtests.com/ft_nq.php;-)
>
>> Arghhhhhh 91. I didn't think I was *that* nerdy :-)
>
> OHOH!
>
> {takes test results, prints them to printer, and burns them! Pleasantly
> dreams of
> scoring only 91}

99! No, that doesn't mean 'factorial'... Oooo, Agent 99, yowza!

Bruce, why are you so surprised? You're posting on comp.lang.idl-
pvwave, for crying out loud!

Ed "supreme nerd god" Meinel
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Parsing C -> Generating DLL/DLM
Next Topic: selection box in widget program

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:37:44 PDT 2025

Total time taken to generate the page: 0.00548 seconds