Dan,
The context of this work is to guide the development of image processing
firmware (dedicated software) for a massively parallel processor, which
could be embedded in an office printer. For this purpose I try to
promote J as THE language to express first thoughts as well as the final
target "assembler"-like code and all stages in between! This is more or
less according to the ideas of Fred Brooks & Gerrit Blaauw, which used
APL to develop micro-code for the IBM/360.
The actual case used here is Image Quantisation of business graphics
scans, which tries to recover the intent of those scanned images. The
algorithm I use, is a parallel form of simulated annealing, where a
object function, called E ("energy"), has to be minimised per pixel.
My ultimate goal is to demonstrate that J can follow the mathematical
description of this process as close as possible, thus tempting the
developer to code the mathematics directly into J.
That is why function f below should e.g. not have a need to pass an
index to it because the description has no need for it. Is there a way
to avoid it and pass globals Gh and T in more elegant ways to f?
The script uses image3 addon and a script in the standard
J504/system/classes/view/ DIR. The script is included below.
I will sent a sample bitmap-file and a draft version of the mathematical
description to your personal mail address.
Thanks in advance for your help.
Jan.
====
0!:000 < 'c:\j504\addons\image3\','image3.ijs'
0!:000 < 'c:\j504\system\classes\view\','viewmat.ijs'
imPath=:'c:\temp\'
d=:1!:2&2
T0=: 4
n=: 33
c=: (<:n)%:1e_2%T0
T=: T0*c^i.n
NCs=: 2
]Cs=: (#~ (>&0 *. <:&NCs) @ | @ j./"1)@(,/ @ (,"0/~) @ i:) NCs
NB. 5x5
ALPHA=: 0.1
delta=:-.@:+:@:=
lhood=:3 : '*: origIm - y.{MU'
NB. compute likelihood
prior=:4 : '+/ x. delta"2 Cs |. y.'
NB. compute prior
NB. annealSingelStep
NB. y. ~ state
NB. x. ~ iteration count
E=:4 : '(lhood x.) + BETA * x. prior y.'
f=:3 : 0
'state index'=.y.
stateNew=.index{Gh
TEMP=.index{T
energy=. state E state
energyNew=. stateNew E state
deltaE=. energyNew - energy
accept=. deltaE <: - TEMP * ^. ALPHA
state=.accept}state,:stateNew
state;>:index
)
d'START arch0 processing...'
origIm=: {."1 read_image imPath,'mbra_22','.bmp' NB. read in
image
viewmat origIm
NB. display
L=:#MU=:30 33 208 216
NB. means are given
(9!:1) 7^5
NB. fix seed for random number generator
BETA=:10
NB. fixed for now
g0=:?($origIm)$L
NB. first random state
d'preparing array of random states...'
Gh=:?(n,$origIm)$L
NB. prepare array of random states
arch0=: <. MU {~ >{. f^:n (g0;0)
NB. quantise (MRF & SA)
viewmat arch0
NB. display
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Dan Bron
Sent: donderdag 21 december 2006 18:27
To: [email protected]
Subject: RE: [Jgeneral] selection
Jan wrote:
> If you could help me making this more elegantly (execution time does
> not matter) that would be great.
I love rewriting other people's code ;) So I want to help you, but I
don't quite know what you want, nor what your script is supposed to do.
Can you provide a full, working script? With any global data defined
in the script (or by supporting external files read by the script)?
Can you provide examples of its use?
Can you be more precise in your goals for the script? What is it, in
the definition below, that you find unappealing or inelegant?
If you need to send attachments, feel free to email me personally.
I'll upload them to the Wiki (or you can do so yourself).
-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
This message and attachment(s) are intended solely for use by the addressee and
may contain information that is privileged, confidential or otherwise exempt
from disclosure under applicable law.
If you are not the intended recipient or agent thereof responsible for
delivering this message to the intended recipient, you are hereby notified that
any dissemination, distribution or copying of this communication is strictly
prohibited.
If you have received this communication in error, please notify the sender
immediately by telephone and with a 'reply' message.
Thank you for your co-operation.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm