NB. gray.js: a J verb that generates a grayscale postscript image from a 2d array 
Author Message
 NB. gray.js: a J verb that generates a grayscale postscript image from a 2d array
Hi,

here is  a verb that will write a file containing
a grayscale postscript image.
Its a neutered version of grayp2s.m, a matlab function for the
same purpose.
Not many comments, but I find that I'm just using it without
thinking about it.

enjoy,

Ira Ekhaus
Senior Scientist
AARC
4 A St
Burlington MA 01803

617 273 2400

NB. gray.js: verb that generates a grayscale postscript image from a  2d array
NB. useage
NB.  y=.x=. nramp 50    NB. support domain
NB.  f=. gnorm (sq x) -/ (sq y)   NB. offset and scale function to go 0 to 1
NB. ( gray  f) write <'f_out.ps'

lb=. '['[rb=. ']'
lt=. '<'[rt=. '>'
lp=. '{'[rp=. '}'
sp=. ' '

gnorm=. '(y. - min, y.)%((max,y.)-(min,y.))':20
hex=.    '0123456789ABCDEF'



max=. >./
min =. <./

d2g=. ',>": &.>  N ;sp;M;sp;8;sp;lb;sp;(N=.1{$y.);sp; 0;sp;0;sp;(M=. 0{$y.) ;sp; 0;sp; 0;sp;rb ' :''
head=. '%!PS-Adobe-2.0',lf,'/inch {72 mul} def',lf,'100 200 translate',lf,'400 400 scale   '
tail=. lf,rp,lf,'image',lf,'showpage'
bod=. '((d2g y.),lf,lp,lf,p=.lt,(,hfd trunc 255*1-y.)),rt': ''
gray =.'head,(bod y.),tail': ''

NB. qq=.  '   ,> ": &.>   M ;N;  8 ;sp;lb; (M=.0{$y.); 0; 0 ; (-N) ;sp; 0; 0; (N=. 1{$y.);rb ' :''
NB. qq1=. ',>": &.>  M ;sp;N;sp;8;sp;lb;sp;(M=.0{$y.);sp; 0;sp;0;sp;(N=. 1{$y.) ;sp; 0;sp; 0;sp;rb ' :''



Mon, 28 Oct 1996 21:28:16 GMT  
 NB. gray.js: a J verb that generates a grayscale postscript image from a 2d array

Quote:
> Hi,

> here is  a verb that will write a file containing
> a grayscale postscript image.
> Its a neutered version of grayp2s.m, a matlab function for the
> same purpose.
> Not many comments, but I find that I'm just using it without
> thinking about it.

> enjoy,

> Ira Ekhaus

> NB. gray.js: verb that generates a grayscale postscript image from a  2d array
> NB. useage
> NB.  y=.x=. nramp 50    NB. support domain
> NB.  f=. gnorm (sq x) -/ (sq y)   NB. offset and scale function to go 0 to 1
> NB. ( gray  f) write <'f_out.ps'

> lb=. '['[rb=. ']'
> lt=. '<'[rt=. '>'
> lp=. '{'[rp=. '}'
> sp=. ' '

> gnorm=. '(y. - min, y.)%((max,y.)-(min,y.))':20
> hex=.    '0123456789ABCDEF'



> max=. >./
> min =. <./

> d2g=. ',>": &.>  N ;sp;M;sp;8;sp;lb;sp;(N=.1{$y.);sp; 0;sp;0;sp;(M=. 0{$y.) ;sp; 0;sp; 0;sp;rb ' :''
> head=. '%!PS-Adobe-2.0',lf,'/inch {72 mul} def',lf,'100 200 translate',lf,'400 400 scale   '
> tail=. lf,rp,lf,'image',lf,'showpage'
> bod=. '((d2g y.),lf,lp,lf,p=.lt,(,hfd trunc 255*1-y.)),rt': ''
> gray =.'head,(bod y.),tail': ''

Neato, thanks for posting this - I imagine it will come in handy.
A few comments though:
  What is nramp?
  I take it lf is a system dependent linefeed (13 10{a. on PC)
  I had to add a end of file character to get the page to eject -
so I added eof=.4{a. to the end of tail.
  The "trunc" function is really "rounding" and there are faster
more natural ways to round than formating etc.  For example:

strange, slower way is:

My test example is as follows:
   sin=.1&o.

   x=._15+30*(i.%<:)100
   z=.s3s"0/~x
   (gray gnorm z) write 'a:temp.ps'

It works fine.  Thanks again.  Maybe you want to archive this
at waterloo!
  Cliff
--
Clifford A. Reiter
Mathematics Department, Lafayette College
Easton, PA 18042 USA,   610-250-5277



Wed, 30 Oct 1996 09:04:31 GMT  
 NB. gray.js: a J verb that generates a grayscale postscript image from a 2d array

Quote:
> Hi,

> here is  a verb that will write a file containing
> a grayscale postscript image.
> Its a neutered version of grayp2s.m, a matlab function for the
> same purpose.
> Not many comments, but I find that I'm just using it without
> thinking about it.

> enjoy,

> Ira Ekhaus

(Sorry if this got posted twice - often posts made here don't
 appear here)

Neato, thanks for posting this - I imagine it will come in handy.
A few comments though:
  What is nramp?
  I take it lf is a system dependent linefeed (13 10{a. on PC)
  I had to add a end of file character to get the page to eject -
so I added eof=.4{a. to the end of tail.
  The "trunc" function is really "rounding" and there are faster
more natural ways to round than formating etc.  For example:

strange, slower way is:

My test example is as follows:
   sin=.1&o.

   x=._15+30*(i.%<:)100
   z=.s3s"0/~x
   (gray gnorm z) write 'a:temp.ps'

It works fine.  Thanks again.  Maybe you want to archive this
at waterloo!
  Cliff
--
Clifford A. Reiter
Mathematics Department, Lafayette College
Easton, PA 18042 USA,   610-250-5277



Wed, 30 Oct 1996 09:07:00 GMT  
 NB. gray.js: a J verb that generates a grayscale postscript image from a 2d array

Quote:
Reiter Clifford writes:
>  I take it lf is a system dependent linefeed (13 10{a. on PC)
>  I had to add a end of file character to get the page to eject -
>so I added eof=.4{a. to the end of tail.
>  The "trunc" function is really "rounding" and there are faster
>more natural ways to round than formating etc.  For example:

>strange, slower way is:


   Um. An interesting way to do rounding.

   Here are some verbs I use :


      roundj =. 'j./ x. round"0 |: +. y.':20 "0   NB. for complex

   NB.  Usage : round g to the nearest 0.05
   g =. 0.01 * i. 10
   g ,: 0.05 round g
0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09
0    0    0 0.05 0.05 0.05 0.05 0.05  0.1  0.1
   NB.  Usage : round 1j1 g to the nearest 0.05
   g =. 1j1 * g
   g ,: 0.05 roundj g
0 0.01j0.01 0.02j0.02 0.03j0.03 0.04j0.04 0.05j0.05 0.06j0.06 0.07j0.07 0.08j0.08 0.09j0.09
0         0         0 0.05j0.05 0.05j0.05 0.05j0.05 0.05j0.05 0.05j0.05   0.1j0.1   0.1j0.1

 -e



Fri, 01 Nov 1996 04:12:58 GMT  
 NB. gray.js: a J verb that generates a grayscale postscript image from a 2d array

Quote:

>   Here are some verbs I use :

>      roundj =. 'j./ x. round"0 |: +. y.':20 "0   NB. for complex
>   NB.  Usage : round g to the nearest 0.05
>   g =. 0.01 * i. 10
>   g ,: 0.05 round g
>0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09
>0    0    0 0.05 0.05 0.05 0.05 0.05  0.1  0.1
>   NB.  Usage : round 1j1 g to the nearest 0.05
>   g =. 1j1 * g
>   g ,: 0.05 roundj g
>0 0.01j0.01 0.02j0.02 0.03j0.03 0.04j0.04 0.05j0.05 0.06j0.06 0.07j0.07 0.08j0.08 0.09j0.09
>0         0         0 0.05j0.05 0.05j0.05 0.05j0.05 0.05j0.05 0.05j0.05   0.1j0.1   0.1j0.1

> -e

And how about
        0.05&round&.+. g
and perhaps
        roundj=.(&round)&.+.  NB. an adverb.
and then
        0.05 roundj g  
But my preference is to the simple
        r=.<.&(0.5&+)
        rj=.r&.+.
and then
        rj&.(100&*) g
Eythan


Fri, 01 Nov 1996 06:20:06 GMT  
 NB. gray.js: a J verb that generates a grayscale postscript image from a 2d array

Quote:
Eythan Weg writes:
>And how about
>    0.05&round&.+. g
>and perhaps
>    roundj=.(&round)&.+.  NB. an adverb.

I got a syntax with this, but on the similar :


      roundj=. ' ([&round)&.+. ]':21
      roundj
].([&round&.+. ])

I there is no syntax error and it works fine.
But can anyone explain how this works?
Especially in contex with dex.

What is :

([&round&.+. ])

Its not a hook.

Thanks



Fri, 01 Nov 1996 13:19:16 GMT  
 NB. gray.js: a J verb that generates a grayscale postscript image from a 2d array

Quote:

>Eythan Weg writes:
>>And how about
>>        0.05&round&.+. g
>>and perhaps
>>        roundj=.(&round)&.+.  NB. an adverb.

I should have written
        roundj=.(&round)(&.+.)

Eythan



Sat, 02 Nov 1996 03:35:59 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. JS-EAI with *JS*-callback

2. js.exception 3279.js

3. help: js generated vrml

4. NB. nonce error

5. 1 (+^:_1) 0 NB. Beware!

6. How to generate 3D model from 2D image ?

7. lapackTest.js

8. profile.js

9. J script file profile.js

10. JS valueOf() in RB ?

11. JS for functional programming?

12. JS for functional programming?

 

 
Powered by phpBB® Forum Software